Moved page load performance measuring to profiler module

This commit is contained in:
krateng 2022-03-06 03:17:31 +01:00
parent e398dd3ac1
commit 57142bc327
2 changed files with 19 additions and 9 deletions

View File

@ -1,17 +1,33 @@
import os
import cProfile, pstats
from doreah.logging import log
from doreah.timing import Clock
from ..globalconf import data_dir
profiler = cProfile.Profile()
def profile(func):
def newfunc(*args,**kwargs):
benchmarkfolder = data_dir['logs']("benchmarks")
os.makedirs(benchmarkfolder,exist_ok=True)
clock = Clock()
clock.start()
profiler.enable()
result = func(*args,**kwargs)
profiler.disable()
try:
pstats.Stats(profiler).dump_stats(f"dev/benchmarking/{func.__name__}.stats")
pstats.Stats(profiler).dump_stats(os.path.join(benchmarkfolder,f"{func.__name__}.stats"))
except:
pass
log(f"Executed {func.__name__} ({args}, {kwargs}) in {clock.stop():.5f}s",module="debug_performance")
return result
return newfunc

View File

@ -13,7 +13,6 @@ import waitress
# doreah toolkit
from doreah.logging import log
from doreah.timing import Clock
from doreah import auth
# rest of the project
@ -224,10 +223,6 @@ def jinja_page(name):
adminmode = request.cookies.get("adminmode") == "true" and auth.check(request)
clock = Clock()
clock.start()
with JinjaDBConnection() as conn:
loc_context = {
@ -247,7 +242,6 @@ def jinja_page(name):
if malojaconfig["DEV_MODE"]: jinja_environment.cache.clear()
log("Generated page {name} in {time:.5f}s".format(name=name,time=clock.stop()),module="debug_performance")
return clean_html(res)
@webserver.route("/<name:re:admin.*>")