# HG changeset patch # User Matt Mackall # Date 1440799171 18000 # Node ID bdac264e5ed4f9bb501bf646a39f255c7cc10400 # Parent 049005de325ea400893f45bd6221215cc9b26db0 contrib: add showstack extension This allows getting a Python stack trace at any time on Unix by hitting Ctrl-\ (or Ctrl-T on BSDs). Useful for debugging mysterious hangs on the fly. Sample output: $ hg log -k nosuchmessage ^\ File "/home/mpm/hg/mercurial/revset.py", line 3089, in _iterfilter if cond(x): File "/home/mpm/hg/mercurial/util.py", line 415, in f cache[arg] = func(arg) File "/home/mpm/hg/mercurial/revset.py", line 1215, in matches for t in c.files() + [c.user(), c.description()]) File "/home/mpm/hg/mercurial/context.py", line 525, in files return self._changeset[3] File "/home/mpm/hg/mercurial/util.py", line 531, in __get__ result = self.func(obj) File "/home/mpm/hg/mercurial/context.py", line 498, in _changeset return self._repo.changelog.read(self.rev()) File "/home/mpm/hg/mercurial/changelog.py", line 338, in read text = self.revision(node) File "/home/mpm/hg/mercurial/revlog.py", line 1092, in revision bins = self._chunks(chain) File "/home/mpm/hg/mercurial/revlog.py", line 1013, in _chunks ladd(decompress(buffer(data, chunkstart - offset, chunklength))) File "/home/mpm/hg/mercurial/revlog.py", line 91, in decompress return _decompress(bin) ---- diff -r 049005de325e -r bdac264e5ed4 contrib/showstack.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contrib/showstack.py Fri Aug 28 16:59:31 2015 -0500 @@ -0,0 +1,17 @@ +# showstack.py - extension to dump a Python stack trace on signal +# +# binds to both SIGQUIT (Ctrl-\) and SIGINFO (Ctrl-T on BSDs) + +import sys, signal, traceback + +def sigshow(*args): + sys.stderr.write("\n") + traceback.print_stack(args[1], limit=10, file=sys.stderr) + sys.stderr.write("----\n") + +def extsetup(ui): + signal.signal(signal.SIGQUIT, sigshow) + try: + signal.signal(signal.SIGINFO, sigshow) + except AttributeError: + pass