summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUltrabug <ultrabug@ultrabug.net>2015-04-02 18:53:02 +0200
committerUltrabug <ultrabug@ultrabug.net>2015-04-02 18:53:02 +0200
commita199d9624b56a508e362eadfc642dbbf07606412 (patch)
treeb6d975aeaa4980fe826759bfa6505cdcb45a8d4b
parente53c74e4c3586638991769e864cb97e78945d583 (diff)
parentc31bf825352e94089bf1e8ab0ea135fedb659537 (diff)
Merge pull request #89 from FedericoCeratto/profiling
add profiling support and make use of setproctitle when available to ensure the process name is always py3status by @FedericoCeratto
-rwxr-xr-xpy3status/__init__.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/py3status/__init__.py b/py3status/__init__.py
index 9d877c8..bbf2560 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
@@ -23,6 +24,32 @@ from threading import Event, Thread
from time import sleep, time
from syslog import syslog, LOG_ERR, LOG_INFO, LOG_WARNING
+try:
+ from setproctitle import setproctitle
+ setproctitle('py3status')
+except ImportError:
+ pass
+
+# Used in development
+enable_profiling = False
+
+
+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):
@@ -467,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.
@@ -753,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
@@ -996,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.
@@ -1497,6 +1527,7 @@ class Py3statusWrapper():
"""
raise KeyboardInterrupt()
+ @profile
def run(self):
"""
Main py3status loop, continuously read from i3status and modules