Repository: jazzband/django-debug-toolbar

Issue:
ProfilingPanel info not collected
In my usage the ProfilingPanel info is not being collected/processed, despite being enabled.

I have run in debug mode and the piece that looks most suspicious (in `generate_stats`) is that:
```
root_func = self.stats.get_root_func()
```
is returning a falsey `root_func`.

python3.6, django 2.2.6, and django debug toolbar 2.0


Discussion:
Do you have anything installed that might be impacting `pstats.Stats`?
I'll check, but can you provide more information about what to look for?
Any other debugging packages installed or any debugging monkey patching that you've done. Perhaps try seeing if you can spin up a new project (or use DDT's example project after pulling it) to see if you can use the ProfilingPanel there.
For the former, we did (in some cases) have `request_profiler` in the stack. But I've removed it for the test. Still not working.

Not sure about any monkey patching going on.
Are you able to use the [`pstats.Stats`](https://docs.python.org/3/library/profile.html#the-stats-class) class?
Good news is that the example does work.
@tim-schilling where might I try using that stats class? python shell or somewhere else? Do you have a snippet I could run?
Run the shell with your django application so the stack should be similar. Though obviously it won't eliminate everything from your stack because running the application is still different than the shell.

This script from the docs should generate a stats class internally.

```
import cProfile
with cProfile.Profile() as pr:
    # ... do something ...
pr.print_stats()
```
I was able to run that (using .`enable` and `disable` because the context manager didn't work).
Sorry, I don't have an answer for you. I can't reproduce this problem.

Resolving patch:
diff --git a/debug_toolbar/panels/profiling.py b/debug_toolbar/panels/profiling.py
--- a/debug_toolbar/panels/profiling.py
+++ b/debug_toolbar/panels/profiling.py
@@ -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__(
@@ -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(


Test patch: