20
20
21
21
class DjangoDebugToolbarStats (Stats ):
22
22
__root = None
23
-
23
+
24
24
def get_root_func (self ):
25
25
if self .__root is None :
26
26
for func , (cc , nc , tt , ct , callers ) in self .stats .iteritems ():
@@ -44,14 +44,14 @@ def __init__(self, statobj, func, depth=0, stats=None,
44
44
self .parent_ids = parent_ids
45
45
self .hsv = hsv
46
46
self ._line_stats_text = None
47
-
47
+
48
48
def parent_classes (self ):
49
49
return self .parent_classes
50
-
50
+
51
51
def background (self ):
52
52
r ,g ,b = hsv_to_rgb (* self .hsv )
53
53
return 'rgb(%f%%,%f%%,%f%%)' % (r * 100 , g * 100 , b * 100 )
54
-
54
+
55
55
def func_std_string (self ): # match what old profile produced
56
56
func_name = self .func
57
57
if func_name [:2 ] == ('~' , 0 ):
@@ -66,16 +66,16 @@ def func_std_string(self): # match what old profile produced
66
66
idx = file_name .find ('/site-packages/' )
67
67
if idx > - 1 :
68
68
file_name = file_name [idx + 14 :]
69
-
69
+
70
70
file_path , file_name = file_name .rsplit (os .sep , 1 )
71
-
71
+
72
72
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 (
73
73
file_path ,
74
74
file_name ,
75
75
line_num ,
76
76
method ,
77
77
))
78
-
78
+
79
79
def subfuncs (self ):
80
80
i = 0
81
81
h , s , v = self .hsv
@@ -94,36 +94,36 @@ def subfuncs(self):
94
94
id = str (self .id ) + '_' + str (i ),
95
95
parent_ids = self .parent_ids + [self .id ],
96
96
hsv = (h1 ,s1 ,1 ))
97
-
97
+
98
98
def count (self ):
99
99
return self .stats [1 ]
100
-
100
+
101
101
def tottime (self ):
102
102
return self .stats [2 ]
103
-
103
+
104
104
def cumtime (self ):
105
105
cc , nc , tt , ct = self .stats
106
106
return self .stats [3 ]
107
-
107
+
108
108
def tottime_per_call (self ):
109
109
cc , nc , tt , ct = self .stats
110
-
110
+
111
111
if nc == 0 :
112
112
return 0
113
-
113
+
114
114
return tt / nc
115
-
115
+
116
116
def cumtime_per_call (self ):
117
117
cc , nc , tt , ct = self .stats
118
-
118
+
119
119
if cc == 0 :
120
120
return 0
121
-
121
+
122
122
return ct / cc
123
-
123
+
124
124
def indent (self ):
125
125
return 16 * self .depth
126
-
126
+
127
127
def line_stats_text (self ):
128
128
if self ._line_stats_text is None and DJ_PROFILE_USE_LINE_PROFILER :
129
129
lstats = self .statobj .line_stats
@@ -143,16 +143,16 @@ class ProfilingDebugPanel(DebugPanel):
143
143
name = 'Profiling'
144
144
template = 'debug_toolbar/panels/profiling.html'
145
145
has_content = True
146
-
146
+
147
147
def nav_title (self ):
148
148
return _ ('Profiling' )
149
-
149
+
150
150
def url (self ):
151
151
return ''
152
-
152
+
153
153
def title (self ):
154
154
return _ ('Profiling' )
155
-
155
+
156
156
def _unwrap_closure_and_profile (self , func ):
157
157
if not hasattr (func , 'func_code' ):
158
158
return
@@ -161,9 +161,9 @@ def _unwrap_closure_and_profile(self, func):
161
161
for cell in func .func_closure :
162
162
if hasattr (cell .cell_contents , 'func_code' ):
163
163
self ._unwrap_closure_and_profile (cell .cell_contents )
164
-
164
+
165
165
def process_view (self , request , view_func , view_args , view_kwargs ):
166
- __traceback_hide__ = True
166
+ print "process_view" , view_func
167
167
self .profiler = cProfile .Profile ()
168
168
args = (request ,) + view_args
169
169
if DJ_PROFILE_USE_LINE_PROFILER :
@@ -176,7 +176,7 @@ def process_view(self, request, view_func, view_args, view_kwargs):
176
176
self .line_profiler = None
177
177
out = self .profiler .runcall (view_func , * args , ** view_kwargs )
178
178
return out
179
-
179
+
180
180
def add_node (self , func_list , func , max_depth , cum_time = 0.1 ):
181
181
func_list .append (func )
182
182
func .has_subfuncs = False
@@ -187,17 +187,17 @@ def add_node(self, func_list, func, max_depth, cum_time=0.1):
187
187
(subfunc .func in self .stats .line_stats .timings ))):
188
188
func .has_subfuncs = True
189
189
self .add_node (func_list , subfunc , max_depth , cum_time = cum_time )
190
-
190
+
191
191
def process_response (self , request , response ):
192
192
self .profiler .create_stats ()
193
193
self .stats = DjangoDebugToolbarStats (self .profiler )
194
194
if DJ_PROFILE_USE_LINE_PROFILER :
195
195
self .stats .line_stats = self .line_profiler .get_stats ()
196
196
self .stats .calc_callees ()
197
-
197
+
198
198
root = FunctionCall (self .stats , self .stats .get_root_func (), depth = 0 )
199
-
199
+
200
200
func_list = []
201
201
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 })
0 commit comments