aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--debug_toolbar/panels/sql.py8
-rw-r--r--debug_toolbar/panels/timer.py48
-rw-r--r--debug_toolbar/templates/debug_toolbar/panels/sql.html4
-rw-r--r--debug_toolbar/templates/debug_toolbar/panels/timer.html21
4 files changed, 75 insertions, 6 deletions
diff --git a/debug_toolbar/panels/sql.py b/debug_toolbar/panels/sql.py
index fc53247..7396c3a 100644
--- a/debug_toolbar/panels/sql.py
+++ b/debug_toolbar/panels/sql.py
@@ -48,9 +48,10 @@ class SQLDebugPanel(DebugPanel):
def title(self):
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)
@@ -74,7 +76,7 @@ def reformat_sql(sql):
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(' LEFT OUTER JOIN ', '\nLEFT OUTER JOIN\n\t')
sql = sql.replace(' ORDER BY ', '\nORDER BY\n\t')
# Use Pygments to highlight SQL if it's available
try:
diff --git a/debug_toolbar/panels/timer.py b/debug_toolbar/panels/timer.py
index ea8ed4a..cafdb05 100644
--- a/debug_toolbar/panels/timer.py
+++ b/debug_toolbar/panels/timer.py
@@ -1,23 +1,67 @@
+import resource
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'
+ has_content = True
def process_request(self, request):
self._start_time = time.time()
+ self._start_rusage = resource.getrusage(resource.RUSAGE_SELF)
def process_response(self, request, response):
self.total_time = (time.time() - self._start_time) * 1000
+ self._end_rusage = resource.getrusage(resource.RUSAGE_SELF)
def title(self):
- return 'Time: %0.2fms' % (self.total_time)
+ 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)
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)
diff --git a/debug_toolbar/templates/debug_toolbar/panels/sql.html b/debug_toolbar/templates/debug_toolbar/panels/sql.html
index f6ff64f..7de2220 100644
--- a/debug_toolbar/templates/debug_toolbar/panels/sql.html
+++ b/debug_toolbar/templates/debug_toolbar/panels/sql.html
@@ -15,7 +15,9 @@
{% if query.params %}
<a class="remoteCall" href="/__debug__/sql_select/?sql={{ query.raw_sql|urlencode }}&params={{ query.params|urlencode }}&time={{ query.time|floatformat:"2"|urlencode }}&hash={{ query.hash }}">SELECT</a>
<a class="remoteCall" href="/__debug__/sql_explain/?sql={{ query.raw_sql|urlencode }}&params={{ query.params|urlencode }}&time={{ query.time|floatformat:"2"|urlencode }}&hash={{ query.hash }}">EXPLAIN</a>
- <a class="remoteCall" href="/__debug__/sql_profile/?sql={{ query.raw_sql|urlencode }}&params={{ query.params|urlencode }}&time={{ query.time|floatformat:"2"|urlencode }}&hash={{ query.hash }}">PROFILE</a>
+ {% if is_mysql %}
+ <a class="remoteCall" href="/__debug__/sql_profile/?sql={{ query.raw_sql|urlencode }}&params={{ query.params|urlencode }}&time={{ query.time|floatformat:"2"|urlencode }}&hash={{ query.hash }}">PROFILE</a>
+ {% endif %}
{% endif %}
</td>
<td class="syntax">{{ query.sql|safe }}</td>
diff --git a/debug_toolbar/templates/debug_toolbar/panels/timer.html b/debug_toolbar/templates/debug_toolbar/panels/timer.html
new file mode 100644
index 0000000..1b077c6
--- /dev/null
+++ b/debug_toolbar/templates/debug_toolbar/panels/timer.html
@@ -0,0 +1,21 @@
+<h3>Resource Usage</h3>
+<table>
+ <colgroup>
+ <col style="width:20%"/>
+ <col/>
+ </colgroup>
+ <thead>
+ <tr>
+ <th>Key</th>
+ <th>Value</th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for key, value in rows %}
+ <tr class="{% cycle 'odd' 'even' %}">
+ <td>{{ key|escape }}</td>
+ <td>{{ value|escape }}</td>
+ </tr>
+ {% endfor %}
+ </tbody>
+</table>