Module: check_mk
Branch: master
Commit: 4b0fe79910fedb92adfff6d56d2caa8bdabc6b3a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4b0fe79910fedb…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Feb 29 14:33:52 2016 +0100
Fix Multisite profiling. It is no longer trigger by config variable
You now have to create the directory var/check_mk/profiling. If it exists, the profile
will be
created in that directory
---
web/htdocs/index.py | 41 +++++++++++++++++++----------------------
1 file changed, 19 insertions(+), 22 deletions(-)
diff --git a/web/htdocs/index.py b/web/htdocs/index.py
index 37c6f6f..e35cd19 100644
--- a/web/htdocs/index.py
+++ b/web/htdocs/index.py
@@ -36,6 +36,25 @@ 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.
@@ -45,7 +64,6 @@ def handler(req, fields = None, is_profiling = False):
try:
config.load_config() # load multisite.mk etc.
html.init_modes()
- init_profiling(is_profiling)
# Make sure all plugins are avaiable as early as possible. At least
# we need the plugins (i.e. the permissions declared in these) at the
@@ -191,27 +209,6 @@ def handler(req, fields = None, is_profiling = False):
return response_code
-# Profiling of the Check_MK GUI can be enabled via global settings
-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 + "/web/multisite.profile"
- retcode = cProfile.runctx(
- "import index; "
- "index.handler(profile_req, profile_fields, is_profiling=True)",
- {'profile_req': html.req, 'profile_fields': html.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(apache.OK)
-
-
# Ajax-Functions want no HTML output in case of an error but
# just a plain server result code of 500
def fail_silently():