diff options
| author | David Cramer | 2011-03-24 17:34:55 -0700 |
|---|---|---|
| committer | David Cramer | 2011-03-24 17:34:55 -0700 |
| commit | 79ddcefb629612da3fb05ccbb8b602d1f026b1f9 (patch) | |
| tree | 45aef5f80eb901e1aaa5d348925b0951c67b3ef2 /debug_toolbar/panels/sql.py | |
| parent | 4bb644ad825ed9009176c7e78967b6ba07d7a681 (diff) | |
| download | django-debug-toolbar-79ddcefb629612da3fb05ccbb8b602d1f026b1f9.tar.bz2 | |
basic color code grouping of db aliases
Diffstat (limited to 'debug_toolbar/panels/sql.py')
| -rw-r--r-- | debug_toolbar/panels/sql.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/debug_toolbar/panels/sql.py b/debug_toolbar/panels/sql.py index 15c6ff3..19a4767 100644 --- a/debug_toolbar/panels/sql.py +++ b/debug_toolbar/panels/sql.py @@ -1,4 +1,5 @@ from datetime import datetime +import itertools import os import re import sys @@ -191,9 +192,21 @@ class SQLDebugPanel(DebugPanel): def content(self): width_ratio_tally = 0 + colors = [ + (256, 0, 0), # red + (0, 256, 0), # blue + (0, 0, 256), # green + ] + for n, db in enumerate(self._databases.itervalues()): + rgb = [0, 0, 0] + color = n % 3 + rgb[color] = 256 - n/3*32 + db['rgb_color'] = rgb + for alias, query in self._queries: query['alias'] = alias query['sql'] = reformat_sql(query['sql']) + query['rgb_color'] = self._databases[alias]['rgb_color'] try: query['width_ratio'] = (query['duration'] / self._sql_time) * 100 except ZeroDivisionError: @@ -207,7 +220,7 @@ class SQLDebugPanel(DebugPanel): params = map(escape, frame[0].rsplit('/', 1) + list(frame[1:])) stacktrace.append('<span class="path">{0}/</span><span class="file">{1}</span> in <span class="func">{3}</span>(<span class="lineno">{2}</span>)\n <span class="code">{4}</span>"'.format(*params)) query['stacktrace'] = mark_safe('\n'.join(stacktrace)) - + context = self.context.copy() context.update({ 'databases': sorted(self._databases.items(), key=lambda x: -x[1]['time_spent']), |
