Skip to content

Update to current djdt #17

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
14 changes: 9 additions & 5 deletions debug_toolbar_line_profiler/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from django.utils.six.moves import cStringIO
from debug_toolbar.panels import Panel
from django.views.generic.base import View
from django.urls import resolve

from line_profiler import LineProfiler, show_func

Expand Down Expand Up @@ -185,19 +186,22 @@ def _unwrap_closure_and_profile(self, func):
if name[0] != '_' and inspect.ismethod(value):
self._unwrap_closure_and_profile(value)

def process_view(self, request, view_func, view_args, view_kwargs):

def process_request(self, request):
match = resolve(request.path)
view_func, view_args, view_kwargs = match
self.view_func = view_func

self.profiler = cProfile.Profile()
args = (request,) + view_args
self.line_profiler = LineProfiler()
self._unwrap_closure_and_profile(view_func)
self._unwrap_closure_and_profile(self.view_func)
signals.profiler_setup.send(sender=self,
profiler=self.line_profiler,
view_func=view_func,
view_args=view_args,
view_kwargs=view_kwargs)
self.line_profiler.enable_by_count()
out = self.profiler.runcall(view_func, *args, **view_kwargs)
out = self.profiler.runcall(super().process_request, request)
self.line_profiler.disable_by_count()
return out

Expand Down Expand Up @@ -238,7 +242,7 @@ def add_node(self, func_list, func, max_depth, cum_time=0.1):
max_depth=max_depth,
cum_time=subfunc.cumtime()/16)

def process_response(self, request, response):
def generate_stats(self, request, response):
if not hasattr(self, 'profiler'):
return None
# Could be delayed until the panel content is requested (perf. optim.)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='django-debug-toolbar-line-profiler',
version='0.6.1',
version='0.7.0',
description='A panel for django-debug-toolbar that integrates ' +
'information from line_profiler',
long_description=open('README.rst').read(),
Expand Down