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

Add option to dump profiler stats #204

Merged
merged 2 commits into from
Dec 13, 2023
Merged
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
2 changes: 2 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ Name Description De
``DEBUG_TB_PANELS`` List of module/class names of panels enable all built-in panels
``DEBUG_TB_PROFILER_ENABLED`` Enable the profiler on all requests ``False``, user-enabled
``DEBUG_TB_TEMPLATE_EDITOR_ENABLED`` Enable the template editor ``False``
``DEBUG_TB_PROFILER_DUMP_FILENAME`` Filename of the profiler stats dump, ``None``, no dump will be written
can be a ``str`` or a ``callable``
==================================== ===================================== ==========================

To change one of the config options, set it in the Flask app's config like::
Expand Down
13 changes: 12 additions & 1 deletion src/flask_debugtoolbar/panels/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ProfilerDebugPanel(DebugPanel):
"""
Panel that displays the time a response took with cProfile output.
"""

name = 'Profiler'

user_activate = True
Expand All @@ -22,6 +23,9 @@ def __init__(self, jinja_env, context={}):
DebugPanel.__init__(self, jinja_env, context=context)
if current_app.config.get('DEBUG_TB_PROFILER_ENABLED'):
self.is_active = True
self.dump_filename = current_app.config.get(
"DEBUG_TB_PROFILER_DUMP_FILENAME"
)

def has_content(self):
return bool(self.profiler)
Expand Down Expand Up @@ -88,7 +92,14 @@ def process_response(self, request, response):

self.stats = stats
self.function_calls = function_calls
# destroy the profiler just in case
Copy link
Member

@jeffwidman jeffwidman Nov 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this comment seems semi-interesting, although I don't see an explicit del call here. Does it somehow just fall out of scope?

Just wondering if this is a contextual comment we should continue pulling forward in the codebase or if it's outdated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it's outdated but if you think otherwise I can restore it.


if self.dump_filename:
if callable(self.dump_filename):
filename = self.dump_filename()
else:
filename = self.dump_filename
self.profiler.dump_stats(filename)

return response

def title(self):
Expand Down