aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--debug_toolbar/__init__.py4
-rw-r--r--debug_toolbar/panels/cache.py89
-rw-r--r--debug_toolbar/templates/debug_toolbar/panels/cache.html12
-rw-r--r--debug_toolbar/toolbar/loader.py79
4 files changed, 116 insertions, 68 deletions
diff --git a/debug_toolbar/__init__.py b/debug_toolbar/__init__.py
index 48da4a6..d0bc5b8 100644
--- a/debug_toolbar/__init__.py
+++ b/debug_toolbar/__init__.py
@@ -5,3 +5,7 @@ try:
.get_distribution('django-debug-toolbar').version
except Exception, e:
VERSION = 'unknown'
+
+from debug_toolbar.toolbar.loader import load_panel_classes
+
+load_panel_classes()
diff --git a/debug_toolbar/panels/cache.py b/debug_toolbar/panels/cache.py
index aa37858..e3b9dad 100644
--- a/debug_toolbar/panels/cache.py
+++ b/debug_toolbar/panels/cache.py
@@ -1,5 +1,6 @@
import time
import inspect
+import sys
from django.core import cache
from django.core.cache.backends.base import BaseCache
@@ -19,17 +20,18 @@ class CacheStatTracker(BaseCache):
self.misses = 0
self.sets = 0
self.gets = 0
- self.get_many = 0
+ self.get_manys = 0
self.deletes = 0
self.total_time = 0
def _get_func_info(self):
- stack = inspect.stack()[2]
- return (stack[1], stack[2], stack[3], stack[4])
+ frame = sys._getframe(3)
+ info = inspect.getframeinfo(frame)
+ return (info[0], info[1], info[2], info[3])
- def get(self, key, **kwargs):
+ def get(self, *args, **kwargs):
t = time.time()
- value = self.cache.get(key, **kwargs)
+ value = self.cache.get(*args, **kwargs)
this_time = time.time() - t
self.total_time += this_time * 1000
if value is None:
@@ -37,37 +39,74 @@ class CacheStatTracker(BaseCache):
else:
self.hits += 1
self.gets += 1
- self.calls.append((this_time, 'get', (key,), self._get_func_info()))
+ self.calls.append((this_time, 'get', args, kwargs, self._get_func_info()))
return value
- def set(self, key, value, timeout=None, **kwargs):
+ def set(self, *args, **kwargs):
t = time.time()
- self.cache.set(key, value, timeout, **kwargs)
+ self.cache.set(*args, **kwargs)
this_time = time.time() - t
self.total_time += this_time * 1000
self.sets += 1
- self.calls.append((this_time, 'set', (key, value, timeout), self._get_func_info()))
+ self.calls.append((this_time, 'set', args, kwargs, self._get_func_info()))
- def delete(self, key, **kwargs):
+ def delete(self, *args, **kwargs):
t = time.time()
- self.cache.delete(key, **kwargs)
+ self.cache.delete(*args, **kwargs)
this_time = time.time() - t
self.total_time += this_time * 1000
self.deletes += 1
- self.calls.append((this_time, 'delete', (key,), self._get_func_info()))
+ self.calls.append((this_time, 'delete', args, kwargs, self._get_func_info()))
- def get_many(self, keys, **kwargs):
+ def get_many(self, *args, **kwargs):
t = time.time()
- results = self.cache.get_many(keys)
+ results = self.cache.get_many(*args, **kwargs)
this_time = time.time() - t
self.total_time += this_time * 1000
- self.get_many += 1
+ self.get_manys += 1
for key, value in results.iteritems():
if value is None:
self.misses += 1
else:
self.hits += 1
- self.calls.append((this_time, 'get_many', (keys,), self._get_func_info()))
+ self.calls.append((this_time, 'get_many', args, kwargs, self._get_func_info()))
+ return results
+
+ def make_key(self, *args, **kwargs):
+ return self.cache.make_key(*args, **kwargs)
+
+ def add(self, *args, **kwargs):
+ return self.cache.add(*args, **kwargs)
+
+ def has_key(self, *args, **kwargs):
+ return self.cache.has_key(*args, **kwargs)
+
+ def incr(self, *args, **kwargs):
+ return self.cache.incr(*args, **kwargs)
+
+ def decr(self, *args, **kwargs):
+ return self.cache.decr(*args, **kwargs)
+
+ def __contains__(self, key):
+ return self.cache.__contains__(key)
+
+ def set_many(self, *args, **kwargs):
+ self.cache.set_many(*args, **kwargs)
+
+ def delete_many(self, *args, **kwargs):
+ self.cache.delete_many(*args, **kwargs)
+
+ def clear(self):
+ self.cache.clear()
+
+ def validate_key(self, *args, **kwargs):
+ self.cache.validate_key(*args, **kwargs)
+
+ def incr_version(self, *args, **kwargs):
+ return self.cache.incr_version(*args, **kwargs)
+
+ def decr_version(self, *args, **kwargs):
+ return self.cache.decr_version(*args, **kwargs)
class CacheDebugPanel(DebugPanel):
@@ -80,16 +119,10 @@ class CacheDebugPanel(DebugPanel):
def __init__(self, *args, **kwargs):
super(CacheDebugPanel, self).__init__(*args, **kwargs)
- # This is hackish but to prevent threading issues is somewhat needed
- if isinstance(cache.cache, CacheStatTracker):
- cache.cache.reset()
- self.cache = cache.cache
- else:
- self.cache = CacheStatTracker(cache.cache)
- cache.cache = self.cache
+ cache.cache.reset()
def nav_title(self):
- return _('Cache')
+ return _('Cache: %.2fms') % cache.cache.total_time
def nav_subtitle(self):
cache_calls = len(self.cache.calls)
@@ -106,7 +139,9 @@ class CacheDebugPanel(DebugPanel):
def process_response(self, request, response):
self.record_stats({
- 'cache_calls': len(self.cache.calls),
- 'cache_time': self.cache.total_time,
- 'cache': self.cache,
+ 'cache_calls': len(cache.cache.calls),
+ 'cache_time': cache.cache.total_time,
+ 'cache': cache.cache,
})
+
+cache.cache = CacheStatTracker(cache.cache)
diff --git a/debug_toolbar/templates/debug_toolbar/panels/cache.html b/debug_toolbar/templates/debug_toolbar/panels/cache.html
index 5c5f13b..8576d3c 100644
--- a/debug_toolbar/templates/debug_toolbar/panels/cache.html
+++ b/debug_toolbar/templates/debug_toolbar/panels/cache.html
@@ -28,7 +28,7 @@
<th>deletes</th>
<td>{{ cache.deletes }}</td>
<th>get_many</th>
- <td>{{ cache.get_many }}</td>
+ <td>{{ cache.get_manys }}</td>
</tr>
</table>
{% if cache.calls %}
@@ -43,12 +43,12 @@
</tr>
</thead>
<tbody>
- {% for query in cache.calls %}
+ {% for call_time, call_type, call_args, call_kwargs, call_func in cache.calls %}
<tr class="{% cycle 'row1' 'row2' %}">
- <td>{{ query.0|floatformat:"4" }}</td>
- <td>{{ query.1|escape }}</td>
- <td>{{ query.2|escape }}</td>
- <td><acronym title="{{ query.3.0 }}:{{ query.3.1 }}">{{ query.3.2|escape }}</acronym>: {{ query.3.3.0|escape }}</td>
+ <td>{{ call_time|floatformat:"4" }}</td>
+ <td>{{ call_type|escape }}</td>
+ <td>{{ call_args|escape }}, {{ call_kwargs|escape }}</td>
+ <td><acronym title="{{ call_func.0 }}:{{ call_func.1 }}">{{ call_func.2|escape }}</acronym>: {{ call_func.3.0|escape }}</td>
</tr>
{% endfor %}
</tbody>
diff --git a/debug_toolbar/toolbar/loader.py b/debug_toolbar/toolbar/loader.py
index a69c314..b2b9b20 100644
--- a/debug_toolbar/toolbar/loader.py
+++ b/debug_toolbar/toolbar/loader.py
@@ -26,19 +26,7 @@ class DebugToolbar(object):
'BASE_URL': base_url, # for backwards compatibility
'DEBUG_TOOLBAR_MEDIA_URL': self.config.get('MEDIA_URL'),
}
- # Override this tuple by copying to settings.py as `DEBUG_TOOLBAR_PANELS`
- self.default_panels = (
- 'debug_toolbar.panels.version.VersionDebugPanel',
- 'debug_toolbar.panels.timer.TimerDebugPanel',
- 'debug_toolbar.panels.settings_vars.SettingsVarsDebugPanel',
- 'debug_toolbar.panels.headers.HeaderDebugPanel',
- 'debug_toolbar.panels.request_vars.RequestVarsDebugPanel',
- 'debug_toolbar.panels.sql.SQLDebugPanel',
- 'debug_toolbar.panels.template.TemplateDebugPanel',
- #'debug_toolbar.panels.cache.CacheDebugPanel',
- 'debug_toolbar.panels.signals.SignalDebugPanel',
- 'debug_toolbar.panels.logger.LoggingPanel',
- )
+
self.load_panels()
self.stats = {}
@@ -53,28 +41,8 @@ class DebugToolbar(object):
"""
Populate debug panels
"""
- from django.conf import settings
- from django.core import exceptions
-
- # Check if settings has a DEBUG_TOOLBAR_PANELS, otherwise use default
- if hasattr(settings, 'DEBUG_TOOLBAR_PANELS'):
- self.default_panels = settings.DEBUG_TOOLBAR_PANELS
-
- for panel_path in self.default_panels:
- try:
- dot = panel_path.rindex('.')
- except ValueError:
- raise exceptions.ImproperlyConfigured, '%s isn\'t a debug panel module' % panel_path
- panel_module, panel_classname = panel_path[:dot], panel_path[(dot + 1):]
- try:
- mod = __import__(panel_module, {}, {}, [''])
- except ImportError, e:
- raise exceptions.ImproperlyConfigured, 'Error importing debug panel %s: "%s"' % (panel_module, e)
- try:
- panel_class = getattr(mod, panel_classname)
- except AttributeError:
- raise exceptions.ImproperlyConfigured, 'Toolbar Panel module "%s" does not define a "%s" class' % (panel_module, panel_classname)
-
+ global panel_classes
+ for panel_class in panel_classes:
try:
panel_instance = panel_class(context=self.template_context)
except:
@@ -96,3 +64,44 @@ class DebugToolbar(object):
})
return render_to_string('debug_toolbar/base.html', context)
+
+
+panel_classes = []
+
+
+def load_panel_classes():
+ from django.conf import settings
+ from django.core import exceptions
+
+ # Override this tuple by copying to settings.py as `DEBUG_TOOLBAR_PANELS`
+ default_panels = (
+ 'debug_toolbar.panels.version.VersionDebugPanel',
+ 'debug_toolbar.panels.timer.TimerDebugPanel',
+ 'debug_toolbar.panels.settings_vars.SettingsVarsDebugPanel',
+ 'debug_toolbar.panels.headers.HeaderDebugPanel',
+ 'debug_toolbar.panels.request_vars.RequestVarsDebugPanel',
+ 'debug_toolbar.panels.sql.SQLDebugPanel',
+ 'debug_toolbar.panels.template.TemplateDebugPanel',
+ #'debug_toolbar.panels.cache.CacheDebugPanel',
+ 'debug_toolbar.panels.signals.SignalDebugPanel',
+ 'debug_toolbar.panels.logger.LoggingPanel',
+ )
+ # Check if settings has a DEBUG_TOOLBAR_PANELS, otherwise use default
+ if hasattr(settings, 'DEBUG_TOOLBAR_PANELS'):
+ default_panels = settings.DEBUG_TOOLBAR_PANELS
+
+ for panel_path in default_panels:
+ try:
+ dot = panel_path.rindex('.')
+ except ValueError:
+ raise exceptions.ImproperlyConfigured, '%s isn\'t a debug panel module' % panel_path
+ panel_module, panel_classname = panel_path[:dot], panel_path[dot + 1:]
+ try:
+ mod = __import__(panel_module, {}, {}, [''])
+ except ImportError, e:
+ raise exceptions.ImproperlyConfigured, 'Error importing debug panel %s: "%s"' % (panel_module, e)
+ try:
+ panel_class = getattr(mod, panel_classname)
+ except AttributeError:
+ raise exceptions.ImproperlyConfigured, 'Toolbar Panel module "%s" does not define a "%s" class' % (panel_module, panel_classname)
+ panel_classes.append(panel_class)