-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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).
- Loading branch information
1 parent
4f4a828
commit a9616a0
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |