Permalink
Browse files

refactor call wrapping code and better display of arguments and keys

  • Loading branch information...
1 parent 5fb925e commit 349aeb78b2b7e94c14290e883f217c2aa8f51588 @clement committed May 2, 2012
Showing with 24 additions and 19 deletions.
  1. +24 −19 redis_panel.py
View
@@ -24,17 +24,27 @@
redis_call = Signal(providing_args=['duration', 'calls'])
-class TrackingRedisMixin(object):
- def execute_command(self, func_name, *args, **kwargs):
+class TrackingRedisBase(object):
+ def make_call_dict(self, depth, *args, **kwargs):
debug_config = getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {})
enable_stack = debug_config.get('ENABLE_STACKTRACES', True)
- trace = enable_stack and tidy_stacktrace(reversed(get_stack()))[:-2] or []
+ trace = enable_stack and tidy_stacktrace(reversed(get_stack()))[:-depth-1] or []
+
+ # prepare arguments for display
+ arguments = map(repr, args[2:])
+ options = map(lambda (k, v): "%s=%s" % (k, repr(v)), kwargs.items())
- call = { 'function': func_name,
- 'args': map(unicode, args + tuple(kwargs.values())),
+ return { 'function': args[0],
+ 'key': len(args) > 1 and args[1] or '',
+ 'args': ' , '.join(arguments + options),
'trace': trace }
+
+class TrackingRedisMixin(TrackingRedisBase):
+ def execute_command(self, func_name, *args, **kwargs):
+ call = self.make_call_dict(2, func_name, *args, **kwargs)
+
try:
start = time.time()
ret = super(TrackingRedisMixin, self).execute_command(func_name,
@@ -48,31 +58,24 @@ def execute_command(self, func_name, *args, **kwargs):
return ret
-class BaseTrackingPipeline(BasePipeline):
+class BaseTrackingPipeline(TrackingRedisBase, BasePipeline):
def execute(self, *args, **kw):
- debug_config = getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {})
- enable_stack = debug_config.get('ENABLE_STACKTRACES', True)
-
- trace = enable_stack and tidy_stacktrace(reversed(get_stack()))[:-1] or []
-
- transaction = {'calls': []}
+ tr = {'calls': []}
for arguments, options in self.command_stack:
- transaction['calls'].append({'function': arguments[0],
- 'args': map(unicode, tuple(arguments[1:]) + tuple(options.values())),
- 'trace': trace})
+ tr['calls'].append(self.make_call_dict(1, *arguments, **options))
try:
start = time.time()
ret = super(BaseTrackingPipeline, self).execute(*args, **kw)
- for i, call in enumerate(transaction['calls']):
+ for i, call in enumerate(tr['calls']):
call['return'] = unicode(ret[i])
finally:
stop = time.time()
- transaction['duration'] = (stop - start) * 1000
+ tr['duration'] = (stop - start) * 1000
- redis_call.send_robust(sender=self, **transaction)
+ redis_call.send_robust(sender=self, **tr)
return ret
@@ -177,6 +180,7 @@ def render_stacktrace(trace):
<tr>
<th>{% trans "Duration" %}</th>
<th>{% trans "Call" %}</th>
+ <th>{% trans "Key" %}</th>
<th>{% trans "Args" %}</th>
<th>{% trans "Result" %}</th>
<th>{% trans "Action" %}</th>
@@ -189,14 +193,15 @@ def render_stacktrace(trace):
<tr>
<td>{% if forloop.first %}{{ tr.duration }} ms{% endif %}</td>
<td>{{ call.function }}</td>
+ <td>{{ call.key }}</td>
<td>{{ call.args }}</td>
<td>{{ call.return }}</td>
<td><a href="#" class="djdtRedisShowTrace">{% trans "Show stacktrace" %}</a></td>
</tr>
{% if call.trace %}
<tr class="djdtRedisTrace" style="display:none">
- <td colspan="5">
+ <td colspan="6">
<pre class="stack">{{ call.trace }}</pre>
</td>
</tr>

0 comments on commit 349aeb7

Please sign in to comment.