Skip to content

Commit

Permalink
gpu_usage: Initial import of script to read gpu usage debugfs info
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
popcornmix committed Dec 12, 2023
1 parent 4f4a828 commit a9616a0
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions scripts/gpu_usage.py
Original file line number Diff line number Diff line change
@@ -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_uage 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)

0 comments on commit a9616a0

Please sign in to comment.