-
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 all commits
68ca369
0c94a14
6714742
ebb7571
e029174
cb45e18
6715a21
df7fc44
4dc084d
216cc13
93b6fbc
f427108
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 |
|---|---|---|
|
|
@@ -47,6 +47,10 @@ def content(self): | |
| (_("System CPU time"), _("%(stime)0.3f ms") % stats), | ||
| (_("Total CPU time"), _("%(total)0.3f ms") % stats), | ||
| (_("Elapsed time"), _("%(total_time)0.3f ms") % stats), | ||
| ( | ||
| _("DebugToolbar time"), | ||
| _("%(toolbar_time)0.3f ms") % stats, | ||
| ), | ||
| ( | ||
| _("Context switches"), | ||
| _("%(vcsw)d voluntary, %(ivcsw)d involuntary") % stats, | ||
|
|
@@ -109,6 +113,9 @@ def generate_stats(self, request, response): | |
| # stats['urss'] = self._end_rusage.ru_idrss | ||
| # stats['usrss'] = self._end_rusage.ru_isrss | ||
|
|
||
| if hasattr(self, "_toolbar_start_time"): | ||
| stats["toolbar_time"] = (perf_counter() - self._toolbar_start_time) * 1000 | ||
|
Member
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. Consider storing the duration with an explicit type using
Author
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. Every other timing stat in this file is a millisecond float, and downstream code consumes |
||
|
|
||
| self.record_stats(stats) | ||
|
|
||
| def generate_server_timing(self, request, response): | ||
|
|
@@ -120,7 +127,13 @@ def generate_server_timing(self, request, response): | |
| self.record_server_timing( | ||
| "total_time", "Elapsed time", stats.get("total_time", 0) | ||
| ) | ||
| self.record_server_timing( | ||
| "toolbar_time", "DebugToolbar time", stats.get("toolbar_time", 0) | ||
| ) | ||
|
|
||
| @staticmethod | ||
| def _elapsed_ru(start, end, name): | ||
| return end.get(name) - start.get(name) | ||
|
|
||
| def enable_instrumentation(self): | ||
| self._toolbar_start_time = perf_counter() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EAFP: Maybe consider catching the AttributeError instead of the default if-branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could do that, but
generate_statsalready useshasattr(self, "_start_time")on line 86. elsewhere the codebase also uses this pattern so I was following that..