diff options
author | Erik Johnston <erik@matrix.org> | 2021-11-08 14:52:51 +0000 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2021-11-08 14:52:51 +0000 |
commit | c5422e2ec14bc1ec71147e2014f7ebbd022447f9 (patch) | |
tree | 813a1a98775d01aba266168f6d7f61fb543d0381 /synapse | |
parent | Fixup (diff) | |
download | synapse-github/erikj/slow_sync_diag.tar.xz |
Log callbacks github/erikj/slow_sync_diag erikj/slow_sync_diag
Diffstat (limited to '')
-rw-r--r-- | synapse/metrics/__init__.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/synapse/metrics/__init__.py b/synapse/metrics/__init__.py index aec18c5a5d..91b115c10c 100644 --- a/synapse/metrics/__init__.py +++ b/synapse/metrics/__init__.py @@ -14,6 +14,7 @@ import functools import gc +import inspect import itertools import logging import os @@ -32,6 +33,7 @@ from prometheus_client.core import ( ) from twisted.internet import reactor +from twisted.internet.defer import Deferred from twisted.python.threadpool import ThreadPool import synapse @@ -589,15 +591,21 @@ def callFromThreadTimer(func): def callFromThread(f: Callable[..., Any], *args: object, **kwargs: object) -> None: @functools.wraps(f) def g(*args, **kwargs): + callbacks = None + if inspect.ismethod(f): + if isinstance(f.__self__, Deferred): + callbacks = list(f.__self__.callbacks) + start = time.time() r = f(*args, **kwargs) end = time.time() if end - start > 0.5: logger.warning( - "callFromThread took %f seconds. name: %s", + "callFromThread took %f seconds. name: %s, callbacks: %s", end - start, f, + callbacks, ) return r |