From 1c2062c5129e8d017a6a93c4545934f379aa14f2 Mon Sep 17 00:00:00 2001 From: krateng Date: Tue, 12 Apr 2022 19:04:22 +0200 Subject: [PATCH] Reenabled site generation profiling --- maloja/proccontrol/profiler.py | 24 +++++++++++++++--------- maloja/server.py | 1 + 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/maloja/proccontrol/profiler.py b/maloja/proccontrol/profiler.py index 3a98d35..068bf61 100644 --- a/maloja/proccontrol/profiler.py +++ b/maloja/proccontrol/profiler.py @@ -11,24 +11,30 @@ from ..globalconf import data_dir profiler = cProfile.Profile() +FULL_PROFILE = False + def profile(func): def newfunc(*args,**kwargs): - benchmarkfolder = data_dir['logs']("benchmarks") - os.makedirs(benchmarkfolder,exist_ok=True) + if FULL_PROFILE: + benchmarkfolder = data_dir['logs']("benchmarks") + os.makedirs(benchmarkfolder,exist_ok=True) clock = Clock() clock.start() - profiler.enable() + if FULL_PROFILE: + profiler.enable() result = func(*args,**kwargs) - profiler.disable() - + if FULL_PROFILE: + profiler.disable() + log(f"Executed {func.__name__} ({args}, {kwargs}) in {clock.stop():.2f}s",module="debug_performance") - try: - pstats.Stats(profiler).dump_stats(os.path.join(benchmarkfolder,f"{func.__name__}.stats")) - except: - pass + if FULL_PROFILE: + try: + pstats.Stats(profiler).dump_stats(os.path.join(benchmarkfolder,f"{func.__name__}.stats")) + except: + pass return result diff --git a/maloja/server.py b/maloja/server.py index 5975a39..639d20b 100644 --- a/maloja/server.py +++ b/maloja/server.py @@ -236,6 +236,7 @@ def static(path): ### DYNAMIC +@profile def jinja_page(name): if name in aliases: redirect(aliases[name]) keys = remove_identical(FormsDict.decode(request.query))