aboutsummaryrefslogtreecommitdiffstats
path: root/debug_toolbar/utils
diff options
context:
space:
mode:
Diffstat (limited to 'debug_toolbar/utils')
-rw-r--r--debug_toolbar/utils/__init__.py42
-rw-r--r--debug_toolbar/utils/tracking/db.py7
2 files changed, 37 insertions, 12 deletions
diff --git a/debug_toolbar/utils/__init__.py b/debug_toolbar/utils/__init__.py
index 61bb717..c4dc160 100644
--- a/debug_toolbar/utils/__init__.py
+++ b/debug_toolbar/utils/__init__.py
@@ -15,29 +15,39 @@ def ms_from_timedelta(td):
"""
return (td.seconds * 1000) + (td.microseconds / 1000.0)
-def tidy_stacktrace(strace):
+def tidy_stacktrace(stack):
"""
Clean up stacktrace and remove all entries that:
1. Are part of Django (except contrib apps)
2. Are part of SocketServer (used by Django's dev server)
3. Are the last entry (which is part of our stacktracing code)
+
+ ``stack`` should be a list of frame tuples from ``inspect.stack()``
"""
trace = []
- for s in strace[:-1]:
- s_path = os.path.realpath(s[0])
+ for frame, path, line_no, func_name, text in (f[:5] for f in stack):
+ s_path = os.path.realpath(path)
+ # Support hiding of frames -- used in various utilities that provide
+ # inspection.
+ if '__traceback_hide__' in frame.f_locals:
+ continue
if getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {}).get('HIDE_DJANGO_SQL', True) \
and django_path in s_path and not 'django/contrib' in s_path:
continue
if socketserver_path in s_path:
continue
- trace.append((s[0], s[1], s[2], s[3]))
+ if not text:
+ text = ''
+ else:
+ text = (''.join(text)).strip()
+ trace.append((path, line_no, func_name, text))
return trace
def get_template_info(source, context_lines=3):
line = 0
upto = 0
source_lines = []
- before = during = after = ""
+ # before = during = after = ""
origin, (start, end) = source
template_source = origin.reload()
@@ -45,9 +55,9 @@ def get_template_info(source, context_lines=3):
for num, next in enumerate(linebreak_iter(template_source)):
if start >= upto and end <= next:
line = num
- before = template_source[upto:start]
- during = template_source[start:end]
- after = template_source[end:next]
+ # before = template_source[upto:start]
+ # during = template_source[start:end]
+ # after = template_source[end:next]
source_lines.append((num, template_source[upto:next]))
upto = next
@@ -65,4 +75,18 @@ def get_template_info(source, context_lines=3):
return {
'name': origin.name,
'context': context,
- } \ No newline at end of file
+ }
+
+def get_name_from_obj(obj):
+ if hasattr(obj, '__name__'):
+ name = obj.__name__
+ elif hasattr(obj, '__class__') and hasattr(obj.__class__, '__name__'):
+ name = obj.__class__.__name__
+ else:
+ name = '<unknown>'
+
+ if hasattr(obj, '__module__'):
+ module = obj.__module__
+ name = '%s.%s' % (module, name)
+
+ return name \ No newline at end of file
diff --git a/debug_toolbar/utils/tracking/db.py b/debug_toolbar/utils/tracking/db.py
index 87f4550..7ffacef 100644
--- a/debug_toolbar/utils/tracking/db.py
+++ b/debug_toolbar/utils/tracking/db.py
@@ -1,5 +1,5 @@
+import inspect
import sys
-import traceback
from datetime import datetime
@@ -29,13 +29,14 @@ class CursorWrapper(object):
self.logger = logger
def execute(self, sql, params=()):
+ __traceback_hide__ = True
start = datetime.now()
try:
return self.cursor.execute(sql, params)
finally:
stop = datetime.now()
duration = ms_from_timedelta(stop - start)
- stacktrace = tidy_stacktrace(traceback.extract_stack())
+ stacktrace = tidy_stacktrace(reversed(inspect.stack()))
_params = ''
try:
_params = simplejson.dumps([force_unicode(x, strings_only=True) for x in params])
@@ -56,7 +57,7 @@ class CursorWrapper(object):
pass
del cur_frame
- alias = getattr(self, 'alias', 'default')
+ alias = getattr(self.db, 'alias', 'default')
conn = connections[alias].connection
# HACK: avoid imports
if conn: