Send Server-Timing header

This is useful to be able to tell when a performance issue is due to the
network or due to the actual execution time

There's hardly any overhead, so send it with every request.
This commit is contained in:
Flaviu Tamas authored and Gina Häußge committed 2021-09-15 15:22:20 +02:00
1 parent 1509f38779
commit d3bd4a895d
1 file changed
+9
+9
View File
@@ -1392,6 +1392,10 @@ class Server(object):
@app.before_request
def before_request():
g.locale = self._get_locale()
# used for performance measurement
g.start_time = octoprint.util.monotonic_time()
if self._debug and "perfprofile" in request.args:
try:
from pyinstrument import Profiler
@@ -1415,6 +1419,11 @@ class Server(object):
output_html = g.perfprofiler.output_html()
return make_response(output_html)
if hasattr(g, "start_time"):
end_time = octoprint.util.monotonic_time()
duration_ms = int((end_time - g.start_time) * 1000)
response.headers.add("Server-Timing", "app;dur={}".format(duration_ms))
return response
from octoprint.util.jinja import MarkdownFilter