| 1 | Without this patch, the 'sanity-check phase fails because loading the
|
| 2 | debug_utils.py module triggers command-line parsing.
|
| 3 |
|
| 4 | Taken from: <https://github.com/ddsmt/ddSMT/pull/41>.
|
| 5 |
|
| 6 | diff --git a/ddsmt/debug_utils.py b/ddsmt/debug_utils.py
|
| 7 | index 7c44971..6cacfe2 100644
|
| 8 | |
| 9 | |
| 10 | @@ -53,30 +53,30 @@ class Profiler:
|
| 11 | function, this argument should never be set to True.
|
| 12 | """
|
| 13 |
|
| 14 | - enabled = options.args().profile
|
| 15 | + enabled = lambda: options.args().profile
|
| 16 | # static profiler, global within one process
|
| 17 | profiler = None
|
| 18 |
|
| 19 | def __init__(self, is_main=False):
|
| 20 | """Create a profiler."""
|
| 21 | - if Profiler.enabled:
|
| 22 | + if Profiler.enabled():
|
| 23 | if multiprocessing.parent_process() is None:
|
| 24 | - self.enabled = True
|
| 25 | + self.enabled = lambda: True
|
| 26 | self.filename = '.profile.prof'
|
| 27 | else:
|
| 28 | - self.enabled = True
|
| 29 | + self.enabled = lambda: True
|
| 30 | self.filename = f'.profile-{os.getpid()}.prof'
|
| 31 | if Profiler.profiler is None:
|
| 32 | Profiler.profiler = cProfile.Profile()
|
| 33 |
|
| 34 | def __enter__(self):
|
| 35 | """Start profiling, if ``--profile`` was given."""
|
| 36 | - if Profiler.enabled and self.enabled:
|
| 37 | + if Profiler.enabled() and self.enabled():
|
| 38 | Profiler.profiler.enable()
|
| 39 |
|
| 40 | def __exit__(self, type, value, traceback):
|
| 41 | """Stop profiling and write results to file."""
|
| 42 | - if Profiler.enabled and self.enabled:
|
| 43 | + if Profiler.enabled() and self.enabled():
|
| 44 | try:
|
| 45 | Profiler.profiler.disable()
|
| 46 | Profiler.profiler.dump_stats(self.filename)
|