From 9e633703236e79b2ed719174d4113bafbcf203d7 Mon Sep 17 00:00:00 2001 From: Federico Ceratto Date: Tue, 31 Mar 2015 17:16:26 +0100 Subject: Add optional setproctitle --- py3status/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/py3status/__init__.py b/py3status/__init__.py index 9d877c8..b152366 100755 --- a/py3status/__init__.py +++ b/py3status/__init__.py @@ -23,6 +23,11 @@ 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 @contextmanager def jsonify(string): -- cgit v1.3 From 1b78174c5ee0fb091ae3762ff0f8b97125c3e6cb Mon Sep 17 00:00:00 2001 From: Federico Ceratto Date: Tue, 31 Mar 2015 18:14:05 +0100 Subject: Implement thread profiling --- py3status/__init__.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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 -- cgit v1.3 From c31bf825352e94089bf1e8ab0ea135fedb659537 Mon Sep 17 00:00:00 2001 From: Federico Ceratto Date: Tue, 31 Mar 2015 18:14:36 +0100 Subject: Disable profiling --- py3status/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py3status/__init__.py b/py3status/__init__.py index 81d0d99..bbf2560 100755 --- a/py3status/__init__.py +++ b/py3status/__init__.py @@ -31,7 +31,7 @@ except ImportError: pass # Used in development -enable_profiling = True +enable_profiling = False def profile(thread_run_fn): -- cgit v1.3