- with stopwatch.Timer() as t:
- ret = entry_point(*args, **kwargs)
- logger.debug(
- f'{entry_point.__name__} (program entry point) returned {ret}.'
- )
+ if config.config['run_profiler']:
+ import cProfile
+ from pstats import SortKey
+
+ with stopwatch.Timer() as t:
+ cProfile.runctx(
+ "ret = entry_point(*args, **kwargs)",
+ globals(),
+ locals(),
+ None,
+ SortKey.CUMULATIVE,
+ )
+ else:
+ with stopwatch.Timer() as t:
+ ret = entry_point(*args, **kwargs)
+
+ logger.debug('%s (program entry point) returned %s.', entry_point.__name__, ret)
+
+ if config.config['trace_memory']:
+ snapshot = tracemalloc.take_snapshot()
+ top_stats = snapshot.statistics('lineno')
+ print()
+ print("--trace_memory's top 10 memory using files:")
+ for stat in top_stats[:10]:
+ print(stat)