Module: check_mk
Branch: master
Commit: c700894a280a544fb432b4598429b9b3abadeb09
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c700894a280a54…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Oct 25 17:04:08 2012 +0200
mkeventd: new option --profile-event
---
mkeventd/bin/mkeventd | 31 ++++++++++++++++++++++++++++++-
1 files changed, 30 insertions(+), 1 deletions(-)
diff --git a/mkeventd/bin/mkeventd b/mkeventd/bin/mkeventd
index 9a63bfb..074b9d9 100755
--- a/mkeventd/bin/mkeventd
+++ b/mkeventd/bin/mkeventd
@@ -567,15 +567,41 @@ class EventServer:
os.chmod(g_pipe_path, 0666)
def run(self):
+ if opt_profile.get("event"):
+ import cProfile
+ profilefile = omd_root + "/var/mkeventd/event.profile"
+ log("Writing profile of event thread to %s." % profilefile)
+ try:
+ cProfile.run("g_event_server.run_loop()", profilefile)
+ except:
+ raise
+ finally:
+ file(profilefile + ".py",
"w").write("#!/usr/bin/python\nimport pstats\nstats =
pstats.Stats(%r)\nstats.sort_stats('time').print_stats()\n" % profilefile)
+ os.chmod(profilefile + ".py", 0755)
+ log("Created profile conversion script %s.py." % profilefile)
+
+ else:
+ self.run_loop()
+
+
+
+ def run_loop(self):
+ c = 0
while True:
+ c += 1
try:
self.serve()
+
except Exception, e:
log("EXCEPTION in event server:\n%s" % format_exception())
if opt_debug:
raise
time.sleep(1)
+ if opt_profile.get("event") and c > 100:
+ return
+
+
def serve(self):
for line in file(g_pipe_path, "r", 0):
line = line.rstrip()
@@ -592,6 +618,9 @@ class EventServer:
elapsed = time.time() - before
self.count_processing_time(elapsed)
+ if opt_profile.get("event"):
+ return
+
def do_housekeeping(self):
with lock_eventstatus:
with lock_configuration:
@@ -1974,7 +2003,7 @@ else:
short_options = "hvVgS:P:p:C:"
long_options = [ "help", "version", "verbose",
"debug", "foreground", "socket=", "pipe=",
- "pidfile=", "statedir=", "configdir",
"profile-status", "debug-locking" ]
+ "pidfile=", "statedir=", "configdir",
"profile-status", "profile-event", "debug-locking" ]
try:
opts, args = getopt.getopt(sys.argv[1:], short_options, long_options)