diff options
-rw-r--r-- | mypy.ini | 3 | ||||
-rw-r--r-- | synapse/app/homeserver.py | 22 | ||||
-rw-r--r-- | synapse/python_dependencies.py | 3 |
3 files changed, 28 insertions, 0 deletions
diff --git a/mypy.ini b/mypy.ini index 85fa22d28f..070ce06556 100644 --- a/mypy.ini +++ b/mypy.ini @@ -349,5 +349,8 @@ ignore_missing_imports = True [mypy-twisted.*] ignore_missing_imports = True +[mypy-viztracer] +ignore_missing_imports = True + [mypy-zope] ignore_missing_imports = True diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py index dd76e07321..57e57500ed 100644 --- a/synapse/app/homeserver.py +++ b/synapse/app/homeserver.py @@ -446,6 +446,28 @@ def run(hs: HomeServer) -> None: ) +def setup_viztracer() -> None: + """ + If installed and enabled by environment variable SYNAPSE_VIZTRACER=1, + install VizTracer's hooks so that Synapse can be attached to by VizTracer + at some point during runtime. + """ + + if os.environ.get("SYNAPSE_VIZTRACER", ""): + logger.info("SYNAPSE_VIZTRACER is set. Installing VizTracer hooks.") + + try: + from viztracer import VizTracer + + VizTracer().install() + except ImportError: + logger.info("VizTracer could not be imported: can't install hooks.") + else: + logger.info( + "SYNAPSE_VIZTRACER not set (or is empty): won't install VizTracer hooks." + ) + + def main() -> None: with LoggingContext("main"): # check base requirements diff --git a/synapse/python_dependencies.py b/synapse/python_dependencies.py index d844fbb3b3..96a4b1b529 100644 --- a/synapse/python_dependencies.py +++ b/synapse/python_dependencies.py @@ -116,6 +116,9 @@ CONDITIONAL_REQUIREMENTS = { "redis": ["txredisapi>=1.4.7", "hiredis"], # Required to use experimental `caches.track_memory_usage` config option. "cache_memory": ["pympler"], + # Required to install VizTracer hooks, which allows VizTracer to be attached + # at runtime. + "viztracer": ["viztracer"], } ALL_OPTIONAL_REQUIREMENTS: Set[str] = set() |