From d4a0b70e15ec6413f5216dd14cb6b26d86ad2e44 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Tue, 29 Jan 2019 07:59:02 +0000 Subject: [PATCH] core: ensure broker profiling output reaches disk Profiler hasn't been used much since the hard exit was added. --- mitogen/core.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mitogen/core.py b/mitogen/core.py index 4bc754ba..aaaed1ba 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -540,7 +540,7 @@ def enable_profiling(): try: return func(*args) finally: - profiler.dump_stats('/tmp/mitogen.%d.%s.pstat' % (os.getpid(), name)) + profiler.dump_stats('/tmp/mitogen.stats.%d.%s.pstat' % (os.getpid(), name)) profiler.create_stats() fp = open('/tmp/mitogen.stats.%d.%s.log' % (os.getpid(), name), 'w') try: @@ -2798,8 +2798,7 @@ class Broker(object): (self._waker.receive_side, self._waker.on_receive) ) self._thread = threading.Thread( - target=_profile_hook, - args=('broker', self._broker_main), + target=self._broker_main, name='mitogen-broker' ) self._thread.start() @@ -2932,7 +2931,7 @@ class Broker(object): 'more child processes still connected to ' 'our stdout/stderr pipes.', self) - def _broker_main(self): + def _do_broker_main(self): """ Broker thread main function. Dispatches IO events until :meth:`shutdown` is called. @@ -2950,6 +2949,9 @@ class Broker(object): self._exitted = True self._broker_exit() + + def _broker_main(self): + _profile_hook('mitogen-broker', self._do_broker_main) fire(self, 'exit') def shutdown(self):