From 2b0eb839dbe1dd0e703cf0ac47b2ae31278c3b06 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 27 May 2015 15:31:00 +0100 Subject: [PATCH] Use pyinstrument --- synapse/app/homeserver.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py index 04986fc6ce..a5c96c86f9 100755 --- a/synapse/app/homeserver.py +++ b/synapse/app/homeserver.py @@ -519,26 +519,30 @@ def run(hs): 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 = Profiler() start = int(time.time()*1000) - profile.enable() + profile.start() func(*args, **kargs) - profile.disable() + profile.stop() end = int(time.time()*1000) - if end - start > 100: + if end - start > 10: ident = current_thread().ident - profile.dump_stats("/tmp/%s.%s.%i.%d-%d.pstat" % ( + name = "/tmp/%s.%s.%i.%d-%d" % ( hs.hostname, func.__name__, ident, start, end - )) + ) + # profile.dump_stats(name + ".pstat") + html = profile.output_html() + with open(name + ".html", "w") as f: + f.write(html) return profiled