Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gpu_usage: Initial import of script to read gpu usage debugfs info #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_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)