summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-02-09 10:10:20 +0000
committerErik Johnston <erik@matrix.org>2016-02-09 10:12:00 +0000
commit97294ef2fd5737a58ff0a5d551a17e77dcf1baaf (patch)
tree1b7f64d90035edac648f588415adc99a0a2c65a5 /synapse
parentDon't measure across event stream call, as it lasts for a long time. (diff)
downloadsynapse-97294ef2fd5737a58ff0a5d551a17e77dcf1baaf.tar.xz
Create new context when measuring
Diffstat (limited to '')
-rw-r--r--synapse/util/metrics.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/synapse/util/metrics.py b/synapse/util/metrics.py
index ca48007218..f70d855122 100644
--- a/synapse/util/metrics.py
+++ b/synapse/util/metrics.py
@@ -48,26 +48,29 @@ block_db_txn_duration = metrics.register_distribution(
 
 
 class Measure(object):
-    __slots__ = ["clock", "name", "start_context", "start"]
+    __slots__ = ["clock", "name", "start_context", "start", "new_context"]
 
     def __init__(self, clock, name):
         self.clock = clock
         self.name = name
         self.start_context = None
         self.start = None
+        self.new_context = LoggingContext(self.name)
 
     def __enter__(self):
         self.start = self.clock.time_msec()
         self.start_context = LoggingContext.current_context()
+        self.new_context.__enter__()
 
     def __exit__(self, exc_type, exc_val, exc_tb):
+        self.new_context.__exit__(exc_type, exc_val, exc_tb)
         if exc_type is not None:
             return
 
         duration = self.clock.time_msec() - self.start
         block_timer.inc_by(duration, self.name)
 
-        context = LoggingContext.current_context()
+        context = self.new_context
 
         if context != self.start_context:
             logger.warn(