mirror of
https://github.com/element-hq/synapse.git
synced 2024-11-21 17:15:38 +03:00
Use theseus to profile
This commit is contained in:
parent
36b3b75b21
commit
648aafc178
1 changed files with 21 additions and 11 deletions
|
@ -516,26 +516,36 @@ class SynapseSite(Site):
|
||||||
|
|
||||||
|
|
||||||
def run(hs):
|
def run(hs):
|
||||||
PROFILE_SYNAPSE = False
|
PROFILE_SYNAPSE = True
|
||||||
if PROFILE_SYNAPSE:
|
if PROFILE_SYNAPSE:
|
||||||
def profile(func):
|
def profile(func):
|
||||||
from cProfile import Profile
|
from cProfile import Profile
|
||||||
from threading import current_thread
|
from threading import current_thread
|
||||||
|
|
||||||
|
from theseus import Tracer
|
||||||
|
|
||||||
def profiled(*args, **kargs):
|
def profiled(*args, **kargs):
|
||||||
profile = Profile()
|
try:
|
||||||
profile.enable()
|
t = Tracer()
|
||||||
func(*args, **kargs)
|
t.install()
|
||||||
profile.disable()
|
|
||||||
ident = current_thread().ident
|
func(*args, **kargs)
|
||||||
profile.dump_stats("/tmp/%s.%s.%i.pstat" % (
|
|
||||||
hs.hostname, func.__name__, ident
|
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
|
return profiled
|
||||||
|
|
||||||
from twisted.python.threadpool import ThreadPool
|
# from twisted.python.threadpool import ThreadPool
|
||||||
ThreadPool._worker = profile(ThreadPool._worker)
|
# ThreadPool._worker = profile(ThreadPool._worker)
|
||||||
reactor.run = profile(reactor.run)
|
reactor.run = profile(reactor.run)
|
||||||
|
|
||||||
def in_thread():
|
def in_thread():
|
||||||
|
|
Loading…
Reference in a new issue