mirror of
https://github.com/element-hq/synapse.git
synced 2024-12-20 02:24:54 +03:00
Profile and output long iterations of runUntilConcurrent
This commit is contained in:
parent
99eb1172b0
commit
9f4e9fcb63
1 changed files with 16 additions and 8 deletions
|
@ -516,27 +516,35 @@ 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
|
||||||
|
import time
|
||||||
|
|
||||||
def profiled(*args, **kargs):
|
def profiled(*args, **kargs):
|
||||||
profile = Profile()
|
profile = Profile()
|
||||||
|
|
||||||
|
start = int(time.time()*1000)
|
||||||
|
|
||||||
profile.enable()
|
profile.enable()
|
||||||
func(*args, **kargs)
|
func(*args, **kargs)
|
||||||
profile.disable()
|
profile.disable()
|
||||||
ident = current_thread().ident
|
|
||||||
profile.dump_stats("/tmp/%s.%s.%i.pstat" % (
|
end = int(time.time()*1000)
|
||||||
hs.hostname, func.__name__, ident
|
|
||||||
))
|
if end - start > 100:
|
||||||
|
ident = current_thread().ident
|
||||||
|
profile.dump_stats("/tmp/%s.%s.%i.%d-%d.pstat" % (
|
||||||
|
hs.hostname, func.__name__, ident, start, end
|
||||||
|
))
|
||||||
|
|
||||||
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.runUntilCurrent = profile(reactor.runUntilCurrent)
|
||||||
|
|
||||||
def in_thread():
|
def in_thread():
|
||||||
with LoggingContext("run"):
|
with LoggingContext("run"):
|
||||||
|
|
Loading…
Reference in a new issue