summaryrefslogtreecommitdiffstats
path: root/py3status/__init__.py
diff options
context:
space:
mode:
authorFederico Ceratto <federico.ceratto@gmail.com>2015-03-31 18:14:05 +0100
committerFederico Ceratto <federico.ceratto@gmail.com>2015-03-31 18:14:05 +0100
commit1b78174c5ee0fb091ae3762ff0f8b97125c3e6cb (patch)
treedd6400467ece4cee529d4432c247353ba7344626 /py3status/__init__.py
parent9e633703236e79b2ed719174d4113bafbcf203d7 (diff)
Implement thread profiling
Diffstat (limited to 'py3status/__init__.py')
-rwxr-xr-xpy3status/__init__.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/py3status/__init__.py b/py3status/__init__.py
index b152366..81d0d99 100755
--- a/py3status/__init__.py
+++ b/py3status/__init__.py
@@ -2,6 +2,7 @@ from __future__ import print_function
import argparse
import ast
+import cProfile
import imp
import locale
import os
@@ -29,6 +30,27 @@ try:
except ImportError:
pass
+# Used in development
+enable_profiling = True
+
+
+def profile(thread_run_fn):
+ if not enable_profiling:
+ return thread_run_fn
+
+ def wrapper_run(self):
+ """Wrap the Thread.run() method
+ """
+ profiler = cProfile.Profile()
+ try:
+ return profiler.runcall(thread_run_fn, self)
+ finally:
+ thread_id = getattr(self, 'ident', 'core')
+ profiler.dump_stats("py3status-%s.profile" % thread_id)
+
+ return wrapper_run
+
+
@contextmanager
def jsonify(string):
"""
@@ -472,6 +494,7 @@ class I3status(Thread):
self.write_in_tmpfile('}\n\n', tmpfile)
tmpfile.flush()
+ @profile
def run(self):
"""
Spawn i3status using a self generated config file and poll its output.
@@ -758,6 +781,7 @@ class Events(Thread):
finally:
return (instance, name)
+ @profile
def run(self):
"""
Wait for an i3bar JSON event, then find the right module to dispatch
@@ -1001,6 +1025,7 @@ class Module(Thread):
msg = 'on_click failed with ({}) for event ({})'.format(err, event)
syslog(LOG_WARNING, msg)
+ @profile
def run(self):
"""
On a timely fashion, execute every method found for this module.
@@ -1502,6 +1527,7 @@ class Py3statusWrapper():
"""
raise KeyboardInterrupt()
+ @profile
def run(self):
"""
Main py3status loop, continuously read from i3status and modules