-
Notifications
You must be signed in to change notification settings - Fork 0
/
GPU Watch.py
92 lines (73 loc) · 2.76 KB
/
GPU Watch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import subprocess
import time
import matplotlib.pyplot as plt
from matplotlib.widgets import Button
# ADB 커맨드 함수
def run_adb_command(command):
result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
return result.stdout, result.stderr
# 정지 버튼 클릭 시
def stop_update(event):
global running
running = False
plt.close()
# 일시 정지 버튼 클릭 시
def pause_update(event):
global paused
paused = not paused
if paused:
btn_pause.label.set_text('Resume')
else:
btn_pause.label.set_text('Pause')
# 그래프 초기화
plt.ion() # 인터랙티브 모드 활성화
fig, ax = plt.subplots(num = 'GPU Watch') #창이름
temp_values = []
clock_values = []
time_values = []
running = True
paused = False
# 정지 버튼
ax_stop = plt.axes([0.05, 0.90, 0.1, 0.075])
btn_stop = Button(ax_stop, 'Exit')
btn_stop.on_clicked(stop_update)
# 일시 정지 버튼
ax_pause = plt.axes([0.20, 0.90, 0.1, 0.075])
btn_pause = Button(ax_pause, 'Pause')
btn_pause.on_clicked(pause_update)
##메인 코드
try:
while running:
if not paused:
command = 'adb shell su -c "cat /sys/class/kgsl/kgsl-3d0/gpuclk"'
stdout, stderr = run_adb_command(command)
if stderr:
print("Error:", stderr)
else:
gpu_clock = float(stdout.strip()) / 1000000 #MHz로 변환
clock_values.append(gpu_clock)
command = f'adb shell su -c "cat /sys/class/kgsl/kgsl-3d0/temp"'
stdout, stderr = run_adb_command(command)
if stderr:
print("Error:", stderr)
else:
gpu_temp = float(stdout.strip()) / 1000 # ℃로 변환
temp_values.append(gpu_temp)
time_values.append(len(time_values) + 1)
# 그래프 업데이트
ax.clear()
ax.plot(time_values, temp_values, label='GPU T-die Temp (℃)')
ax.plot(time_values, clock_values, label='GPU Clock (MHz)')
ax.set_xlabel('Time (seconds)')
ax.set_ylabel('Value')
ax.legend()
# 수치 출력
if len(temp_values) > 0:
ax.text(0.02, 0.95, f'GPU Temp: {temp_values[-1]:.2f} ℃', transform=ax.transAxes, fontsize=12, va='top')
if len(clock_values) > 0:
ax.text(0.02, 0.85, f'GPU Clock: {clock_values[-1]:.2f} MHz', transform=ax.transAxes, fontsize=12, va='top')
plt.pause(1) # 1초마다 업데이트
except KeyboardInterrupt:
print("그래프 표시를 종료합니다.")
plt.ioff()
plt.show()