diff options
| author | Martin Maney | 2008-11-08 19:48:18 -0600 |
|---|---|---|
| committer | Rob Hudson | 2008-12-09 14:01:31 -0800 |
| commit | 47d1a4ff38bc48a6dd54246556434a72c0476bb0 (patch) | |
| tree | 9ecd55f191e8eeb60ae7e2806f9962bcc1956a6c | |
| parent | d58f119fc17bd15edee5f3ac783703a8aec534b8 (diff) | |
| download | django-debug-toolbar-47d1a4ff38bc48a6dd54246556434a72c0476bb0.tar.bz2 | |
Added more of the rusage stats in a drop-down panel
(some items were commented out after I was reminded that not all of the original BSD items are supported under Linux)
| -rw-r--r-- | debug_toolbar/panels/timer.py | 43 | ||||
| -rw-r--r-- | debug_toolbar/templates/debug_toolbar/panels/timer.html | 7 |
2 files changed, 49 insertions, 1 deletions
diff --git a/debug_toolbar/panels/timer.py b/debug_toolbar/panels/timer.py index a1d6355..b93c843 100644 --- a/debug_toolbar/panels/timer.py +++ b/debug_toolbar/panels/timer.py @@ -1,11 +1,16 @@ import time, resource + +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() @@ -23,5 +28,41 @@ class TimerDebugPanel(DebugPanel): 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/timer.html b/debug_toolbar/templates/debug_toolbar/panels/timer.html new file mode 100644 index 0000000..161507c --- /dev/null +++ b/debug_toolbar/templates/debug_toolbar/panels/timer.html @@ -0,0 +1,7 @@ +<h3>Resource Usage</h3> +<table> + <colgroup><col width="50%" align="right" /><col width="50%" /></colgroup> + {% for row in rows %} + <tr><td align="right">{{ row.1 }}</td><th>{{ row.0 }}</th></tr> + {% endfor %} +</table> |
