Module: check_mk
Branch: master
Commit: 54afce4ff26727be287d22f4b69a883f65e29a3e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=54afce4ff26727…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Oct 18 16:58:26 2017 +0200
Profiling can now be enabled per HTTP request
Change-Id: I31cc9738d938e63b95a8b34d31e9a01c7549bd5e
---
web/htdocs/index.py | 36 ++++++++++++++++++------------
web/plugins/wato/check_mk_configuration.py | 19 +++++++++++-----
2 files changed, 35 insertions(+), 20 deletions(-)
diff --git a/web/htdocs/index.py b/web/htdocs/index.py
index a0f29dd..099073d 100644
--- a/web/htdocs/index.py
+++ b/web/htdocs/index.py
@@ -239,24 +239,32 @@ def init_sys_path():
def init_profiling(is_profiling):
- if not is_profiling and config.profile:
- import cProfile
+ if is_profiling:
+ return # Don't start again when already profiling
- # Ubuntu: install python-profiler when using this feature
- profile_file = cmk.paths.var_dir + "/multisite.profile"
+ if config.profile == False:
+ return # Not enabled
- p = cProfile.Profile()
- p.runcall(handler, html.req, html.fields, True)
- p.dump_stats(profile_file)
+ if config.profile == "enable_by_var" and not
html.has_var("_profile"):
+ return # Not enabled by HTTP variable
- file(profile_file + ".py", "w").write(
- "#!/usr/bin/env 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)
+ import cProfile
- raise FinalizeRequest()
+ # Ubuntu: install python-profiler when using this feature
+ profile_file = cmk.paths.var_dir + "/multisite.profile"
+
+ p = cProfile.Profile()
+ p.runcall(handler, html.req, html.fields, True)
+ p.dump_stats(profile_file)
+
+ file(profile_file + ".py", "w").write(
+ "#!/usr/bin/env 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
diff --git a/web/plugins/wato/check_mk_configuration.py
b/web/plugins/wato/check_mk_configuration.py
index e579999..c127b7f 100644
--- a/web/plugins/wato/check_mk_configuration.py
+++ b/web/plugins/wato/check_mk_configuration.py
@@ -110,14 +110,21 @@ register_configvar(group,
register_configvar(group,
"profile",
- Checkbox(
+ DropdownChoice(
title = _("Profile requests"),
- label = _("enable profile mode"),
help = _("It is possible to profile the rendering process of Multisite
pages. This "
- "Is done using the Python module cProfile. When enabled two files
are placed "
- "into the Multisite var directory named
<tt>multisite.profile</tt> and "
- "<tt>multisite.profile.py</tt>. By executing the later
file you can get "
- "runtime statistics about the last processed page."),
+ "Is done using the Python module cProfile. When profiling is
performed "
+ "two files are created <tt>%s</tt> and
<tt>%s</tt>. By executing the later "
+ "file you can get runtime statistics about the last processed page.
When "
+ "enabled by request the profiling mode is enabled by providing the
HTTP "
+ "variable <tt>_profile</tt>.") %
+ (site_neutral_path(cmk.paths.var_dir +
"/multisite.profile"),
+ site_neutral_path(cmk.paths.var_dir +
"/multisite.profile.py")),
+ choices = [
+ (False, _("Disable profiling")),
+ ("enable_by_var", _("Enable profiling by request")),
+ (True, _("Enable profiling for all requests")),
+ ],
),
domain = "multisite"
)