Skip to content

Commit 0e262ae

Browse files
committed
Fixed ProfilingDebugPanel; fixed example site if installed other debug_toolbar in system
1 parent c914736 commit 0e262ae

File tree

4 files changed

+36
-34
lines changed

4 files changed

+36
-34
lines changed

debug_toolbar/panels/profiling.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
class DjangoDebugToolbarStats(Stats):
2222
__root = None
23-
23+
2424
def get_root_func(self):
2525
if self.__root is None:
2626
for func, (cc, nc, tt, ct, callers) in self.stats.iteritems():
@@ -44,14 +44,14 @@ def __init__(self, statobj, func, depth=0, stats=None,
4444
self.parent_ids = parent_ids
4545
self.hsv = hsv
4646
self._line_stats_text = None
47-
47+
4848
def parent_classes(self):
4949
return self.parent_classes
50-
50+
5151
def background(self):
5252
r,g,b = hsv_to_rgb(*self.hsv)
5353
return 'rgb(%f%%,%f%%,%f%%)' %(r*100, g*100, b*100)
54-
54+
5555
def func_std_string(self): # match what old profile produced
5656
func_name = self.func
5757
if func_name[:2] == ('~', 0):
@@ -66,16 +66,16 @@ def func_std_string(self): # match what old profile produced
6666
idx = file_name.find('/site-packages/')
6767
if idx > -1:
6868
file_name = file_name[idx+14:]
69-
69+
7070
file_path, file_name = file_name.rsplit(os.sep, 1)
71-
71+
7272
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(
7373
file_path,
7474
file_name,
7575
line_num,
7676
method,
7777
))
78-
78+
7979
def subfuncs(self):
8080
i=0
8181
h, s, v = self.hsv
@@ -94,36 +94,36 @@ def subfuncs(self):
9494
id=str(self.id) + '_' + str(i),
9595
parent_ids=self.parent_ids + [self.id],
9696
hsv=(h1,s1,1))
97-
97+
9898
def count(self):
9999
return self.stats[1]
100-
100+
101101
def tottime(self):
102102
return self.stats[2]
103-
103+
104104
def cumtime(self):
105105
cc, nc, tt, ct = self.stats
106106
return self.stats[3]
107-
107+
108108
def tottime_per_call(self):
109109
cc, nc, tt, ct = self.stats
110-
110+
111111
if nc == 0:
112112
return 0
113-
113+
114114
return tt/nc
115-
115+
116116
def cumtime_per_call(self):
117117
cc, nc, tt, ct = self.stats
118-
118+
119119
if cc == 0:
120120
return 0
121-
121+
122122
return ct/cc
123-
123+
124124
def indent(self):
125125
return 16 * self.depth
126-
126+
127127
def line_stats_text(self):
128128
if self._line_stats_text is None and DJ_PROFILE_USE_LINE_PROFILER:
129129
lstats = self.statobj.line_stats
@@ -143,16 +143,16 @@ class ProfilingDebugPanel(DebugPanel):
143143
name = 'Profiling'
144144
template = 'debug_toolbar/panels/profiling.html'
145145
has_content = True
146-
146+
147147
def nav_title(self):
148148
return _('Profiling')
149-
149+
150150
def url(self):
151151
return ''
152-
152+
153153
def title(self):
154154
return _('Profiling')
155-
155+
156156
def _unwrap_closure_and_profile(self, func):
157157
if not hasattr(func, 'func_code'):
158158
return
@@ -161,9 +161,9 @@ def _unwrap_closure_and_profile(self, func):
161161
for cell in func.func_closure:
162162
if hasattr(cell.cell_contents, 'func_code'):
163163
self._unwrap_closure_and_profile(cell.cell_contents)
164-
164+
165165
def process_view(self, request, view_func, view_args, view_kwargs):
166-
__traceback_hide__ = True
166+
print "process_view", view_func
167167
self.profiler = cProfile.Profile()
168168
args = (request,) + view_args
169169
if DJ_PROFILE_USE_LINE_PROFILER:
@@ -176,7 +176,7 @@ def process_view(self, request, view_func, view_args, view_kwargs):
176176
self.line_profiler = None
177177
out = self.profiler.runcall(view_func, *args, **view_kwargs)
178178
return out
179-
179+
180180
def add_node(self, func_list, func, max_depth, cum_time=0.1):
181181
func_list.append(func)
182182
func.has_subfuncs = False
@@ -187,17 +187,17 @@ def add_node(self, func_list, func, max_depth, cum_time=0.1):
187187
(subfunc.func in self.stats.line_stats.timings))):
188188
func.has_subfuncs = True
189189
self.add_node(func_list, subfunc, max_depth, cum_time=cum_time)
190-
190+
191191
def process_response(self, request, response):
192192
self.profiler.create_stats()
193193
self.stats = DjangoDebugToolbarStats(self.profiler)
194194
if DJ_PROFILE_USE_LINE_PROFILER:
195195
self.stats.line_stats = self.line_profiler.get_stats()
196196
self.stats.calc_callees()
197-
197+
198198
root = FunctionCall(self.stats, self.stats.get_root_func(), depth=0)
199-
199+
200200
func_list = []
201201
self.add_node(func_list, root, 10, root.stats[3]/8)
202-
203-
self.stats_record({'func_list': func_list})
202+
203+
self.record_stats({'func_list': func_list})

debug_toolbar/utils/tracking/db.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import inspect
21
import sys
32

43
from datetime import datetime
@@ -7,7 +6,7 @@
76
from django.conf import settings
87
from django.template import Node
98
from django.utils import simplejson
10-
from django.utils.encoding import force_unicode
9+
from django.utils.encoding import force_unicode, smart_str
1110
from django.utils.hashcompat import sha_constructor
1211

1312
from debug_toolbar.utils import ms_from_timedelta, tidy_stacktrace, get_template_info, \
@@ -113,7 +112,7 @@ def execute(self, sql, params=()):
113112
'duration': duration,
114113
'raw_sql': sql,
115114
'params': _params,
116-
'hash': sha_constructor(settings.SECRET_KEY + sql + _params).hexdigest(),
115+
'hash': sha_constructor(settings.SECRET_KEY + smart_str(sql) + _params).hexdigest(),
117116
'stacktrace': stacktrace,
118117
'start_time': start,
119118
'stop_time': stop,

example/example.db

0 Bytes
Binary file not shown.

example/settings.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
PROJECT_PATH = os.path.realpath(os.path.dirname(__file__))
3+
os.sys.path.insert(0, os.path.dirname(PROJECT_PATH))
34

45
ADMIN_MEDIA_PREFIX = '/admin_media/'
56
DATABASE_ENGINE = 'sqlite3'
@@ -31,7 +32,9 @@
3132
'django.core.context_processors.request',
3233
)
3334
TEMPLATE_DEBUG = DEBUG
34-
TEMPLATE_DIRS = (os.path.join(PROJECT_PATH, 'templates'))
35+
TEMPLATE_DIRS = (
36+
os.path.join(PROJECT_PATH, 'templates'),
37+
)
3538
DEBUG_TOOLBAR_PANELS = (
3639
'debug_toolbar.panels.version.VersionDebugPanel',
3740
'debug_toolbar.panels.timer.TimerDebugPanel',

0 commit comments

Comments
 (0)