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

Fix logcontext spam on non-Linux platforms #6059

Merged
merged 2 commits into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/6059.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix logcontext spam on non-Linux platforms.
13 changes: 11 additions & 2 deletions synapse/logging/context.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2014-2016 OpenMarket Ltd
# Copyright 2019 The Matrix.org Foundation C.I.C.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -42,13 +43,17 @@
# exception.
resource.getrusage(RUSAGE_THREAD)

is_thread_resource_usage_supported = True

def get_thread_resource_usage():
return resource.getrusage(RUSAGE_THREAD)


except Exception:
# 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():
return None

Expand Down Expand Up @@ -359,7 +364,11 @@ def stop(self):

# When we stop, let's record the cpu used since we started
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

utime_delta, stime_delta = self._get_cputime()
Expand Down