Module: check_mk
Branch: master
Commit: ed23640261dc855d16fb22383052d82272caf1c3
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ed23640261dc85…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Jul 27 13:01:56 2018 +0200
Add helper for checking whether or not tracking is active + early exit if not
Change-Id: Ib3b08a4f5f94f5048aabadd47adcfa790a6b40a6
---
cmk/cpu_tracking.py | 40 +++++++++++++++++++++++++---------------
1 file changed, 25 insertions(+), 15 deletions(-)
diff --git a/cmk/cpu_tracking.py b/cmk/cpu_tracking.py
index d09de20..e14018a 100644
--- a/cmk/cpu_tracking.py
+++ b/cmk/cpu_tracking.py
@@ -59,33 +59,43 @@ def end():
def push_phase(phase):
- if current_phase != None:
- console.vverbose("[cpu_tracking] Push phase (Stack: %r)\n" %
phase_stack)
- phase_stack.append(current_phase)
- _set_phase(phase)
+ if _is_not_tracking():
+ return
+
+ console.vverbose("[cpu_tracking] Push phase (Stack: %r)\n" % phase_stack)
+ phase_stack.append(current_phase)
+ _set_phase(phase)
def pop_phase():
- if current_phase != None:
- console.vverbose("[cpu_tracking] Pop current phase (Stack: %r)\n" %
phase_stack)
- if len(phase_stack) == 1:
- _set_phase(None)
- else:
- _set_phase(phase_stack[-1])
+ if _is_not_tracking():
+ return
+
+ console.vverbose("[cpu_tracking] Pop current phase (Stack: %r)\n" %
phase_stack)
+ if len(phase_stack) == 1:
+ _set_phase(None)
+ else:
+ _set_phase(phase_stack[-1])
- del phase_stack[-1]
+ del phase_stack[-1]
def get_times():
return times
+def _is_not_tracking():
+ return current_phase is None
+
+
def _set_phase(phase):
global current_phase
- if current_phase != None:
- console.vverbose("[cpu_tracking] Set phase: %s (previous %s)\n" %
(phase, current_phase))
- _add_times_to_phase()
- current_phase = phase
+ if _is_not_tracking():
+ return
+
+ console.vverbose("[cpu_tracking] Set phase: %s (previous %s)\n" % (phase,
current_phase))
+ _add_times_to_phase()
+ current_phase = phase
def _add_times_to_phase():