1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Reenabled site generation profiling

This commit is contained in:
krateng 2022-04-12 19:04:22 +02:00
parent 6b39ca8b19
commit 1c2062c512
2 changed files with 16 additions and 9 deletions

View File

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

View File

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