aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/debug.py
diff options
context:
space:
mode:
authorThomas Kriechbaumer <Kriechi@users.noreply.github.com>2016-06-11 14:22:48 +0200
committerGitHub <noreply@github.com>2016-06-11 14:22:48 +0200
commitc801f81373d5935f60bf950b1f266911a94ecf60 (patch)
treef43829ac75d65d0147c618007e87975f18b8fd3e /netlib/debug.py
parent8489c01ac81479e48c2ff2c3ab308e07e3d2bacd (diff)
parente9f8eb1f6bf1a30bba304769507c1eb6ef64c3cf (diff)
downloadmitmproxy-c801f81373d5935f60bf950b1f266911a94ecf60.tar.gz
mitmproxy-c801f81373d5935f60bf950b1f266911a94ecf60.tar.bz2
mitmproxy-c801f81373d5935f60bf950b1f266911a94ecf60.zip
Merge pull request #1243 from cortesi/debug2
debug: On SIGUSR2, we dump tracebacks for all threads to screen
Diffstat (limited to 'netlib/debug.py')
-rw-r--r--netlib/debug.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/netlib/debug.py b/netlib/debug.py
index 6f6b0460..303a2f6f 100644
--- a/netlib/debug.py
+++ b/netlib/debug.py
@@ -4,6 +4,7 @@ import sys
import threading
import signal
import platform
+import traceback
import psutil
@@ -76,5 +77,22 @@ def dump_info(sig, frm, file=sys.stdout): # pragma: no cover
print("****************************************************", file=file)
-def register_info_dumper(): # pragma: no cover
+def dump_stacks(signal, frame, file=sys.stdout):
+ id2name = dict([(th.ident, th.name) for th in threading.enumerate()])
+ code = []
+ for threadId, stack in sys._current_frames().items():
+ code.append(
+ "\n# Thread: %s(%d)" % (
+ id2name.get(threadId, ""), threadId
+ )
+ )
+ for filename, lineno, name, line in traceback.extract_stack(stack):
+ code.append('File: "%s", line %d, in %s' % (filename, lineno, name))
+ if line:
+ code.append(" %s" % (line.strip()))
+ print("\n".join(code), file=file)
+
+
+def register_info_dumpers(): # pragma: no cover
signal.signal(signal.SIGUSR1, dump_info)
+ signal.signal(signal.SIGUSR2, dump_stacks)