diff options
| -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> |
