Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Add missing type hints to synapse.app. #11287

Merged
merged 13 commits into from
Nov 10, 2021
24 changes: 0 additions & 24 deletions synapse/app/homeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,30 +413,6 @@ def format_config_error(e: ConfigError) -> Iterator[str]:


def run(hs: HomeServer):
PROFILE_SYNAPSE = False
if PROFILE_SYNAPSE:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this broken, sorry?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code doesn't work:

type object 'ThreadPool' has no attribute '_worker'

It also doesn't have anyway to enable it without modifying code, so I figure this seems less than useful. I believe that cProfile has too much overhead for actually running synapse, but 🤷 I can attempt to get it to work if you'd like.


def profile(func):
from cProfile import Profile
from threading import current_thread

def profiled(*args, **kargs):
profile = Profile()
profile.enable()
func(*args, **kargs)
profile.disable()
ident = current_thread().ident
profile.dump_stats(
"/tmp/%s.%s.%i.pstat" % (hs.hostname, func.__name__, ident)
)

return profiled

from twisted.python.threadpool import ThreadPool

ThreadPool._worker = profile(ThreadPool._worker)
reactor.run = profile(reactor.run)

_base.start_reactor(
"synapse-homeserver",
soft_file_limit=hs.config.server.soft_file_limit,
Expand Down