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
|
import cProfile, pstats
|
||||||
|
|
||||||
|
|
||||||
|
from doreah.logging import log
|
||||||
|
from doreah.timing import Clock
|
||||||
|
|
||||||
|
from ..globalconf import data_dir
|
||||||
|
|
||||||
|
|
||||||
profiler = cProfile.Profile()
|
profiler = cProfile.Profile()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def profile(func):
|
def profile(func):
|
||||||
def newfunc(*args,**kwargs):
|
def newfunc(*args,**kwargs):
|
||||||
|
|
||||||
|
benchmarkfolder = data_dir['logs']("benchmarks")
|
||||||
|
os.makedirs(benchmarkfolder,exist_ok=True)
|
||||||
|
|
||||||
|
clock = Clock()
|
||||||
|
clock.start()
|
||||||
|
|
||||||
profiler.enable()
|
profiler.enable()
|
||||||
result = func(*args,**kwargs)
|
result = func(*args,**kwargs)
|
||||||
profiler.disable()
|
profiler.disable()
|
||||||
try:
|
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:
|
except:
|
||||||
pass
|
pass
|
||||||
|
log(f"Executed {func.__name__} ({args}, {kwargs}) in {clock.stop():.5f}s",module="debug_performance")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
return newfunc
|
return newfunc
|
||||||
|
@ -13,7 +13,6 @@ import waitress
|
|||||||
|
|
||||||
# doreah toolkit
|
# doreah toolkit
|
||||||
from doreah.logging import log
|
from doreah.logging import log
|
||||||
from doreah.timing import Clock
|
|
||||||
from doreah import auth
|
from doreah import auth
|
||||||
|
|
||||||
# rest of the project
|
# rest of the project
|
||||||
@ -224,10 +223,6 @@ def jinja_page(name):
|
|||||||
|
|
||||||
adminmode = request.cookies.get("adminmode") == "true" and auth.check(request)
|
adminmode = request.cookies.get("adminmode") == "true" and auth.check(request)
|
||||||
|
|
||||||
|
|
||||||
clock = Clock()
|
|
||||||
clock.start()
|
|
||||||
|
|
||||||
with JinjaDBConnection() as conn:
|
with JinjaDBConnection() as conn:
|
||||||
|
|
||||||
loc_context = {
|
loc_context = {
|
||||||
@ -247,7 +242,6 @@ def jinja_page(name):
|
|||||||
|
|
||||||
if malojaconfig["DEV_MODE"]: jinja_environment.cache.clear()
|
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)
|
return clean_html(res)
|
||||||
|
|
||||||
@webserver.route("/<name:re:admin.*>")
|
@webserver.route("/<name:re:admin.*>")
|
||||||
|
Loading…
Reference in New Issue
Block a user