Start yappi last and stop it first

In the debug handler, stop yappi before doing anything else, and
start it last.  Principally so that objgraph doesn't affect it.

Change-Id: I1940a1820f14c9664162645c86c37b6cd2286545
This commit is contained in:
James E. Blair 2024-06-09 07:15:51 -07:00
parent 9b475efd8c
commit d72ad52ec6

View File

@ -46,6 +46,19 @@ def stack_dump_handler(signum, frame):
signal.signal(signal.SIGUSR2, signal.SIG_IGN)
log = logging.getLogger("zuul.stack_dump")
log.debug("Beginning debug handler")
try:
if yappi:
if yappi.is_running():
log.debug("Stopping Yappi")
yappi.stop()
yappi_out = io.StringIO()
yappi.get_func_stats().print_all(out=yappi_out)
yappi.get_thread_stats().print_all(out=yappi_out)
log.debug(yappi_out.getvalue())
yappi_out.close()
yappi.clear_stats()
except Exception:
log.exception("Yappi error:")
try:
threads = {}
for t in threading.enumerate():
@ -65,22 +78,6 @@ def stack_dump_handler(signum, frame):
log.debug(log_str)
except Exception:
log.exception("Thread dump error:")
try:
if yappi:
if not yappi.is_running():
log.debug("Starting Yappi")
yappi.start()
else:
log.debug("Stopping Yappi")
yappi.stop()
yappi_out = io.StringIO()
yappi.get_func_stats().print_all(out=yappi_out)
yappi.get_thread_stats().print_all(out=yappi_out)
log.debug(yappi_out.getvalue())
yappi_out.close()
yappi.clear_stats()
except Exception:
log.exception("Yappi error:")
try:
if objgraph:
log.debug("Most common types:")
@ -90,6 +87,13 @@ def stack_dump_handler(signum, frame):
objgraph_out.close()
except Exception:
log.exception("Objgraph error:")
try:
if yappi:
if not yappi.is_running():
log.debug("Starting Yappi")
yappi.start()
except Exception:
log.exception("Yappi error:")
log.debug("End debug handler")
signal.signal(signal.SIGUSR2, stack_dump_handler)