summary refs log tree commit diff
path: root/synapse/app/homeserver.py
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-05-06 17:08:00 +0100
committerMark Haines <mark.haines@matrix.org>2015-05-06 17:08:00 +0100
commit4a7a4a5b6cc6bf6201e996b5a6b1b82a4b874677 (patch)
treef5432b9bec358821691faea4487da3f5d48d606c /synapse/app/homeserver.py
parentDon't read from the config file before checking it exists (diff)
downloadsynapse-4a7a4a5b6cc6bf6201e996b5a6b1b82a4b874677.tar.xz
Optional profiling using cProfile
Diffstat (limited to '')
-rwxr-xr-xsynapse/app/homeserver.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py
index d8d0df7e41..c227265190 100755
--- a/synapse/app/homeserver.py
+++ b/synapse/app/homeserver.py
@@ -496,11 +496,31 @@ class SynapseSite(Site):
 
 
 def run(hs):
+    PROFILE_SYNAPSE = False
+    if PROFILE_SYNAPSE:
+        def profile(func):
+            from cProfile import Profile
+            from threading import current_thread
+
+            def profiled(*args, **kargs):
+                profile = Profile()
+                profile.enable()
+                func(*args, **kargs)
+                profile.disable()
+                ident = current_thread().ident
+                profile.dump_stats("/tmp/%s.%s.%i.pstat" % (
+                    hs.hostname, func.__name__, ident
+                ))
+
+            return profiled
+
+        from twisted.python.threadpool import ThreadPool
+        ThreadPool._worker = profile(ThreadPool._worker)
+        reactor.run = profile(reactor.run)
 
     def in_thread():
         with LoggingContext("run"):
             change_resource_limit(hs.config.soft_file_limit)
-
             reactor.run()
 
     if hs.config.daemonize: