1 files changed, 24 insertions, 12 deletions
diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py
index f3513abb55..a41cd4f433 100755
--- a/synapse/app/homeserver.py
+++ b/synapse/app/homeserver.py
@@ -516,27 +516,39 @@ class SynapseSite(Site):
def run(hs):
- PROFILE_SYNAPSE = False
+ PROFILE_SYNAPSE = True
if PROFILE_SYNAPSE:
def profile(func):
- from cProfile import Profile
+ from pyinstrument import Profiler
from threading import current_thread
+ import time
def profiled(*args, **kargs):
- profile = Profile()
- profile.enable()
+ profile = Profiler()
+
+ start = int(time.time()*1000)
+
+ profile.start()
func(*args, **kargs)
- profile.disable()
- ident = current_thread().ident
- profile.dump_stats("/tmp/%s.%s.%i.pstat" % (
- hs.hostname, func.__name__, ident
- ))
+ profile.stop()
+
+ end = int(time.time()*1000)
+
+ if end - start > 100:
+ ident = current_thread().ident
+ name = "/tmp/%s.%s.%i.%d-%d.%d" % (
+ hs.hostname, func.__name__, ident, start, end, end-start
+ )
+ # profile.dump_stats(name + ".pstat")
+ html = profile.output_html()
+ with open(name + ".html", "w") as f:
+ f.write(html)
return profiled
- from twisted.python.threadpool import ThreadPool
- ThreadPool._worker = profile(ThreadPool._worker)
- reactor.run = profile(reactor.run)
+ # from twisted.python.threadpool import ThreadPool
+ # ThreadPool._worker = profile(ThreadPool._worker)
+ reactor.runUntilCurrent = profile(reactor.runUntilCurrent)
def in_thread():
with LoggingContext("run"):
|