Module: check_mk
Branch: master
Commit: 77cb5c921a2c86e0671ed517495c897639b23384
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=77cb5c921a2c86…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Mar 1 10:11:14 2016 +0100
Finally cleaned up profiling again. Is now enabled / disabled by config again.
---
web/htdocs/index.py | 19 ++++++++++---------
web/htdocs/modules.py | 2 +-
2 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/web/htdocs/index.py b/web/htdocs/index.py
index a4487b1..1cad319 100644
--- a/web/htdocs/index.py
+++ b/web/htdocs/index.py
@@ -43,8 +43,8 @@ def handler(req, fields = None, is_profiling = False):
response_code = apache.OK
try:
- init_profiling(req, fields, is_profiling)
config.load_config() # load multisite.mk etc.
+ init_profiling(is_profiling)
html.init_modes()
# Make sure all plugins are avaiable as early as possible. At least
@@ -221,23 +221,24 @@ def init_sys_path():
sys.path[0:0] = [ local_module_path, defaults.web_dir + "/htdocs"
]
-def init_profiling(req, fields, is_profiling):
- if not is_profiling and os.path.exists(defaults.var_dir + "/profiling"):
+def init_profiling(is_profiling):
+ if not is_profiling and config.profile:
import cProfile
- # the profiler loses the memory about all modules. We need to hand over
- # the request object in the apache module.
+
# Ubuntu: install python-profiler when using this feature
profile_file = defaults.var_dir + "/profiling/multisite.profile"
- retcode = cProfile.runctx(
- "import index; "
- "index.handler(profile_req, profile_fields, is_profiling=True)",
- {'profile_req': req, 'profile_fields': fields}, {},
profile_file)
+
+ p = cProfile.Profile()
+ p.runcall(handler, html.req, html.fields, True)
+ p.dump_stats(profile_file)
+
file(profile_file + ".py", "w").write(
"#!/usr/bin/python\n"
"import pstats\n"
"stats = pstats.Stats(%r)\n"
"stats.sort_stats('time').print_stats()\n" % profile_file)
os.chmod(profile_file + ".py", 0755)
+
raise FinalizeRequest()
diff --git a/web/htdocs/modules.py b/web/htdocs/modules.py
index c3bac52..572e492 100644
--- a/web/htdocs/modules.py
+++ b/web/htdocs/modules.py
@@ -63,7 +63,7 @@ def init_modules():
module_names_prev = set(imports())
- # The config module is handled separate from the other modulesa
+ # The config module is handled separate from the other modules
module_names_prev.add("config")
# Load the list of internal hard coded modules