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')
|
2021-08-16 06:27:44 +02:00
|
|
|
Available values are: {name} {temp} {mem_used} {mem_total} {fanspeed} {clock_gpu} {clock_mem} {gpu_usage_pct} {mem_usage_pct} {mem_io_pct}
|
2020-04-24 16:08:53 +02:00
|
|
|
|
|
|
|
Requires nvidia-smi
|
2020-05-08 20:58:35 +02:00
|
|
|
|
|
|
|
contributed by `RileyRedpath <https://github.com/RileyRedpath>`_ - many thanks!
|
2021-08-16 06:27:44 +02:00
|
|
|
|
|
|
|
Note: mem_io_pct is (from `man nvidia-smi`):
|
|
|
|
> Percent of time over the past sample period during which global (device)
|
|
|
|
> memory was being read or written.
|
2020-04-24 16:08:53 +02:00
|
|
|
"""
|
|
|
|
|
2020-04-24 16:15:00 +02:00
|
|
|
import core.module
|
|
|
|
import core.widget
|
2020-04-24 16:08:53 +02:00
|
|
|
|
2020-04-24 16:15:00 +02:00
|
|
|
import util.cli
|
2020-04-28 20:15:25 +02:00
|
|
|
import util.format
|
2020-04-24 16:15:00 +02:00
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-04-24 16:15:00 +02:00
|
|
|
class Module(core.module.Module):
|
2020-04-26 16:39:24 +02:00
|
|
|
def __init__(self, config, theme):
|
|
|
|
super().__init__(config, theme, core.widget.Widget(self.utilization))
|
2020-04-24 16:15:00 +02:00
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
self.__utilization = "Not found: 0 0/0"
|
2020-04-24 16:08:53 +02:00
|
|
|
|
|
|
|
def utilization(self, widget):
|
2020-04-24 16:15:00 +02:00
|
|
|
return self.__utilization
|
2020-04-24 16:08:53 +02:00
|
|
|
|
2020-04-28 20:15:25 +02:00
|
|
|
def hidden(self):
|
2020-05-02 09:49:28 +02:00
|
|
|
return "not found" in self.__utilization
|
2020-04-28 20:15:25 +02:00
|
|
|
|
2020-04-24 16:15:00 +02:00
|
|
|
def update(self):
|
2020-05-03 11:15:52 +02:00
|
|
|
sp = util.cli.execute("nvidia-smi -q", ignore_errors=True)
|
|
|
|
|
|
|
|
title = ""
|
|
|
|
usedMem = ""
|
|
|
|
totalMem = ""
|
|
|
|
temp = ""
|
|
|
|
name = "not found"
|
|
|
|
clockMem = ""
|
|
|
|
clockGpu = ""
|
|
|
|
fanspeed = ""
|
2021-07-24 23:18:04 +02:00
|
|
|
gpuUsagePct = ""
|
2021-08-16 06:27:44 +02:00
|
|
|
memIoPct = ""
|
|
|
|
memUsage = "not found"
|
2020-05-03 11:15:52 +02:00
|
|
|
for item in sp.split("\n"):
|
2020-04-24 16:08:53 +02:00
|
|
|
try:
|
2020-05-03 11:15:52 +02:00
|
|
|
key, val = item.split(":")
|
2020-04-24 16:08:53 +02:00
|
|
|
key, val = key.strip(), val.strip()
|
2020-05-03 11:15:52 +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-05-03 11:15:52 +02:00
|
|
|
elif key == "Fan Speed":
|
|
|
|
fanspeed = val.split(" ")[0]
|
2021-07-24 23:18:04 +02:00
|
|
|
elif title == "Utilization":
|
|
|
|
if key == "Gpu":
|
|
|
|
gpuUsagePct = val.split(" ")[0]
|
|
|
|
elif key == "Memory":
|
2021-08-16 06:27:44 +02:00
|
|
|
memIoPct = val.split(" ")[0]
|
2020-04-24 16:08:53 +02:00
|
|
|
|
|
|
|
except:
|
|
|
|
title = item.strip()
|
|
|
|
|
2021-08-16 06:27:44 +02:00
|
|
|
if totalMem and usedMem:
|
|
|
|
memUsage = int(int(usedMem) / int(totalMem) * 100)
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
str_format = self.parameter(
|
|
|
|
"format", "{name}: {temp}°C {mem_used}/{mem_total} MiB"
|
|
|
|
)
|
2020-04-24 16:15:00 +02:00
|
|
|
self.__utilization = str_format.format(
|
2020-05-03 11:15:52 +02:00
|
|
|
name=name,
|
|
|
|
temp=temp,
|
|
|
|
mem_used=usedMem,
|
|
|
|
mem_total=totalMem,
|
|
|
|
clock_gpu=clockGpu,
|
|
|
|
clock_mem=clockMem,
|
|
|
|
fanspeed=fanspeed,
|
2021-07-24 23:18:04 +02:00
|
|
|
gpu_usage_pct=gpuUsagePct,
|
2021-08-16 06:27:44 +02:00
|
|
|
mem_io_pct=memIoPct,
|
|
|
|
mem_usage_pct=memUsage,
|
2020-05-03 11:15:52 +02:00
|
|
|
)
|
|
|
|
|
2020-04-24 16:15:00 +02:00
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|