diff options
| -rwxr-xr-x | py3status/__init__.py | 31 | ||||
| -rw-r--r-- | py3status/modules/dpms.py | 11 |
2 files changed, 35 insertions, 7 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 diff --git a/py3status/modules/dpms.py b/py3status/modules/dpms.py index c2d9c4e..ecbc3a7 100644 --- a/py3status/modules/dpms.py +++ b/py3status/modules/dpms.py @@ -15,19 +15,17 @@ from os import system class Py3status: """ """ - def __init__(self): - """ - Detect current state on start. - """ - self.run = system('xset -q | grep -iq "DPMS is enabled"') == 0 - def dpms(self, i3s_output_list, i3s_config): """ Display a colorful state of DPMS. """ + + self.run = system('xset -q | grep -iq "DPMS is enabled"') == 0 + response = { 'full_text': 'DPMS' } + if self.run: response['color'] = i3s_config['color_good'] else: @@ -45,4 +43,3 @@ class Py3status: else: self.run = True system("xset +dpms;xset s on") - system("killall -USR1 py3status") |
