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

Improve per-block CPU and DB usage metrics #7426

Merged
merged 3 commits into from
May 6, 2020
Merged
Changes from 1 commit
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
18 changes: 13 additions & 5 deletions synapse/logging/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ class LoggingContext(object):
"name",
"parent_context",
"_resource_usage",
"_prev_resource_usage",
"usage_start",
"main_thread",
"finished",
Expand All @@ -259,6 +260,7 @@ def __init__(self, name=None, parent_context=None, request=None) -> None:

# track the resources used by this context so far
self._resource_usage = ContextResourceUsage()
self._prev_resource_usage = None # type: Optional[ContextResourceUsage]

# The thread resource usage when the logcontext became active. None
# if the context is not currently active.
Expand Down Expand Up @@ -434,12 +436,18 @@ def stop(self, rusage: "Optional[resource._RUsage]") -> None:
self._resource_usage.ru_utime += utime_delta
self._resource_usage.ru_stime += stime_delta

# if we have a parent, pass our CPU usage stats on
# if we have a parent, pass the change in our usage stats on.
if self.parent_context:
self.parent_context._resource_usage += self._resource_usage

# reset them in case we get entered again
self._resource_usage.reset()
if self._prev_resource_usage:
delta_resource_usage = (
self._resource_usage - self._prev_resource_usage
)
else:
delta_resource_usage = self._resource_usage
self.parent_context._resource_usage += delta_resource_usage

# Store the current usage for future deltas.
self._prev_resource_usage = self._resource_usage.copy()
clokep marked this conversation as resolved.
Show resolved Hide resolved
finally:
self.usage_start = None

Expand Down