summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-08-19 17:51:08 +0100
committerErik Johnston <erik@matrix.org>2016-08-19 18:23:44 +0100
commit39b900b31614ba21e6a24abafba33a51b763534b (patch)
tree0a48b398e8f10e66018bd9ab47b9f6f266a5fbfa /synapse
parentMeasure _get_event_from_row (diff)
downloadsynapse-39b900b31614ba21e6a24abafba33a51b763534b.tar.xz
Measure http.server render
Diffstat (limited to 'synapse')
-rw-r--r--synapse/http/server.py58
1 files changed, 30 insertions, 28 deletions
diff --git a/synapse/http/server.py b/synapse/http/server.py
index 2b3c05a740..f3357d2ff7 100644
--- a/synapse/http/server.py
+++ b/synapse/http/server.py
@@ -19,6 +19,7 @@ from synapse.api.errors import (
 )
 from synapse.util.logcontext import LoggingContext, PreserveLoggingContext
 from synapse.util.caches import intern_dict
+from synapse.util.metrics import Measure
 import synapse.metrics
 import synapse.events
 
@@ -234,41 +235,42 @@ class JsonResource(HttpServer, resource.Resource):
         request_metrics = RequestMetrics()
         request_metrics.start(self.clock)
 
-        # Loop through all the registered callbacks to check if the method
-        # and path regex match
-        for path_entry in self.path_regexs.get(request.method, []):
-            m = path_entry.pattern.match(request.path)
-            if not m:
-                continue
+        with Measure(self.clock, "http.render"):
+            # Loop through all the registered callbacks to check if the method
+            # and path regex match
+            for path_entry in self.path_regexs.get(request.method, []):
+                m = path_entry.pattern.match(request.path)
+                if not m:
+                    continue
 
-            # We found a match! Trigger callback and then return the
-            # returned response. We pass both the request and any
-            # matched groups from the regex to the callback.
+                # We found a match! Trigger callback and then return the
+                # returned response. We pass both the request and any
+                # matched groups from the regex to the callback.
 
-            callback = path_entry.callback
+                callback = path_entry.callback
 
-            servlet_instance = getattr(callback, "__self__", None)
-            if servlet_instance is not None:
-                servlet_classname = servlet_instance.__class__.__name__
-            else:
-                servlet_classname = "%r" % callback
+                servlet_instance = getattr(callback, "__self__", None)
+                if servlet_instance is not None:
+                    servlet_classname = servlet_instance.__class__.__name__
+                else:
+                    servlet_classname = "%r" % callback
 
-            kwargs = intern_dict({
-                name: urllib.unquote(value).decode("UTF-8") if value else value
-                for name, value in m.groupdict().items()
-            })
+                kwargs = intern_dict({
+                    name: urllib.unquote(value).decode("UTF-8") if value else value
+                    for name, value in m.groupdict().items()
+                })
 
-            callback_return = yield callback(request, **kwargs)
-            if callback_return is not None:
-                code, response = callback_return
-                self._send_response(request, code, response)
+                callback_return = yield callback(request, **kwargs)
+                if callback_return is not None:
+                    code, response = callback_return
+                    self._send_response(request, code, response)
 
-            try:
-                request_metrics.stop(self.clock, request, servlet_classname)
-            except:
-                pass
+                try:
+                    request_metrics.stop(self.clock, request, servlet_classname)
+                except:
+                    pass
 
-            return
+                return
 
         # Huh. No one wanted to handle that? Fiiiiiine. Send 400.
         raise UnrecognizedRequestError()