Module: check_mk
Branch: master
Commit: 007e0eb247b220c5795b88fa6355898c3324af06
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=007e0eb247b220…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Jul 27 12:11:57 2018 +0200
Renamed cpu_tracking.set_phase to be module internal
Change-Id: I69a56729adffe2503948090a6c292ff50d100a91
---
cmk/cpu_tracking.py | 30 +++++++++++++++++-------------
1 file changed, 17 insertions(+), 13 deletions(-)
diff --git a/cmk/cpu_tracking.py b/cmk/cpu_tracking.py
index d1768ea..102445b 100644
--- a/cmk/cpu_tracking.py
+++ b/cmk/cpu_tracking.py
@@ -34,6 +34,10 @@ try:
except NameError:
_ = lambda x: x # Fake i18n when not available
+# TODO: Move state out of module scope
+# TODO: This should be rewritten to a context manager object. See cmk.profile for
+# an example how it could look like.
+
current_phase = None
def start(initial_phase):
@@ -43,36 +47,28 @@ def start(initial_phase):
last_time_snapshot = _time_snapshot()
current_phase = initial_phase
phase_stack = []
- set_phase(initial_phase)
+ _set_phase(initial_phase)
def end():
console.vverbose("[cpu_tracking] End\n")
- set_phase(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
+ _set_phase(None)
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)
+ _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)
+ _set_phase(None)
else:
- set_phase(phase_stack[-1])
+ _set_phase(phase_stack[-1])
del phase_stack[-1]
@@ -81,6 +77,14 @@ def get_times():
return times
+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
+
+
def _add_times_to_phase():
global last_time_snapshot
new_time_snapshot = _time_snapshot()