From 045e6d3dc71bbae453093a1b32ca8b73065d47e6 Mon Sep 17 00:00:00 2001 From: Dom Cobley Date: Tue, 12 Dec 2023 15:24:30 +0000 Subject: [PATCH] gpu_usage: Initial import of script to read gpu usage debugfs info Shows gpu usage as reported by the v3d driver Works on pi4 and pi5 (earlier models don't expose this info) This provides a little more detail than the GPU taskbar plugin (which just reports the maximum of the different fields). --- scripts/gpu_usage.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 scripts/gpu_usage.py diff --git a/scripts/gpu_usage.py b/scripts/gpu_usage.py new file mode 100755 index 0000000..2057112 --- /dev/null +++ b/scripts/gpu_usage.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 + +import time +import operator + +def get_stats(): + try: + with open('/sys/kernel/debug/dri/0/gpu_usage') as f: + lines = f.readlines() + except: + print("gpu_usage is not supported on this device") + exit(1) + queue = {} + for i in lines: + s = i.replace("'", "").replace('"', "").strip().rstrip(';').split(';') + queues = ["bin", "render", "tfu", "csd", "cache_clean"] + if s[0] == 'timestamp': + timestamp = int(s[1]) + elif s[0] == 'QUEUE': + names = s[1:] + elif s[0].replace("v3d_", "") in queues: + queue[s[0]] = list(map(int, s[1:])) + else: + print(s) + assert(False) + return timestamp, names, queue + +last_timestamp = None + +while True: + timestamp, names, queue = get_stats() + if last_timestamp is not None: + q = {} + t = timestamp - last_timestamp + for k,v in queue.items(): + q[k] = list(map(operator.sub, queue[k], last_queue[k])) + s = [] + for k,v in q.items(): + s.append(f"{k}: jobs:{v[0]:3}{100.0*v[1]/t:6.1f}%") + print(", ".join(s)) + last_timestamp = timestamp + last_queue = queue + time.sleep(1)