aboutsummaryrefslogtreecommitdiffstats
path: root/debug_toolbar/panels
diff options
context:
space:
mode:
authorAlex Gaynor2009-03-21 12:17:05 -0400
committerAlex Gaynor2009-03-21 12:17:05 -0400
commit4ffe14db039981d06aa58f3ad3c2b3472824961b (patch)
treeb6a94348f2c20bfb6c29303227889d70f06c62c3 /debug_toolbar/panels
parent0fea345f0d59ed0f17f29e59072f34d7d016abde (diff)
parent8c64bb0cc82c6129b4ab14ff4cc80880761680d4 (diff)
downloaddjango-debug-toolbar-4ffe14db039981d06aa58f3ad3c2b3472824961b.tar.bz2
resoled merge conflicts
Diffstat (limited to 'debug_toolbar/panels')
-rw-r--r--debug_toolbar/panels/sql.py18
-rw-r--r--debug_toolbar/panels/template.py12
-rw-r--r--debug_toolbar/panels/timer.py63
3 files changed, 80 insertions, 13 deletions
diff --git a/debug_toolbar/panels/sql.py b/debug_toolbar/panels/sql.py
index 7584bd7..b041bf8 100644
--- a/debug_toolbar/panels/sql.py
+++ b/debug_toolbar/panels/sql.py
@@ -19,7 +19,7 @@ class DatabaseStatTracker(util.CursorDebugWrapper):
return self.cursor.execute(sql, params)
finally:
stop = time.time()
- _params = None
+ _params = ''
try:
_params = simplejson.dumps([force_unicode(x) for x in params])
except TypeError:
@@ -27,7 +27,7 @@ class DatabaseStatTracker(util.CursorDebugWrapper):
# We keep `sql` to maintain backwards compatibility
self.db.queries.append({
'sql': self.db.ops.last_executed_query(self.cursor, sql, params),
- 'time': stop - start,
+ 'time': (stop - start) * 1000, # convert to ms
'raw_sql': sql,
'params': _params,
'hash': sha_constructor(settings.SECRET_KEY + sql + _params).hexdigest(),
@@ -47,10 +47,11 @@ class SQLDebugPanel(DebugPanel):
self._sql_time = 0
def title(self):
- self._sql_time = sum(map(lambda q: float(q['time']) * 1000, connection.queries))
+ self._sql_time = sum(map(lambda q: float(q['time']), connection.queries))
+ num_queries = len(connection.queries) - self._offset
return '%d SQL %s (%.2fms)' % (
- len(connection.queries),
- (len(connection.queries) == 1) and 'query' or 'queries',
+ num_queries,
+ (num_queries == 1) and 'query' or 'queries',
self._sql_time
)
@@ -65,6 +66,7 @@ class SQLDebugPanel(DebugPanel):
context = {
'queries': sql_queries,
'sql_time': self._sql_time,
+ 'is_mysql': settings.DATABASE_ENGINE == 'mysql',
}
return render_to_string('debug_toolbar/panels/sql.html', context)
@@ -73,9 +75,11 @@ def reformat_sql(sql):
sql = sql.replace('SELECT ', 'SELECT\n\t')
sql = sql.replace(' FROM ', '\nFROM\n\t')
sql = sql.replace(' WHERE ', '\nWHERE\n\t')
- sql = sql.replace(' INNER JOIN ', '\nINNER JOIN\n\t')
- sql = sql.replace(' OUTER JOIN ', '\nOUTER JOIN\n\t')
+ sql = sql.replace(' INNER JOIN', '\n\tINNER JOIN')
+ sql = sql.replace(' LEFT OUTER JOIN' , '\n\tLEFT OUTER JOIN')
sql = sql.replace(' ORDER BY ', '\nORDER BY\n\t')
+ sql = sql.replace(' HAVING ', '\nHAVING\n\t')
+ sql = sql.replace(' GROUP BY ', '\nGROUP BY\n\t')
# Use Pygments to highlight SQL if it's available
try:
from pygments import highlight
diff --git a/debug_toolbar/panels/template.py b/debug_toolbar/panels/template.py
index fa85cb8..7dc7b06 100644
--- a/debug_toolbar/panels/template.py
+++ b/debug_toolbar/panels/template.py
@@ -48,11 +48,15 @@ class TemplateDebugPanel(DebugPanel):
return ''
def process_request(self, request):
- self.context_processors = dict(
- [("%s.%s" % (k.__module__, k.__name__), pformat(k(request))) for k in get_standard_processors()]
- )
+ self.request = request
def content(self):
+ context_processors = dict(
+ [
+ ("%s.%s" % (k.__module__, k.__name__),
+ pformat(k(self.request))) for k in get_standard_processors()
+ ]
+ )
template_context = []
for i, d in enumerate(self.templates):
info = {}
@@ -73,6 +77,6 @@ class TemplateDebugPanel(DebugPanel):
context = {
'templates': template_context,
'template_dirs': [normpath(x) for x in settings.TEMPLATE_DIRS],
- 'context_processors': self.context_processors,
+ 'context_processors': context_processors,
}
return render_to_string('debug_toolbar/panels/templates.html', context)
diff --git a/debug_toolbar/panels/timer.py b/debug_toolbar/panels/timer.py
index ea8ed4a..352bf55 100644
--- a/debug_toolbar/panels/timer.py
+++ b/debug_toolbar/panels/timer.py
@@ -1,23 +1,82 @@
+try:
+ import resource
+except ImportError:
+ pass # Will fail on Win32 systems
import time
+from django.template.loader import render_to_string
from debug_toolbar.panels import DebugPanel
+
class TimerDebugPanel(DebugPanel):
"""
Panel that displays the time a response took in milliseconds.
"""
name = 'Timer'
+ try: # if resource module not available, don't show content panel
+ resource
+ except NameError:
+ has_content = False
+ has_resource = False
+ else:
+ has_content = True
+ has_resource = True
def process_request(self, request):
self._start_time = time.time()
+ if self.has_resource:
+ self._start_rusage = resource.getrusage(resource.RUSAGE_SELF)
def process_response(self, request, response):
self.total_time = (time.time() - self._start_time) * 1000
+ if self.has_resource:
+ self._end_rusage = resource.getrusage(resource.RUSAGE_SELF)
def title(self):
- return 'Time: %0.2fms' % (self.total_time)
+ if self.has_resource:
+ utime = self._end_rusage.ru_utime - self._start_rusage.ru_utime
+ stime = self._end_rusage.ru_stime - self._start_rusage.ru_stime
+ return 'Time: %0.2fms, %0.2fms CPU' % (self.total_time, (utime + stime) * 1000.0)
+ else:
+ return 'Time: %0.2fms' % (self.total_time)
def url(self):
return ''
+ def _elapsed_ru(self, name):
+ return getattr(self._end_rusage, name) - getattr(self._start_rusage, name)
+
def content(self):
- return ''
+
+ utime = 1000 * self._elapsed_ru('ru_utime')
+ stime = 1000 * self._elapsed_ru('ru_stime')
+ vcsw = self._elapsed_ru('ru_nvcsw')
+ ivcsw = self._elapsed_ru('ru_nivcsw')
+ minflt = self._elapsed_ru('ru_minflt')
+ majflt = self._elapsed_ru('ru_majflt')
+
+# these are documented as not meaningful under Linux. If you're running BSD
+# feel free to enable them, and add any others that I hadn't gotten to before
+# I noticed that I was getting nothing but zeroes and that the docs agreed. :-(
+#
+# blkin = self._elapsed_ru('ru_inblock')
+# blkout = self._elapsed_ru('ru_oublock')
+# swap = self._elapsed_ru('ru_nswap')
+# rss = self._end_rusage.ru_maxrss
+# srss = self._end_rusage.ru_ixrss
+# urss = self._end_rusage.ru_idrss
+# usrss = self._end_rusage.ru_isrss
+
+ rows = (
+ ('User CPU time', '%0.3f msec' % utime),
+ ('System CPU time', '%0.3f msec' % stime),
+ ('Total CPU time', '%0.3f msec' % (utime + stime)),
+ ('Elapsed time', '%0.3f msec' % self.total_time),
+ ('Context switches', '%d voluntary, %d involuntary' % (vcsw, ivcsw)),
+# ('Memory use', '%d max RSS, %d shared, %d unshared' % (rss, srss, urss + usrss)),
+# ('Page faults', '%d no i/o, %d requiring i/o' % (minflt, majflt)),
+# ('Disk operations', '%d in, %d out, %d swapout' % (blkin, blkout, swap)),
+ )
+ context = {
+ 'rows': rows,
+ }
+ return render_to_string('debug_toolbar/panels/timer.html', context)