Module: check_mk
Branch: master
Commit: e95ed330110fe3d5acec1605b408b03ed1d0f05c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e95ed330110fe3…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Mar 1 09:22:03 2016 +0100
Cleaned up profiling code again
---
web/htdocs/index.py | 40 +++++++++++++++++++++-------------------
1 file changed, 21 insertions(+), 19 deletions(-)
diff --git a/web/htdocs/index.py b/web/htdocs/index.py
index e35cd19..a4487b1 100644
--- a/web/htdocs/index.py
+++ b/web/htdocs/index.py
@@ -36,25 +36,6 @@ from html_mod_python import html_mod_python, FinalizeRequest
# Main entry point for all HTTP-requests (called directly by mod_apache)
def handler(req, fields = None, is_profiling = False):
- if not is_profiling and os.path.exists(defaults.var_dir + "/profiling"):
- 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)
- 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)
- return apache.OK
-
-
# Create an object that contains all data about the request and
# helper functions for creating valid HTML. Parse URI and
# store results in the request object for later usage.
@@ -62,6 +43,7 @@ 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.
html.init_modes()
@@ -239,6 +221,26 @@ 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"):
+ 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)
+ 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()
+
+
# Early initialization upon first start of the application by the server
def initialize():
init_sys_path()