diff options
author | Richard van der Hoff <1389908+richvdh@users.noreply.github.com> | 2018-07-10 13:56:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-10 13:56:07 +0100 |
commit | 55370331da54c46c04253b009865097fe9e95191 (patch) | |
tree | a4f7c5e260460586cc3adadc8ea6470e064e7e88 /synapse/http/site.py | |
parent | another typo (diff) | |
download | synapse-55370331da54c46c04253b009865097fe9e95191.tar.xz |
Refactor logcontext resource usage tracking (#3501)
Factor out the resource usage tracking out to a separate object, which can be passed around and copied independently of the logcontext itself.
Diffstat (limited to 'synapse/http/site.py')
-rw-r--r-- | synapse/http/site.py | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/synapse/http/site.py b/synapse/http/site.py index fc954e343c..21e26f9c5e 100644 --- a/synapse/http/site.py +++ b/synapse/http/site.py @@ -20,7 +20,7 @@ from twisted.web.server import Request, Site from synapse.http import redact_uri from synapse.http.request_metrics import RequestMetrics -from synapse.util.logcontext import LoggingContext +from synapse.util.logcontext import LoggingContext, ContextResourceUsage logger = logging.getLogger(__name__) @@ -95,15 +95,9 @@ class SynapseRequest(Request): def _finished_processing(self): try: context = LoggingContext.current_context() - ru_utime, ru_stime = context.get_resource_usage() - db_txn_count = context.db_txn_count - db_txn_duration_sec = context.db_txn_duration_sec - db_sched_duration_sec = context.db_sched_duration_sec - evt_db_fetch_count = context.evt_db_fetch_count + usage = context.get_resource_usage() except Exception: - ru_utime, ru_stime = (0, 0) - db_txn_count, db_txn_duration_sec = (0, 0) - evt_db_fetch_count = 0 + usage = ContextResourceUsage() end_time = time.time() @@ -130,18 +124,18 @@ class SynapseRequest(Request): self.site.site_tag, authenticated_entity, end_time - self.start_time, - ru_utime, - ru_stime, - db_sched_duration_sec, - db_txn_duration_sec, - int(db_txn_count), + usage.ru_utime, + usage.ru_stime, + usage.db_sched_duration_sec, + usage.db_txn_duration_sec, + int(usage.db_txn_count), self.sentLength, self.code, self.method, self.get_redacted_uri(), self.clientproto, user_agent, - evt_db_fetch_count, + usage.evt_db_fetch_count, ) try: |