summary refs log tree commit diff
path: root/synapse/util/metrics.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2019-12-09 11:32:44 +0000
committerGitHub <noreply@github.com>2019-12-09 11:32:44 +0000
commita9b393340fb9e4bf227f5ef0ca3de708748a617c (patch)
treeb80d67d8eaf89bb1e993cf159643229b4672541a /synapse/util/metrics.py
parentMerge pull request #6469 from matrix-org/erikj/make_database_class (diff)
parentFixup functions to consistently return deferreds (diff)
downloadsynapse-a9b393340fb9e4bf227f5ef0ca3de708748a617c.tar.xz
Merge pull request #6484 from matrix-org/erikj/port_sync_handler
Port SyncHandler to async/await
Diffstat (limited to 'synapse/util/metrics.py')
-rw-r--r--synapse/util/metrics.py23
1 files changed, 17 insertions, 6 deletions
diff --git a/synapse/util/metrics.py b/synapse/util/metrics.py
index 3286804322..63ddaaba87 100644
--- a/synapse/util/metrics.py
+++ b/synapse/util/metrics.py
@@ -13,6 +13,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import inspect
 import logging
 from functools import wraps
 
@@ -64,12 +65,22 @@ def measure_func(name=None):
     def wrapper(func):
         block_name = func.__name__ if name is None else name
 
-        @wraps(func)
-        @defer.inlineCallbacks
-        def measured_func(self, *args, **kwargs):
-            with Measure(self.clock, block_name):
-                r = yield func(self, *args, **kwargs)
-            return r
+        if inspect.iscoroutinefunction(func):
+
+            @wraps(func)
+            async def measured_func(self, *args, **kwargs):
+                with Measure(self.clock, block_name):
+                    r = await func(self, *args, **kwargs)
+                return r
+
+        else:
+
+            @wraps(func)
+            @defer.inlineCallbacks
+            def measured_func(self, *args, **kwargs):
+                with Measure(self.clock, block_name):
+                    r = yield func(self, *args, **kwargs)
+                return r
 
         return measured_func