Merge pull request #31814 from sagarvora/restrict-cprofile-output

fix(DX): limit cprofiler output to 200 lines
This commit is contained in:
Sagar Vora 2025-03-20 08:48:01 +05:30 committed by GitHub
commit c5f79016eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View file

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

View file

@ -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: