Skip to content

Commit c0c35d7

Browse files
committed
Allowed using ProfilingPanel as non last panel.
1 parent 3e626df commit c0c35d7

File tree

1 file changed

+4
-31
lines changed

1 file changed

+4
-31
lines changed

debug_toolbar/panels/profiling.py

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,6 @@
99
from debug_toolbar import settings as dt_settings
1010
from debug_toolbar.panels import Panel
1111

12-
# Occasionally the disable method on the profiler is listed before
13-
# the actual view functions. This function call should be ignored as
14-
# it leads to an error within the tests.
15-
INVALID_PROFILER_FUNC = "_lsprof.Profiler"
16-
17-
18-
def contains_profiler(func_tuple):
19-
"""Helper function that checks to see if the tuple contains
20-
the INVALID_PROFILE_FUNC in any string value of the tuple."""
21-
has_profiler = False
22-
for value in func_tuple:
23-
if isinstance(value, str):
24-
has_profiler |= INVALID_PROFILER_FUNC in value
25-
return has_profiler
26-
27-
28-
class DjangoDebugToolbarStats(Stats):
29-
__root = None
30-
31-
def get_root_func(self):
32-
if self.__root is None:
33-
for func, (cc, nc, tt, ct, callers) in self.stats.items():
34-
if len(callers) == 0 and not contains_profiler(func):
35-
self.__root = func
36-
break
37-
return self.__root
38-
3912

4013
class FunctionCall:
4114
def __init__(
@@ -169,12 +142,12 @@ def generate_stats(self, request, response):
169142
return None
170143
# Could be delayed until the panel content is requested (perf. optim.)
171144
self.profiler.create_stats()
172-
self.stats = DjangoDebugToolbarStats(self.profiler)
145+
self.stats = Stats(self.profiler)
173146
self.stats.calc_callees()
174147

175-
root_func = self.stats.get_root_func()
176-
# Ensure root function exists before continuing with function call analysis
177-
if root_func:
148+
root_func = cProfile.label(super().process_request.__code__)
149+
150+
if root_func in self.stats.stats:
178151
root = FunctionCall(self.stats, root_func, depth=0)
179152
func_list = []
180153
self.add_node(

0 commit comments

Comments
 (0)