aboutsummaryrefslogtreecommitdiffstats
path: root/debug_toolbar/panels/profiling.py
diff options
context:
space:
mode:
Diffstat (limited to 'debug_toolbar/panels/profiling.py')
-rw-r--r--debug_toolbar/panels/profiling.py64
1 files changed, 32 insertions, 32 deletions
diff --git a/debug_toolbar/panels/profiling.py b/debug_toolbar/panels/profiling.py
index 01ae1e0..26f7888 100644
--- a/debug_toolbar/panels/profiling.py
+++ b/debug_toolbar/panels/profiling.py
@@ -21,7 +21,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():
@@ -45,15 +45,15 @@ 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
+
+ def func_std_string(self): # match what old profile produced
func_name = self.func
if func_name[:2] == ('~', 0):
# special case for built-in functions
@@ -67,16 +67,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('<span class="path">{0}/</span><span class="file">{1}</span> in <span class="func">{3}</span>(<span class="lineno">{2}</span>)'.format(
file_path,
file_name,
line_num,
method,
))
-
+
def subfuncs(self):
i=0
h, s, v = self.hsv
@@ -95,39 +95,38 @@ class FunctionCall(object):
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
-
+
if nc == 0:
return 0
-
+
return tt/nc
-
+
def cumtime_per_call(self):
cc, nc, tt, ct = self.stats
-
+
if cc == 0:
return 0
-
+
return ct/cc
-
+
def indent(self):
return 16 * self.depth
-
+
def line_stats_text(self):
- if (self._line_stats_text is None and
- DJ_PROFILE_USE_LINE_PROFILER):
+ if self._line_stats_text is None and DJ_PROFILE_USE_LINE_PROFILER:
lstats = self.statobj.line_stats
if self.func in lstats.timings:
out = StringIO()
@@ -144,16 +143,16 @@ class ProfilingDebugPanel(DebugPanel):
"""
name = 'Profiling'
has_content = True
-
+
def nav_title(self):
return _('Profiling')
-
+
def url(self):
return ''
-
+
def title(self):
return _('Profiling')
-
+
def _unwrap_closure_and_profile(self, func):
if not hasattr(func, 'func_code'):
return
@@ -162,7 +161,7 @@ class ProfilingDebugPanel(DebugPanel):
for cell in func.func_closure:
if hasattr(cell.cell_contents, 'func_code'):
self._unwrap_closure_and_profile(cell.cell_contents)
-
+
def process_view(self, request, view_func, view_args, view_kwargs):
__traceback_hide__ = True
self.profiler = cProfile.Profile()
@@ -177,16 +176,17 @@ class ProfilingDebugPanel(DebugPanel):
self.line_profiler = None
out = self.profiler.runcall(view_func, *args, **view_kwargs)
return out
-
+
def process_response(self, request, response):
self.profiler.create_stats()
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
+ toolbar = DebugToolbarMiddleware.get_current()
+ toolbar.stats['profiling'] = self.stats
return response
-
+
def add_node(self, func_list, func, max_depth, cum_time=0.1):
func_list.append(func)
func.has_subfuncs = False
@@ -197,15 +197,15 @@ class ProfilingDebugPanel(DebugPanel):
(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):
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()
context.update({
'func_list': func_list,
})
-
+
return render_to_string('debug_toolbar/panels/profiling.html', context)