Fixed timestamp log warning

This commit is contained in:
bjmb
2017-03-06 16:19:44 -05:00
committed by Jim Witschey
parent 7e6a7e4d13
commit 9ac54596e1
2 changed files with 12 additions and 6 deletions

View File

@@ -53,7 +53,7 @@ class MonotonicTimestampGenerator(object):
Defaults to 1 second.
"""
def __init__(self, warn_on_drift=True, warning_threshold=0, warning_interval=0):
def __init__(self, warn_on_drift=True, warning_threshold=warning_threshold, warning_interval=warning_interval):
self.lock = Lock()
with self.lock:
self.last = 0
@@ -97,7 +97,7 @@ class MonotonicTimestampGenerator(object):
since_last_warn = now - self._last_warn
warn = (self.warn_on_drift and
(diff > self.warning_threshold * 1e6) and
(diff >= self.warning_threshold * 1e6) and
(since_last_warn >= self.warning_interval * 1e6))
if warn:
log.warn(

View File

@@ -123,7 +123,10 @@ class TestTimestampGeneratorLogging(unittest.TestCase):
@test_category timing
"""
tsg = timestamps.MonotonicTimestampGenerator()
tsg = timestamps.MonotonicTimestampGenerator(
warning_threshold=1e-6,
warning_interval=1e-6
)
#The units of _last_warn is seconds
tsg._last_warn = 12
@@ -181,7 +184,8 @@ class TestTimestampGeneratorLogging(unittest.TestCase):
@test_category timing
"""
tsg = timestamps.MonotonicTimestampGenerator(
warning_threshold=1e-6
warning_threshold=1e-6,
warning_interval=1e-6
)
tsg.last, tsg._last_warn = 100, 97
tsg._next_timestamp(98, tsg.last)
@@ -198,6 +202,7 @@ class TestTimestampGeneratorLogging(unittest.TestCase):
@test_category timing
"""
tsg = timestamps.MonotonicTimestampGenerator(
warning_threshold=1e-6,
warning_interval=2e-6
)
tsg.last = 100
@@ -219,7 +224,8 @@ class TestTimestampGeneratorLogging(unittest.TestCase):
@test_category timing
"""
tsg = timestamps.MonotonicTimestampGenerator(
warning_interval=1e-6
warning_interval=1e-6,
warning_threshold=1e-6,
)
tsg.last = 100
tsg._next_timestamp(70, tsg.last)
@@ -249,7 +255,7 @@ class TestTimestampGeneratorMultipleThreads(unittest.TestCase):
with lock:
generated_timestamps.append(timestamp)
tsg = timestamps.MonotonicTimestampGenerator(warning_threshold=1)
tsg = timestamps.MonotonicTimestampGenerator()
fixed_time = 1
num_threads = 5