From a08238af1ec07e077a0ee0f816d82c62c3f0ac63 Mon Sep 17 00:00:00 2001 From: Yann Malet Date: Sat, 10 Sep 2011 01:24:32 +0200 Subject: Revert some of the previous changes and modify slightly the panels to separate the gneration of the stats and the generation of the content. --- debug_toolbar/panels/cache.py | 1 + debug_toolbar/panels/profiling.py | 47 ++++++++++++++++++++------------------- debug_toolbar/panels/sql.py | 1 + 3 files changed, 26 insertions(+), 23 deletions(-) (limited to 'debug_toolbar') diff --git a/debug_toolbar/panels/cache.py b/debug_toolbar/panels/cache.py index c03971d..4cc783e 100644 --- a/debug_toolbar/panels/cache.py +++ b/debug_toolbar/panels/cache.py @@ -102,6 +102,7 @@ class CacheDebugPanel(DebugPanel): 'cache': self.cache, } request.debug_toolbar.stats['cache'] = self.stats + return response def content(self): context = self.context.copy() diff --git a/debug_toolbar/panels/profiling.py b/debug_toolbar/panels/profiling.py index 289e1f7..623b27a 100644 --- a/debug_toolbar/panels/profiling.py +++ b/debug_toolbar/panels/profiling.py @@ -8,9 +8,9 @@ from debug_toolbar.panels import DebugPanel try: from line_profiler import LineProfiler, show_func DJ_PROFILE_USE_LINE_PROFILER = True -except ImportError: +except ImportError: DJ_PROFILE_USE_LINE_PROFILER = False - + from cStringIO import StringIO import cProfile @@ -20,7 +20,7 @@ import os class DjangoDebugToolbarStats(Stats): __root = None - + def get_root_func(self): if self.__root is None: for func, (cc, nc, tt, ct, callers) in self.stats.iteritems(): @@ -28,7 +28,7 @@ class DjangoDebugToolbarStats(Stats): self.__root = func break return self.__root - + class FunctionCall(object): def __init__(self, statobj, func, depth=0, stats=None, id=0, parent_ids=[], hsv=(0,0.5,1)): self.statobj = statobj @@ -42,14 +42,14 @@ class FunctionCall(object): self.parent_ids = parent_ids self.hsv = hsv self._line_stats_text = None - + def parent_classes(self): return self.parent_classes - + def background(self): r,g,b = hsv_to_rgb(*self.hsv) return 'rgb(%f%%,%f%%,%f%%)' %(r*100, g*100, b*100) - + def func_std_string(self): # match what old profile produced func_name = self.func if func_name[:2] == ('~', 0): @@ -64,16 +64,16 @@ class FunctionCall(object): idx = file_name.find('/site-packages/') if idx > -1: file_name=file_name[idx+14:] - + file_path, file_name = file_name.rsplit(os.sep, 1) - + return mark_safe('{0}/{1} in {3}({2})'.format( file_path, file_name, line_num, method, )) - + def subfuncs(self): i=0 h,s,v = self.hsv @@ -86,23 +86,23 @@ class FunctionCall(object): else: s1 = s*(stats[3]/self.stats[3]) yield FunctionCall(self.statobj, - func, - self.depth+1, + func, + self.depth+1, stats=stats, id=str(self.id) + '_' + str(i), parent_ids=self.parent_ids + [self.id], hsv=(h1,s1,1)) - + def count(self): return self.stats[1] - + def tottime(self): return self.stats[2] - + def cumtime(self): cc, nc, tt, ct = self.stats return self.stats[3] - + def tottime_per_call(self): cc, nc, tt, ct = self.stats @@ -110,7 +110,7 @@ class FunctionCall(object): return 0 return tt/nc - + def cumtime_per_call(self): cc, nc, tt, ct = self.stats @@ -121,7 +121,7 @@ class FunctionCall(object): def indent(self): return 16 * self.depth - + def line_stats_text(self): if self._line_stats_text is None: lstats = self.statobj.line_stats @@ -146,7 +146,7 @@ class ProfilingDebugPanel(DebugPanel): def url(self): return '' - + def title(self): return _('Profiling') @@ -179,6 +179,8 @@ class ProfilingDebugPanel(DebugPanel): self.stats = DjangoDebugToolbarStats(self.profiler) if DJ_PROFILE_USE_LINE_PROFILER: self.stats.line_stats = self.line_profiler.get_stats() + self.stats.calc_callees() + request.debug_toolbar.stats['profiling'] = self.stats return response def add_node(self, func_list, func, max_depth, cum_time=0.1): @@ -189,12 +191,11 @@ class ProfilingDebugPanel(DebugPanel): if subfunc.stats[3] >= cum_time or (subfunc.func in self.stats.line_stats.timings): func.has_subfuncs = True self.add_node(func_list, subfunc, max_depth, cum_time=cum_time) - + def content(self): - - self.stats.calc_callees() + import ipdb; ipdb.set_trace() root = FunctionCall(self.stats, self.stats.get_root_func(), depth=0) - + func_list = [] self.add_node(func_list, root, 10, root.stats[3]/8) context = self.context.copy() diff --git a/debug_toolbar/panels/sql.py b/debug_toolbar/panels/sql.py index 2eced7c..bfe52d9 100644 --- a/debug_toolbar/panels/sql.py +++ b/debug_toolbar/panels/sql.py @@ -211,6 +211,7 @@ class SQLDebugPanel(DebugPanel): 'sql_time': self._sql_time, } request.debug_toolbar.stats['sql'] = getattr(self, 'stats', None) + return response def content(self): context = self.context.copy() -- cgit v1.2.3