|
9 | 9 | from debug_toolbar import settings as dt_settings
|
10 | 10 | from debug_toolbar.panels import Panel
|
11 | 11 |
|
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 |
| - |
39 | 12 |
|
40 | 13 | class FunctionCall:
|
41 | 14 | def __init__(
|
@@ -169,12 +142,12 @@ def generate_stats(self, request, response):
|
169 | 142 | return None
|
170 | 143 | # Could be delayed until the panel content is requested (perf. optim.)
|
171 | 144 | self.profiler.create_stats()
|
172 |
| - self.stats = DjangoDebugToolbarStats(self.profiler) |
| 145 | + self.stats = Stats(self.profiler) |
173 | 146 | self.stats.calc_callees()
|
174 | 147 |
|
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: |
178 | 151 | root = FunctionCall(self.stats, root_func, depth=0)
|
179 | 152 | func_list = []
|
180 | 153 | self.add_node(
|
|
0 commit comments