diff options
| author | Alex Gaynor | 2009-03-21 17:37:42 -0400 | 
|---|---|---|
| committer | Alex Gaynor | 2009-03-21 17:37:42 -0400 | 
| commit | 671bac94182b000be3960dc7c83e89ccef7ccf26 (patch) | |
| tree | c15d284652b46ba5c7751c42989f667f18dcd606 /debug_toolbar/panels/sql.py | |
| parent | 4ffe14db039981d06aa58f3ad3c2b3472824961b (diff) | |
| parent | 30ab58a69510f3fd35e19f6be9b669d2fdf956c0 (diff) | |
| download | django-debug-toolbar-671bac94182b000be3960dc7c83e89ccef7ccf26.tar.bz2 | |
Merge commit 'rob/master'
Diffstat (limited to 'debug_toolbar/panels/sql.py')
| -rw-r--r-- | debug_toolbar/panels/sql.py | 29 | 
1 files changed, 28 insertions, 1 deletions
| diff --git a/debug_toolbar/panels/sql.py b/debug_toolbar/panels/sql.py index b041bf8..d3ac7f3 100644 --- a/debug_toolbar/panels/sql.py +++ b/debug_toolbar/panels/sql.py @@ -1,5 +1,8 @@ +import os +import SocketServer  import time -from debug_toolbar.panels import DebugPanel +import traceback +import django  from django.conf import settings  from django.db import connection  from django.db.backends import util @@ -7,6 +10,28 @@ from django.template.loader import render_to_string  from django.utils import simplejson  from django.utils.encoding import force_unicode  from django.utils.hashcompat import sha_constructor +from debug_toolbar.panels import DebugPanel + +# Figure out some paths +django_path = os.path.realpath(os.path.dirname(django.__file__)) +socketserver_path = os.path.realpath(os.path.dirname(SocketServer.__file__)) + +def tidy_stacktrace(strace): +    """ +    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) +    """ +    trace = [] +    for s in strace[:-1]: +        s_path = os.path.realpath(s[0]) +        if 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])) +    return trace  class DatabaseStatTracker(util.CursorDebugWrapper):      """ @@ -19,6 +44,7 @@ class DatabaseStatTracker(util.CursorDebugWrapper):              return self.cursor.execute(sql, params)          finally:              stop = time.time() +            stacktrace = tidy_stacktrace(traceback.extract_stack())              _params = ''              try:                  _params = simplejson.dumps([force_unicode(x) for x in params]) @@ -31,6 +57,7 @@ class DatabaseStatTracker(util.CursorDebugWrapper):                  'raw_sql': sql,                  'params': _params,                  'hash': sha_constructor(settings.SECRET_KEY + sql + _params).hexdigest(), +                'stacktrace': stacktrace,              })  util.CursorDebugWrapper = DatabaseStatTracker | 
