From f92aba225936fa768c098a8f1db51125ac1715ec Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sun, 10 Nov 2013 10:10:28 +0100 Subject: Disable instrumentation for disabled panels. This eliminates the performance overhead when a panel is disabled. --- debug_toolbar/panels/__init__.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'debug_toolbar/panels/__init__.py') diff --git a/debug_toolbar/panels/__init__.py b/debug_toolbar/panels/__init__.py index d4a61da..9586e80 100644 --- a/debug_toolbar/panels/__init__.py +++ b/debug_toolbar/panels/__init__.py @@ -22,31 +22,44 @@ class DebugPanel(object): context = {} # Panel methods + def __init__(self, toolbar, context={}): self.toolbar = toolbar self.context.update(context) self.slug = slugify(self.name) + def content(self): + if self.has_content: + context = self.context.copy() + context.update(self.get_stats()) + return render_to_string(self.template, context) + def dom_id(self): return 'djDebug%sPanel' % (self.name.replace(' ', '')) + # Titles and subtitles + def nav_title(self): - """Title showing in toolbar""" + """Title showing in sidebar""" raise NotImplementedError def nav_subtitle(self): - """Subtitle showing until title in toolbar""" + """Subtitle showing under title in sidebar""" return '' def title(self): """Title showing in panel""" raise NotImplementedError - def content(self): - if self.has_content: - context = self.context.copy() - context.update(self.get_stats()) - return render_to_string(self.template, context) + # Enable and disable (expensive) instrumentation + + def enable_instrumentation(self): + pass + + def disable_instrumentation(self): + pass + + # Store and retrieve stats (shared between panels) def record_stats(self, stats): panel_stats = self.toolbar.stats.get(self.slug) -- cgit v1.2.3