Patchwork contrib: add showstack extension

login
register
mail settings
Submitter Matt Mackall
Date Aug. 28, 2015, 10:02 p.m.
Message ID <354f7f63caa34e6c2b91.1440799328@ruin.waste.org>
Download mbox | patch
Permalink /patch/10323/
State Superseded
Headers show

Comments

Matt Mackall - Aug. 28, 2015, 10:02 p.m.
# HG changeset patch
# User Matt Mackall <mpm@selenic.com>
# Date 1440799171 18000
#      Fri Aug 28 16:59:31 2015 -0500
# Node ID 354f7f63caa34e6c2b917cc51e1f36a508a4a05d
# Parent  ab66c1dee405aca0c51b8f76eab255d805c194d7
contrib: add showstack extension

This allows getting a Python stack trace at any time on Unix by hitting
Ctrl-\. 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)
----

Patch

diff -r ab66c1dee405 -r 354f7f63caa3 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,11 @@ 
+# showstack.py - extension to dump a Python stack trace on SIGQUIT (Ctrl-\)
+
+import os, sys, signal, time, traceback
+
+def sigshow(*args):
+    print "----"
+    traceback.print_stack(args[1], limit=10)
+    print "----"
+
+def extsetup(ui):
+    signal.signal(signal.SIGQUIT, sigshow)