From 5d5092d6aef9beef98bb809788adfa3511f0a6ca Mon Sep 17 00:00:00 2001 From: Sagar Vora Date: Thu, 20 Mar 2025 08:37:51 +0530 Subject: [PATCH 1/2] fix: limit profiler output to 200 lines --- frappe/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/app.py b/frappe/app.py index 9373689380..d5114ab019 100644 --- a/frappe/app.py +++ b/frappe/app.py @@ -477,7 +477,7 @@ def serve( from werkzeug.serving import run_simple if profile or os.environ.get("USE_PROFILER"): - application = ProfilerMiddleware(application, sort_by=("cumtime", "calls")) + application = ProfilerMiddleware(application, sort_by=("cumtime", "calls"), restrictions=(200,)) if not os.environ.get("NO_STATICS"): application = application_with_statics() From f51781c90a98497a249162d539b0d1f20b91e729 Mon Sep 17 00:00:00 2001 From: Sagar Vora Date: Thu, 20 Mar 2025 08:38:25 +0530 Subject: [PATCH 2/2] fix: use python feature to limit profiler output --- frappe/recorder.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frappe/recorder.py b/frappe/recorder.py index d3eac91a00..c5318d1056 100644 --- a/frappe/recorder.py +++ b/frappe/recorder.py @@ -251,7 +251,7 @@ class Recorder: profiler_output = io.StringIO() pstats.Stats(self.profiler, stream=profiler_output).strip_dirs().sort_stats( "cumulative" - ).print_stats() + ).print_stats(200) profile = profiler_output.getvalue() profiler_output.close() return profile @@ -259,7 +259,7 @@ class Recorder: def dump(self): if not self._recording: return - profiler_output = self.process_profiler() or "" + profiler_output = self.process_profiler() request_data = { "uuid": self.uuid, @@ -277,7 +277,7 @@ class Recorder: request_data["calls"] = self.calls request_data["headers"] = self.headers request_data["form_dict"] = self.form_dict - request_data["profile"] = "".join(profiler_output.splitlines(keepends=True)[:200]) + request_data["profile"] = profiler_output frappe.cache.hset(RECORDER_REQUEST_HASH, self.uuid, request_data) if self.config.record_sql: