Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit a8c8d1f

Browse files
committed
Fix logcontext spam on non-Linux platforms (#6059)
2 parents 57967fc + a86a290 commit a8c8d1f

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

changelog.d/6059.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix logcontext spam on non-Linux platforms.

docs/sample_config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@ opentracing:
17121712
#enabled: true
17131713

17141714
# The list of homeservers we wish to send and receive span contexts and span baggage.
1715-
# See docs/opentracing.md
1715+
# See docs/opentracing.rst
17161716
# This is a list of regexes which are matched against the server_name of the
17171717
# homeserver.
17181718
#

synapse/logging/context.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright 2014-2016 OpenMarket Ltd
2+
# Copyright 2019 The Matrix.org Foundation C.I.C.
23
#
34
# Licensed under the Apache License, Version 2.0 (the "License");
45
# you may not use this file except in compliance with the License.
@@ -42,13 +43,17 @@
4243
# exception.
4344
resource.getrusage(RUSAGE_THREAD)
4445

46+
is_thread_resource_usage_supported = True
47+
4548
def get_thread_resource_usage():
4649
return resource.getrusage(RUSAGE_THREAD)
4750

4851

4952
except Exception:
5053
# If the system doesn't support resource.getrusage(RUSAGE_THREAD) then we
51-
# won't track resource usage by returning None.
54+
# won't track resource usage.
55+
is_thread_resource_usage_supported = False
56+
5257
def get_thread_resource_usage():
5358
return None
5459

@@ -359,7 +364,11 @@ def stop(self):
359364

360365
# When we stop, let's record the cpu used since we started
361366
if not self.usage_start:
362-
logger.warning("Called stop on logcontext %s without calling start", self)
367+
# Log a warning on platforms that support thread usage tracking
368+
if is_thread_resource_usage_supported:
369+
logger.warning(
370+
"Called stop on logcontext %s without calling start", self
371+
)
363372
return
364373

365374
utime_delta, stime_delta = self._get_cputime()

0 commit comments

Comments
 (0)