diff options
author | Mark Haines <mark.haines@matrix.org> | 2015-08-13 17:27:53 +0100 |
---|---|---|
committer | Mark Haines <mark.haines@matrix.org> | 2015-08-13 17:27:53 +0100 |
commit | c5966b2a97090bf5b1e2ced83e3f424a3f4d4cad (patch) | |
tree | 3cc3a75259e130906b963570e2c747f5ab0cba2d /synapse/metrics/__init__.py | |
parent | Add a few strategic new lines to break up the on_query_client_keys and on_cla... (diff) | |
parent | Merge pull request #224 from matrix-org/erikj/reactor_metrics (diff) | |
download | synapse-c5966b2a97090bf5b1e2ced83e3f424a3f4d4cad.tar.xz |
Merge remote-tracking branch 'origin/develop' into markjh/end-to-end-key-federation
Diffstat (limited to 'synapse/metrics/__init__.py')
-rw-r--r-- | synapse/metrics/__init__.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/synapse/metrics/__init__.py b/synapse/metrics/__init__.py index 9233ea3da9..0be9772991 100644 --- a/synapse/metrics/__init__.py +++ b/synapse/metrics/__init__.py @@ -18,8 +18,12 @@ from __future__ import absolute_import import logging from resource import getrusage, getpagesize, RUSAGE_SELF +import functools import os import stat +import time + +from twisted.internet import reactor from .metric import ( CounterMetric, CallbackMetric, DistributionMetric, CacheMetric @@ -144,3 +148,28 @@ def _process_fds(): return counts get_metrics_for("process").register_callback("fds", _process_fds, labels=["type"]) + +reactor_metrics = get_metrics_for("reactor") +tick_time = reactor_metrics.register_distribution("tick_time") +pending_calls_metric = reactor_metrics.register_distribution("pending_calls") + + +def runUntilCurrentTimer(func): + + @functools.wraps(func) + def f(*args, **kwargs): + pending_calls = len(reactor.getDelayedCalls()) + start = time.time() * 1000 + ret = func(*args, **kwargs) + end = time.time() * 1000 + tick_time.inc_by(end - start) + pending_calls_metric.inc_by(pending_calls) + return ret + + return f + + +if hasattr(reactor, "runUntilCurrent"): + # runUntilCurrent is called when we have pending calls. It is called once + # per iteratation after fd polling. + reactor.runUntilCurrent = runUntilCurrentTimer(reactor.runUntilCurrent) |