From ed4d3e1d3e5786b4848c29165594efc38c821706 Mon Sep 17 00:00:00 2001 From: Mike Jarvis Date: Thu, 12 Oct 2023 15:34:56 -0400 Subject: [PATCH] Test creation of pstats output files for multiprocessing --- galsim/config/util.py | 2 +- tests/test_config_output.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/galsim/config/util.py b/galsim/config/util.py index b7909b359c..1e07d9428e 100644 --- a/galsim/config/util.py +++ b/galsim/config/util.py @@ -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 diff --git a/tests/test_config_output.py b/tests/test_config_output.py index d84e80778d..b7a9e2bd77 100644 --- a/tests/test_config_output.py +++ b/tests/test_config_output.py @@ -140,13 +140,13 @@ 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 @@ -154,6 +154,10 @@ def test_fits(): # 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