Use hunter for line tracing.
This commit is contained in:
parent
a98060e020
commit
eb3b0b960f
@ -36,6 +36,10 @@ from PyQt5.QtWidgets import QApplication, QDialog, QMessageBox
|
||||
from PyQt5.QtGui import QDesktopServices, QPixmap, QIcon
|
||||
from PyQt5.QtCore import (pyqtSlot, qInstallMessageHandler, QTimer, QUrl,
|
||||
QObject, Qt, QSocketNotifier)
|
||||
try:
|
||||
import hunter
|
||||
except ImportError:
|
||||
hunter = None
|
||||
|
||||
import qutebrowser
|
||||
import qutebrowser.resources # pylint: disable=unused-import
|
||||
@ -50,7 +54,7 @@ from qutebrowser.misc import (crashdialog, readline, ipc, earlyinit,
|
||||
from qutebrowser.misc import utilcmds # pylint: disable=unused-import
|
||||
from qutebrowser.keyinput import modeman
|
||||
from qutebrowser.utils import (log, version, message, utils, qtutils, urlutils,
|
||||
debug, objreg, usertypes, standarddir)
|
||||
objreg, usertypes, standarddir)
|
||||
# We import utilcmds to run the cmdutils.register decorators.
|
||||
|
||||
|
||||
@ -924,6 +928,10 @@ class Application(QApplication):
|
||||
"""Extend QApplication::exit to log the event."""
|
||||
log.destroy.debug("Now calling QApplication::exit.")
|
||||
if self._args.debug_exit:
|
||||
print("Now logging late shutdown.", file=sys.stderr)
|
||||
debug.trace_lines(True)
|
||||
if hunter is None:
|
||||
print("Not logging late shutdown because hunter could not be "
|
||||
"imported!", file=sys.stderr)
|
||||
else:
|
||||
print("Now logging late shutdown.", file=sys.stderr)
|
||||
hunter.trace()
|
||||
super().exit(status)
|
||||
|
@ -20,6 +20,13 @@
|
||||
At this point we can be sure we have all python 3.4 features available.
|
||||
"""
|
||||
|
||||
try:
|
||||
# Importing hunter to register its atexit handler early so it gets called
|
||||
# late.
|
||||
import hunter # pylint: disable=import-error,unused-import
|
||||
except ImportError:
|
||||
hunter = None
|
||||
|
||||
import os
|
||||
import sys
|
||||
import faulthandler
|
||||
|
@ -24,6 +24,10 @@ import functools
|
||||
import types
|
||||
|
||||
from PyQt5.QtCore import QCoreApplication
|
||||
try:
|
||||
import hunter
|
||||
except ImportError:
|
||||
hunter = None
|
||||
|
||||
from qutebrowser.utils import log, objreg, usertypes
|
||||
from qutebrowser.commands import cmdutils, runners, cmdexc
|
||||
@ -119,6 +123,22 @@ def debug_console():
|
||||
con_widget.show()
|
||||
|
||||
|
||||
@cmdutils.register(debug=True, maxsplit=0)
|
||||
def debug_trace(expr=""):
|
||||
"""Trace executed code via hunter.
|
||||
|
||||
Args:
|
||||
expr: What to trace, passed to hunter.
|
||||
"""
|
||||
if hunter is None:
|
||||
raise cmdexc.CommandError("You need to install 'hunter' to use this "
|
||||
"command!")
|
||||
try:
|
||||
eval('hunter.trace({})'.format(expr))
|
||||
except Exception as e:
|
||||
raise cmdexc.CommandError("{}: {}".format(e.__class__.__name__, e))
|
||||
|
||||
|
||||
@cmdutils.register(hide=True)
|
||||
def fooled():
|
||||
"""Turn off april's fools."""
|
||||
|
@ -20,7 +20,6 @@
|
||||
"""Utilities used for debugging."""
|
||||
|
||||
import re
|
||||
import sys
|
||||
import inspect
|
||||
import functools
|
||||
import datetime
|
||||
@ -87,36 +86,6 @@ def log_signals(obj):
|
||||
connect_log_slot(obj)
|
||||
|
||||
|
||||
def trace_lines(do_trace):
|
||||
"""Turn on/off printing each executed line.
|
||||
|
||||
Args:
|
||||
do_trace: Whether to start tracing (True) or stop it (False).
|
||||
"""
|
||||
def trace(frame, event, arg):
|
||||
"""Trace function passed to sys.settrace.
|
||||
|
||||
Return:
|
||||
Itself, so tracing continues.
|
||||
"""
|
||||
if sys is not None:
|
||||
loc = '{}:{}'.format(frame.f_code.co_filename, frame.f_lineno)
|
||||
if arg is not None:
|
||||
arg = utils.compact_text(str(arg), 200)
|
||||
else:
|
||||
arg = ''
|
||||
print("{:11} {:80} {}".format(event, loc, arg), file=sys.stderr)
|
||||
return trace
|
||||
else:
|
||||
# When tracing while shutting down, it seems sys can be None
|
||||
# sometimes... if that's the case, we stop tracing.
|
||||
return None
|
||||
if do_trace:
|
||||
sys.settrace(trace)
|
||||
else:
|
||||
sys.settrace(None)
|
||||
|
||||
|
||||
def qenum_key(base, value, add_base=False, klass=None):
|
||||
"""Convert a Qt Enum value to its key as a string.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user