aboutsummaryrefslogtreecommitdiffstats
path: root/deckit
diff options
context:
space:
mode:
Diffstat (limited to 'deckit')
-rw-r--r--deckit/modules/stats.py34
1 files changed, 33 insertions, 1 deletions
diff --git a/deckit/modules/stats.py b/deckit/modules/stats.py
index c190ec8..a764246 100644
--- a/deckit/modules/stats.py
+++ b/deckit/modules/stats.py
@@ -21,7 +21,9 @@ VRAM in use comes from the DRM fdinfo scan, as quickshell's perf panel does.
"""
import re
+import shlex
import socket
+import subprocess
import time
from pathlib import Path
@@ -89,12 +91,40 @@ def _battery(hw):
return None
+def _cpu_name(cpuinfo):
+ """'AMD Ryzen 7 9700X 8-Core Processor' -> 'AMD Ryzen 7 9700X'."""
+ for line in cpuinfo.splitlines():
+ if line.startswith("model name"):
+ name = re.sub(r"\((R|TM)\)|\bCPU\b|@.*|\d+-Core|Processor", "", line.partition(":")[2])
+ return " ".join(name.split()) or None
+ return None
+
+
+def _gpu_name(lspci):
+ """lspci -mm's line -> 'Intel Arc B580': the vendor's first word, then the
+ marketing name in brackets, else the whole device name."""
+ try:
+ f = shlex.split(lspci)
+ except ValueError:
+ return None
+ if len(f) < 4:
+ return None
+ m = re.search(r"\[(.+?)\]", f[3])
+ return f"{f[2].split()[0]} {m[1] if m else f[3]}"
+
+
def _gpu(hw):
if hw.get("gpu", "auto") == "none":
return None
for name in Path("/sys/class/hwmon").glob("hwmon*/name"):
if _read(name) == "xe":
- return {"hwmon": name.parent, "name": "Intel Arc"}
+ slot = (name.parent / "device").resolve().name
+ try:
+ out = subprocess.run(["lspci", "-mm", "-s", slot], capture_output=True,
+ text=True, timeout=2).stdout
+ except (OSError, subprocess.TimeoutExpired):
+ out = ""
+ return {"hwmon": name.parent, "name": _gpu_name(out) or "GPU"}
return None
@@ -113,6 +143,7 @@ def make(cfg: dict) -> Module:
cpu_sensor = _cpu_sensor(hw)
battery = _battery(hw)
gpu = _gpu(hw)
+ cpu_name = _cpu_name(_read("/proc/cpuinfo")) or "CPU"
gpu_total = _parse_bytes(hw.get("gpu_mem_total", "")) if gpu else None
prev = {"cpu": None, "net": None, "t": None, "gpu_t": 0, "gpu_v": None}
@@ -167,6 +198,7 @@ def make(cfg: dict) -> Module:
"host": socket.gethostname(),
"uptime": int(float(_read("/proc/uptime", "0").split()[0])),
"cpu": cpu_percent(),
+ "cpuName": cpu_name,
"cpuTemp": round(int(t) / 1000) if t else None,
"memUsed": mem["MemTotal"] - mem["MemAvailable"],
"memTotal": mem["MemTotal"],