mirror of
https://github.com/facebook/sapling.git
synced 2024-10-16 11:52:02 +03:00
584656dff3
Summary: Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`. Then run `arc lint` again so some other autofixers like spellchecker etc. looked at the code base. Manually accept the changes whenever they make sense, or use a workaround (ex. changing "dict()" to "dict constructor") where autofix is false positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less interesting to fix (hgsubversion tests), or cannot be fixed without breaking OSS build (FBPYTHON4). Conflicted linters (test-check-module-imports.t, part of test-check-code.t, test-check-pyflakes.t) are removed or disabled. Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed. An issue of the auto-formatter is lines are no longer guarnateed to be <= 80 chars. But that seems less important comparing with the benefit auto-formatter provides. As we're here, also remove test-check-py3-compat.t, as it is currently broken if `PYTHON3=/bin/python3` is set. Reviewed By: wez, phillco, simpkins, pkaush, singhsrb Differential Revision: D8173629 fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
83 lines
2.2 KiB
Python
83 lines
2.2 KiB
Python
# sigtrace.py
|
|
#
|
|
# Copyright 2017 Facebook, Inc.
|
|
#
|
|
# This software may be used and distributed according to the terms of the
|
|
# GNU General Public License version 2 or any later version.
|
|
|
|
"""sigtrace - dump stack and memory traces on signal
|
|
|
|
By default, SIGUSR1 will make hg dump stacks of all threads and SIGUSR2 will
|
|
dump memory traces. All traces are dumped to /tmp by default.
|
|
|
|
Config::
|
|
|
|
[sigtrace]
|
|
signal = USR1
|
|
memsignal = USR2
|
|
pathformat = /tmp/trace-%(pid)s-%(time)s.log
|
|
mempathformat = /tmp/memtrace-%(pid)s-%(time)s.log
|
|
"""
|
|
|
|
import os
|
|
import signal
|
|
import sys
|
|
import time
|
|
import traceback
|
|
|
|
from mercurial import registrar
|
|
|
|
|
|
pathformat = "/tmp/trace-%(pid)s-%(time)s.log"
|
|
mempathformat = "/tmp/memtrace-%(pid)s-%(time)s.log"
|
|
|
|
configtable = {}
|
|
configitem = registrar.configitem(configtable)
|
|
|
|
configitem("sigtrace", "pathformat", default=pathformat)
|
|
configitem("sigtrace", "signal", default="USR1")
|
|
configitem("sigtrace", "mempathformat", default=mempathformat)
|
|
configitem("sigtrace", "memsignal", default="USR2")
|
|
|
|
|
|
def printstacks(sig, currentframe):
|
|
content = ""
|
|
for tid, frame in sys._current_frames().iteritems():
|
|
content += "Thread %s:\n%s\n" % (tid, "".join(traceback.format_stack(frame)))
|
|
|
|
with open(pathformat % {"time": time.time(), "pid": os.getpid()}, "w") as f:
|
|
f.write(content)
|
|
|
|
|
|
memorytracker = []
|
|
|
|
|
|
def printmemory(sig, currentframe):
|
|
try:
|
|
from pympler import muppy, summary
|
|
|
|
muppy.get_objects
|
|
except ImportError:
|
|
return
|
|
|
|
all_objects = muppy.get_objects()
|
|
sum1 = summary.summarize(all_objects)
|
|
path = mempathformat % {"time": time.time(), "pid": os.getpid()}
|
|
with open(path, "w") as f:
|
|
f.write("\n".join(summary.format_(sum1, limit=50, sort="#")))
|
|
|
|
|
|
def uisetup(ui):
|
|
global pathformat, mempathformat
|
|
pathformat = ui.config("sigtrace", "pathformat")
|
|
mempathformat = ui.config("sigtrace", "mempathformat")
|
|
signame = ui.config("sigtrace", "signal")
|
|
sig = getattr(signal, "SIG" + signame, None)
|
|
if sig is not None:
|
|
signal.signal(sig, printstacks)
|
|
|
|
sig2name = ui.config("sigtrace", "memsignal")
|
|
sig2 = getattr(signal, "SIG" + sig2name, None)
|
|
if sig2:
|
|
signal.signal(sig2, printmemory)
|