Compare commits

...

4 Commits

Author SHA1 Message Date
Olivier Wilkinson (reivilibre)
54c230d80c Use the SYNAPSE_VIZTRACER as the output path 2022-01-19 14:50:34 +00:00
Olivier Wilkinson (reivilibre)
2130e9ff9f Actually call the setup_viztracer function 2022-01-19 11:32:38 +00:00
Olivier Wilkinson (reivilibre)
2ea5d11cb6 Work around lack of logging so early at startup (think about doing this better later) 2022-01-19 11:26:37 +00:00
Olivier Wilkinson (reivilibre)
6717a84678 Allow installing VizTracer with SYNAPSE_VIZTRACER=1 env var 2022-01-19 10:27:49 +00:00
3 changed files with 38 additions and 0 deletions

View File

@@ -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

View File

@@ -446,10 +446,42 @@ 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.
"""
def eprint(msg: str) -> None:
print(msg, file=sys.stderr)
viztracer_output_path = os.environ.get("SYNAPSE_VIZTRACER", "")
if viztracer_output_path:
eprint(
f"SYNAPSE_VIZTRACER is set. Installing VizTracer hooks to output to {viztracer_output_path}."
)
try:
from viztracer import VizTracer
VizTracer(output_file=viztracer_output_path).install()
except ImportError:
eprint("VizTracer could not be imported: can't install hooks.")
else:
eprint(
"SYNAPSE_VIZTRACER not set (or is empty): won't install VizTracer hooks."
)
def main() -> None:
with LoggingContext("main"):
# check base requirements
check_requirements()
# Set up VizTracer for debugging (if enabled)
setup_viztracer()
hs = setup(sys.argv[1:])
# redirect stdio to the logs, if configured.

View File

@@ -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()