From 91a0b5d05da1f47e4cbb37497b257afca9d427ee Mon Sep 17 00:00:00 2001 From: chestm007 Date: Fri, 21 Dec 2018 03:09:22 +1100 Subject: [PATCH] basic amdgpu monitoring (#686) * basic amdgpu monitoring --- i3pystatus/amdgpu.py | 60 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 i3pystatus/amdgpu.py diff --git a/i3pystatus/amdgpu.py b/i3pystatus/amdgpu.py new file mode 100644 index 0000000..50e0e00 --- /dev/null +++ b/i3pystatus/amdgpu.py @@ -0,0 +1,60 @@ +import os + +from i3pystatus import IntervalModule + + +class Amdgpu(IntervalModule): + """ + Shows information about gpu's using the amdgpu driver + + .. rubric :: Available formatters + + * `{temp}` + * `{sclk}` - Gpu clock speed + * `{mclk}` - Memory clock speed + """ + + settings = ( + 'format', + ('card', '[1, 2, ...] card to read (options are in /sys/class/drm/)') + ) + + card = 0 + format = '{temp} {mclk} {sclk}' + + def init(self): + self.dev_path = '/sys/class/drm/card{}/device/'.format(self.card) + self.detect_hwmon() + + def detect_hwmon(self): + hwmon_base = self.dev_path + 'hwmon/' + self.hwmmon_path = hwmon_base + os.listdir(hwmon_base)[0] + '/' + + def run(self): + self.data = dict( + sclk=self.get_sclk(), + mclk=self.get_mclk(), + temp=self.get_temp() + ) + + self.output = { + 'full_text': self.format.format(**self.data) + } + + @staticmethod + def parse_clk_reading(reading): + for l in reading.splitlines(): + if l.endswith('*'): + return l.split(' ')[1] + + def get_mclk(self): + with open(self.dev_path + 'pp_dpm_mclk') as f: + return self.parse_clk_reading(f.read()) + + def get_sclk(self): + with open(self.dev_path + 'pp_dpm_sclk') as f: + return self.parse_clk_reading(f.read()) + + def get_temp(self): + with open(self.hwmmon_path + 'temp1_input') as f: + return float(f.read()) / 1000