-
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() | ||
|
||
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.