summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-05-29 14:31:39 +0100
committerErik Johnston <erik@matrix.org>2015-05-29 14:31:39 +0100
commit7f20f0137035c12d4afc88c4507b0fd79419ac0f (patch)
tree3cb62c528e0b8237e7e47064fd46e55412b69f4d
parentmerge branch 'erikj/ultrajson' of github.com:matrix-org/synapse into erikj/pr... (diff)
downloadsynapse-7f20f0137035c12d4afc88c4507b0fd79419ac0f.tar.xz
Use pyinstrument
-rwxr-xr-xsynapse/app/homeserver.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py
index 6c01fcd423..f6e222f1da 100755
--- a/synapse/app/homeserver.py
+++ b/synapse/app/homeserver.py
@@ -523,21 +523,21 @@ 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
             import resource
 
             def profiled(*args, **kargs):
-                profile = Profile()
+                profile = Profiler()
 
                 rusage = resource.getrusage(resource.RUSAGE_SELF)
                 start_utime = rusage.ru_utime * 1000
                 start = int(time.time()*1000)
 
-                profile.enable()
+                profile.start()
                 func(*args, **kargs)
-                profile.disable()
+                profile.stop()
 
                 end = int(time.time()*1000)
                 rusage = resource.getrusage(resource.RUSAGE_SELF)
@@ -545,11 +545,14 @@ def run(hs):
 
                 if end_utime - start_utime > 50:
                     ident = current_thread().ident
-                    name = "/tmp/%s.%s.%i.%d-%d.%d-%d.pstat" % (
+                    name = "/tmp/%s.%s.%i.%d-%d.%d-%d" % (
                         hs.hostname, func.__name__, ident, start, end,
                         end-start, end_utime - start_utime,
                     )
-                    profile.dump_stats(name)
+                    # profile.dump_stats(name + ".html")
+                    html = profile.output_html()
+                    with open(name + ".html", "w") as f:
+                        f.write(html)
 
             return profiled