diff options
author | Erik Johnston <erik@matrix.org> | 2015-05-28 11:51:08 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2015-05-28 11:51:08 +0100 |
commit | 648aafc178d5ba8ea096d9e2868125626627c93c (patch) | |
tree | 8bb29b31ed3df635a58fa7a20570e5a36b1084fa | |
parent | Registration should be disabled by default (diff) | |
download | synapse-github/erikj/theseus.tar.xz |
Use theseus to profile github/erikj/theseus erikj/theseus
-rwxr-xr-x | synapse/app/homeserver.py | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py index f3513abb55..beb9366268 100755 --- a/synapse/app/homeserver.py +++ b/synapse/app/homeserver.py @@ -516,26 +516,36 @@ class SynapseSite(Site): def run(hs): - PROFILE_SYNAPSE = False + PROFILE_SYNAPSE = True if PROFILE_SYNAPSE: def profile(func): from cProfile import Profile from threading import current_thread + from theseus import Tracer + 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 - )) + try: + t = Tracer() + t.install() + + func(*args, **kargs) + + ident = current_thread().ident + name = "/tmp/%s.%s.%i.callgrind" % ( + hs.hostname, func.__name__, ident + ) + + with open(name, 'wb') as outfile: + t.write_data(outfile) + except: + logger.exception("WIBBLE") + raise return profiled - from twisted.python.threadpool import ThreadPool - ThreadPool._worker = profile(ThreadPool._worker) + # from twisted.python.threadpool import ThreadPool + # ThreadPool._worker = profile(ThreadPool._worker) reactor.run = profile(reactor.run) def in_thread(): |