mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-22 12:04:58 -05:00
Sanity-checking for metrics updates
Check that our clocks go forward.
This commit is contained in:
parent
f682af052d
commit
fe641df770
@ -325,10 +325,9 @@ class LoggingContext(object):
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
usage_end = get_thread_resource_usage()
|
utime_delta, stime_delta = self._get_cputime()
|
||||||
|
self._resource_usage.ru_utime += utime_delta
|
||||||
self._resource_usage.ru_utime += usage_end.ru_utime - self.usage_start.ru_utime
|
self._resource_usage.ru_stime += stime_delta
|
||||||
self._resource_usage.ru_stime += usage_end.ru_stime - self.usage_start.ru_stime
|
|
||||||
|
|
||||||
self.usage_start = None
|
self.usage_start = None
|
||||||
|
|
||||||
@ -346,13 +345,38 @@ class LoggingContext(object):
|
|||||||
# can include resource usage so far.
|
# can include resource usage so far.
|
||||||
is_main_thread = threading.current_thread() is self.main_thread
|
is_main_thread = threading.current_thread() is self.main_thread
|
||||||
if self.alive and self.usage_start and is_main_thread:
|
if self.alive and self.usage_start and is_main_thread:
|
||||||
current = get_thread_resource_usage()
|
utime_delta, stime_delta = self._get_cputime()
|
||||||
res.ru_utime += current.ru_utime - self.usage_start.ru_utime
|
res.ru_utime += utime_delta
|
||||||
res.ru_stime += current.ru_stime - self.usage_start.ru_stime
|
res.ru_stime += stime_delta
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def _get_cputime(self):
|
||||||
|
"""Get the cpu usage time so far
|
||||||
|
|
||||||
|
Returns: Tuple[float, float]: seconds in user mode, seconds in system mode
|
||||||
|
"""
|
||||||
|
current = get_thread_resource_usage()
|
||||||
|
|
||||||
|
utime_delta = current.ru_utime - self.usage_start.ru_utime
|
||||||
|
stime_delta = current.ru_stime - self.usage_start.ru_stime
|
||||||
|
|
||||||
|
# sanity check
|
||||||
|
if utime_delta < 0:
|
||||||
|
raise ValueError("utime went backwards! %f < %f" % (
|
||||||
|
current.ru_utime, self.usage_start.ru_utime,
|
||||||
|
))
|
||||||
|
|
||||||
|
if stime_delta < 0:
|
||||||
|
raise ValueError("stime went backwards! %f < %f" % (
|
||||||
|
current.ru_stime, self.usage_start.ru_stime,
|
||||||
|
))
|
||||||
|
|
||||||
|
return utime_delta, stime_delta
|
||||||
|
|
||||||
def add_database_transaction(self, duration_sec):
|
def add_database_transaction(self, duration_sec):
|
||||||
|
if duration_sec < 0:
|
||||||
|
raise ValueError('DB txn time can only be non-negative')
|
||||||
self._resource_usage.db_txn_count += 1
|
self._resource_usage.db_txn_count += 1
|
||||||
self._resource_usage.db_txn_duration_sec += duration_sec
|
self._resource_usage.db_txn_duration_sec += duration_sec
|
||||||
|
|
||||||
@ -363,6 +387,8 @@ class LoggingContext(object):
|
|||||||
sched_sec (float): number of seconds it took us to get a
|
sched_sec (float): number of seconds it took us to get a
|
||||||
connection
|
connection
|
||||||
"""
|
"""
|
||||||
|
if sched_sec < 0:
|
||||||
|
raise ValueError('DB scheduling time can only be non-negative')
|
||||||
self._resource_usage.db_sched_duration_sec += sched_sec
|
self._resource_usage.db_sched_duration_sec += sched_sec
|
||||||
|
|
||||||
def record_event_fetch(self, event_count):
|
def record_event_fetch(self, event_count):
|
||||||
|
Loading…
Reference in New Issue
Block a user