Skip to content

Commit

Permalink
Test creation of pstats output files for multiprocessing
Browse files Browse the repository at this point in the history
  • Loading branch information
rmjarvis committed Oct 12, 2023
1 parent e163f72 commit ed4d3e1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion galsim/config/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ def worker(task_queue, results_queue, config, logger, initializers, initargs):
logger.debug('%s: Received STOP', proc)
if pr is not None:
pr.disable()
pr.dump_stats(config.get('root', 'galsim') + '_' + str(proc) + '.pstats')
pr.dump_stats(config.get('root', 'galsim') + '-' + str(proc) + '.pstats')
s = StringIO()
sortby = 'time' # Note: This is now called tottime, but time seems to be a valid
# alias for this that is backwards compatible to older versions
Expand Down
8 changes: 6 additions & 2 deletions tests/test_config_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,24 @@ def test_fits():
np.testing.assert_array_equal(im2.array, im1_list[k].array)
galsim.config.util.max_queue_size = 32767 # Set it back.

# Check that profile outputs something appropriate for multithreading.
# Check that profile outputs something appropriate for multiprocessing.
# (The single-thread profiling is handled by the galsim executable, which we don't
# bother testing here.)
config = galsim.config.CopyConfig(config1)
with CaptureLog() as cl:
galsim.config.Process(config, logger=cl.logger,
new_params={'profile':True, 'output.nproc': -1})
new_params={'profile':True, 'output.nproc': 4})
#print(cl.output)
# Unfortunately, the LoggerProxy doesn't really work right with the string logger used
# by CaptureLog. I tried for a while to figure out how to get it to capture the proxied
# logs and couldn't get it working. So this just checks for an info log before the
# multithreading starts. But with a regular logger, there really is profiling output.
if galsim.config.UpdateNProc(10, 6, config) > 1:
assert "Starting separate profiling for each of the" in cl.output
for p in range(4):
pstats_file = f'galsim-Process-{p+1}.pstats'
assert os.path.exists(pstats_file)
os.remove(pstats_file)

# Check some public API utility functions
assert galsim.config.GetNFiles(config) == 6
Expand Down

0 comments on commit ed4d3e1

Please sign in to comment.