Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using ProfilingPanel as non last panel #1299

Merged
merged 1 commit into from
Oct 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 4 additions & 31 deletions debug_toolbar/panels/profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,6 @@
from debug_toolbar import settings as dt_settings
from debug_toolbar.panels import Panel

# Occasionally the disable method on the profiler is listed before
# the actual view functions. This function call should be ignored as
# it leads to an error within the tests.
INVALID_PROFILER_FUNC = "_lsprof.Profiler"


def contains_profiler(func_tuple):
"""Helper function that checks to see if the tuple contains
the INVALID_PROFILE_FUNC in any string value of the tuple."""
has_profiler = False
for value in func_tuple:
if isinstance(value, str):
has_profiler |= INVALID_PROFILER_FUNC in value
return has_profiler


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.items():
if len(callers) == 0 and not contains_profiler(func):
self.__root = func
break
return self.__root


class FunctionCall:
def __init__(
Expand Down Expand Up @@ -169,12 +142,12 @@ def generate_stats(self, request, response):
return None
# Could be delayed until the panel content is requested (perf. optim.)
self.profiler.create_stats()
self.stats = DjangoDebugToolbarStats(self.profiler)
self.stats = Stats(self.profiler)
self.stats.calc_callees()

root_func = self.stats.get_root_func()
# Ensure root function exists before continuing with function call analysis
if root_func:
root_func = cProfile.label(super().process_request.__code__)

if root_func in self.stats.stats:
root = FunctionCall(self.stats, root_func, depth=0)
func_list = []
self.add_node(
Expand Down