From d3bd4a895d79a089ef1777eeb5efebd0f4cf77ea Mon Sep 17 00:00:00 2001 From: Flaviu Tamas Date: Sat, 11 Sep 2021 14:11:25 -0400 Subject: [PATCH] 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. --- src/octoprint/server/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index a2dde3b46..561b470db 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -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