Fixed timestamp log warning
This commit is contained in:
@@ -53,7 +53,7 @@ class MonotonicTimestampGenerator(object):
|
|||||||
Defaults to 1 second.
|
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()
|
self.lock = Lock()
|
||||||
with self.lock:
|
with self.lock:
|
||||||
self.last = 0
|
self.last = 0
|
||||||
@@ -97,7 +97,7 @@ class MonotonicTimestampGenerator(object):
|
|||||||
since_last_warn = now - self._last_warn
|
since_last_warn = now - self._last_warn
|
||||||
|
|
||||||
warn = (self.warn_on_drift and
|
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))
|
(since_last_warn >= self.warning_interval * 1e6))
|
||||||
if warn:
|
if warn:
|
||||||
log.warn(
|
log.warn(
|
||||||
|
|||||||
@@ -123,7 +123,10 @@ class TestTimestampGeneratorLogging(unittest.TestCase):
|
|||||||
|
|
||||||
@test_category timing
|
@test_category timing
|
||||||
"""
|
"""
|
||||||
tsg = timestamps.MonotonicTimestampGenerator()
|
tsg = timestamps.MonotonicTimestampGenerator(
|
||||||
|
warning_threshold=1e-6,
|
||||||
|
warning_interval=1e-6
|
||||||
|
)
|
||||||
#The units of _last_warn is seconds
|
#The units of _last_warn is seconds
|
||||||
tsg._last_warn = 12
|
tsg._last_warn = 12
|
||||||
|
|
||||||
@@ -181,7 +184,8 @@ class TestTimestampGeneratorLogging(unittest.TestCase):
|
|||||||
@test_category timing
|
@test_category timing
|
||||||
"""
|
"""
|
||||||
tsg = timestamps.MonotonicTimestampGenerator(
|
tsg = timestamps.MonotonicTimestampGenerator(
|
||||||
warning_threshold=1e-6
|
warning_threshold=1e-6,
|
||||||
|
warning_interval=1e-6
|
||||||
)
|
)
|
||||||
tsg.last, tsg._last_warn = 100, 97
|
tsg.last, tsg._last_warn = 100, 97
|
||||||
tsg._next_timestamp(98, tsg.last)
|
tsg._next_timestamp(98, tsg.last)
|
||||||
@@ -198,6 +202,7 @@ class TestTimestampGeneratorLogging(unittest.TestCase):
|
|||||||
@test_category timing
|
@test_category timing
|
||||||
"""
|
"""
|
||||||
tsg = timestamps.MonotonicTimestampGenerator(
|
tsg = timestamps.MonotonicTimestampGenerator(
|
||||||
|
warning_threshold=1e-6,
|
||||||
warning_interval=2e-6
|
warning_interval=2e-6
|
||||||
)
|
)
|
||||||
tsg.last = 100
|
tsg.last = 100
|
||||||
@@ -219,7 +224,8 @@ class TestTimestampGeneratorLogging(unittest.TestCase):
|
|||||||
@test_category timing
|
@test_category timing
|
||||||
"""
|
"""
|
||||||
tsg = timestamps.MonotonicTimestampGenerator(
|
tsg = timestamps.MonotonicTimestampGenerator(
|
||||||
warning_interval=1e-6
|
warning_interval=1e-6,
|
||||||
|
warning_threshold=1e-6,
|
||||||
)
|
)
|
||||||
tsg.last = 100
|
tsg.last = 100
|
||||||
tsg._next_timestamp(70, tsg.last)
|
tsg._next_timestamp(70, tsg.last)
|
||||||
@@ -249,7 +255,7 @@ class TestTimestampGeneratorMultipleThreads(unittest.TestCase):
|
|||||||
with lock:
|
with lock:
|
||||||
generated_timestamps.append(timestamp)
|
generated_timestamps.append(timestamp)
|
||||||
|
|
||||||
tsg = timestamps.MonotonicTimestampGenerator(warning_threshold=1)
|
tsg = timestamps.MonotonicTimestampGenerator()
|
||||||
fixed_time = 1
|
fixed_time = 1
|
||||||
num_threads = 5
|
num_threads = 5
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user