bumblebee-status/modules/contrib/nvidiagpu.py

77 lines
2.3 KiB
Python
Raw Normal View History

2020-04-24 16:08:53 +02:00
# -*- coding: utf-8 -*-
"""Displays GPU name, temperature and memory usage.
Parameters:
2020-04-24 16:09:12 +02:00
* nvidiagpu.format: Format string (defaults to '{name}: {temp}°C %{usedmem}/{totalmem} MiB')
2020-04-24 16:08:53 +02:00
Available values are: {name} {temp} {mem_used} {mem_total} {fanspeed} {clock_gpu} {clock_mem}
Requires nvidia-smi
"""
import core.module
import core.widget
2020-04-24 16:08:53 +02:00
import util.cli
2020-04-28 20:15:25 +02:00
import util.format
class Module(core.module.Module):
def __init__(self, config, theme):
super().__init__(config, theme, core.widget.Widget(self.utilization))
self.__utilization = 'Not found: 0 0/0'
2020-04-24 16:08:53 +02:00
def utilization(self, widget):
return self.__utilization
2020-04-24 16:08:53 +02:00
2020-04-28 20:15:25 +02:00
def hidden(self):
return "not found" in self.__utilization
2020-04-28 20:15:25 +02:00
def update(self):
sp = util.cli.execute('nvidia-smi -q', ignore_errors=True)
2020-04-24 16:08:53 +02:00
2020-04-24 16:09:12 +02:00
title = ''
usedMem = ''
totalMem = ''
temp = ''
name = 'not found'
clockMem = ''
clockGpu = ''
fanspeed = ''
for item in sp.split('\n'):
2020-04-24 16:08:53 +02:00
try:
key, val = item.split(':')
key, val = key.strip(), val.strip()
2020-04-24 16:09:12 +02:00
if title == 'Clocks':
if key == 'Graphics':
clockGpu = val.split(' ')[0]
elif key == 'Memory':
clockMem = val.split(' ')[0]
if title == 'FB Memory Usage':
if key == 'Total':
totalMem = val.split(' ')[0]
elif key == 'Used':
usedMem = val.split(' ')[0]
elif key == 'GPU Current Temp':
temp = val.split(' ')[0]
elif key == 'Product Name':
2020-04-24 16:08:53 +02:00
name = val
2020-04-24 16:09:12 +02:00
elif key == 'Fan Speed':
fanspeed = val.split(' ')[0]
2020-04-24 16:08:53 +02:00
except:
title = item.strip()
2020-04-24 16:09:12 +02:00
str_format = self.parameter('format', '{name}: {temp}°C {mem_used}/{mem_total} MiB')
self.__utilization = str_format.format(
2020-04-24 16:08:53 +02:00
name = name,
temp = temp,
mem_used = usedMem,
mem_total = totalMem,
clock_gpu = clockGpu,
clock_mem = clockMem,
fanspeed = fanspeed,
)
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4