💾 Archived View for gemini.mcgillij.dev › cpu_governor.gmi captured on 2023-11-04 at 11:27:22. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2022-03-01)

-=-=-=-=-=-=-

cpu_governor.py a py3status module

:author:

mcgillij

:category:

Python

:date:

2021-01-29 22:49

:tags:

Linux, Python, i3, py3status, #100DaysToOffload

:slug:

cpu-governor-py3status

:summary:

Another py3status module for i3, this time for showing the CPU governor

:cover_image:

cpu_cover.png

Contents

cpu_governor

A simple module for py3status written to show the status of which CPU governor that your currently using.

If your anything like me, and change the governor quite often for different workloads, this is handy information to have on your desktop to remind you to change it back when your done doing processor intensive tasks.

Screenshot

[image: cpu_governor screenshot]

This is what the module looks like on my system## Code

Below is the entirety of the code.

# -*- coding: utf-8 -*-
"""
Module to report the CPU governor state in py3status bar
"""


class Py3status:
    cache_timeout = 600
    format = 'đź’»: {status}'

    def _get_cpu_status(self):
        try:
            status = self.py3.command_output(["cat", "/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"])
            return {'status': status.strip()}

        except self.py3.CommandError as ce:
            return len(ce.output.splitlines())

    def cpu_governor_status(self):

        status = self._get_cpu_status()
        full_text = self.py3.safe_format(self.format, status)

        return {
            'full_text': full_text,
            'cached_until': self.py3.time_in(self.cache_timeout)
        }

if __name__ == "__main__":
    from py3status.module_test import module_test
    module_test(Py3status)

Installation

To install the module just copy it to "~/.i3/py3status/" and add the following line to your "~/.config/i3/i3status.conf"

order += "cpu_governor"

That’s it, restart your i3 session and you should be able to see your cpu governor setting.

Source

The source is also

available on github

if you don’t want to copy / paste from a webpage.