mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
Fix logcontext spam on non-Linux platforms (#6059)
This checks whether the current platform supports thread resource usage tracking before logging a warning to avoid log spam. Fixes https://github.com/matrix-org/synapse/issues/6055
This commit is contained in:
parent
7100b5cc9d
commit
a86a290850
1
changelog.d/6059.bugfix
Normal file
1
changelog.d/6059.bugfix
Normal file
@ -0,0 +1 @@
|
|||||||
|
Fix logcontext spam on non-Linux platforms.
|
@ -1,4 +1,5 @@
|
|||||||
# Copyright 2014-2016 OpenMarket Ltd
|
# Copyright 2014-2016 OpenMarket Ltd
|
||||||
|
# Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
@ -42,13 +43,17 @@ try:
|
|||||||
# exception.
|
# exception.
|
||||||
resource.getrusage(RUSAGE_THREAD)
|
resource.getrusage(RUSAGE_THREAD)
|
||||||
|
|
||||||
|
is_thread_resource_usage_supported = True
|
||||||
|
|
||||||
def get_thread_resource_usage():
|
def get_thread_resource_usage():
|
||||||
return resource.getrusage(RUSAGE_THREAD)
|
return resource.getrusage(RUSAGE_THREAD)
|
||||||
|
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
# If the system doesn't support resource.getrusage(RUSAGE_THREAD) then we
|
# If the system doesn't support resource.getrusage(RUSAGE_THREAD) then we
|
||||||
# won't track resource usage by returning None.
|
# won't track resource usage.
|
||||||
|
is_thread_resource_usage_supported = False
|
||||||
|
|
||||||
def get_thread_resource_usage():
|
def get_thread_resource_usage():
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -359,7 +364,11 @@ class LoggingContext(object):
|
|||||||
|
|
||||||
# When we stop, let's record the cpu used since we started
|
# When we stop, let's record the cpu used since we started
|
||||||
if not self.usage_start:
|
if not self.usage_start:
|
||||||
logger.warning("Called stop on logcontext %s without calling start", self)
|
# Log a warning on platforms that support thread usage tracking
|
||||||
|
if is_thread_resource_usage_supported:
|
||||||
|
logger.warning(
|
||||||
|
"Called stop on logcontext %s without calling start", self
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
utime_delta, stime_delta = self._get_cputime()
|
utime_delta, stime_delta = self._get_cputime()
|
||||||
|
Loading…
Reference in New Issue
Block a user