-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Track and display middleware time in the toolbar #2049
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
68ca369
0c94a14
6714742
ebb7571
e029174
cb45e18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import re | ||
import socket | ||
from functools import cache | ||
from time import perf_counter | ||
|
||
from asgiref.sync import iscoroutinefunction, markcoroutinefunction | ||
from django.conf import settings | ||
|
@@ -78,6 +79,8 @@ def __init__(self, get_response): | |
markcoroutinefunction(self) | ||
|
||
def __call__(self, request): | ||
# Start tracking middleware execution time | ||
toolbar_start_time = perf_counter() | ||
# Decide whether the toolbar is active for this request. | ||
if self.async_mode: | ||
return self.__acall__(request) | ||
|
@@ -98,10 +101,14 @@ def __call__(self, request): | |
# regardless of the response. Keep 'return' clauses below. | ||
for panel in reversed(toolbar.enabled_panels): | ||
panel.disable_instrumentation() | ||
toolbar_end_time = perf_counter() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The other thing I was thinking about is how to handle measuring the full time of the toolbar's processing. This is actually stopping before all the The problem is, how do we capture that? I have a few ideas, but I'm not happy with them. I think we could measure the end time in The other idea I had was to create a templatetag that would do the diff between the stored time and the current time at the time the toolbar is rendered. The problem here is that it wouldn't be compatible with the serializable branch where we want to store all the stats before rendering. So I think trying to consolidate all the logic into @salty-ivy @elineda any thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have updated the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Excellent, thank you @earthcomfy! This is looking really nice. The last bit we need are the tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a test to ensure the timer panel is first. Are there any other tests that need to be included There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @earthcomfy ideally we'd have tests covering all the changes on the Timer panel. Or updates to similar tests to also cover these new fields. |
||
toolbar.toolbar_time = (toolbar_end_time - toolbar_start_time) * 1000 | ||
|
||
return self._postprocess(request, response, toolbar) | ||
|
||
async def __acall__(self, request): | ||
# Start tracking middleware execution time | ||
toolbar_start_time = perf_counter() | ||
# Decide whether the toolbar is active for this request. | ||
show_toolbar = get_show_toolbar() | ||
if not show_toolbar(request) or DebugToolbar.is_toolbar_request(request): | ||
|
@@ -125,6 +132,8 @@ async def __acall__(self, request): | |
# regardless of the response. Keep 'return' clauses below. | ||
for panel in reversed(toolbar.enabled_panels): | ||
panel.disable_instrumentation() | ||
toolbar_end_time = perf_counter() | ||
toolbar.middleware_time = (toolbar_end_time - toolbar_start_time) * 1000 | ||
|
||
return self._postprocess(request, response, toolbar) | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.