mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Moved page load performance measuring to profiler module
This commit is contained in:
parent
e398dd3ac1
commit
57142bc327
@ -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
|
||||
|
@ -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.*>")
|
||||
|
Loading…
Reference in New Issue
Block a user