-
Notifications
You must be signed in to change notification settings - Fork 0
/
py_monitor.sh
executable file
·54 lines (47 loc) · 1.34 KB
/
py_monitor.sh
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
#! /usr/bin/python3
def get_color(param):
switcher = {
0: '\033[1;31;31m',
1: '\033[1;31;32m',
2: '\033[1;31;33m',
3: '\033[1;31;35m',
}
return switcher.get(param, '\033[1;31;38m')
def draw_chart(cpuinfo_cur_freq, scaling_max_freq, color):
normalized_cur_freq = int(cpuinfo_cur_freq / scaling_max_freq * 100)
i = 0
while i < 100:
if normalized_cur_freq > int(i):
print('%s=' % color, end="")
else:
print(' ', end="")
i += 1
print('%s| %d Hz' % (color, cpuinfo_cur_freq))
return
import os
import time
cpu_scaling_max_freq = [0] * 99999999
cpu_cpuinfo_cur_freq = [0] * 99999999
cpu_count = int(os.popen("nproc").read())
cpu_cpuinfo_max_freq = [0] * cpu_count
i = 0
while i < cpu_count:
cpu_cpuinfo_max_freq[i] = int(os.popen("cat /sys/devices/system/cpu/cpufreq/policy"+str(i)+"/cpuinfo_max_freq").read())
i += 1
#i = 0
#while i < cpu_count:
# print(cpu_cpuinfo_max_freq[i])
# i += 1
i = 0
cpu_index = 0
while True:
# print(i)
cpu_cpuinfo_cur_freq[i] = int(os.popen("cat /sys/devices/system/cpu/cpufreq/policy"+str(cpu_index)+"/cpuinfo_cur_freq").read())
cpu_scaling_max_freq[i] = int(os.popen("cat /sys/devices/system/cpu/cpufreq/policy"+str(cpu_index)+"/scaling_max_freq").read())
#
# draw_chart(cpu_cpuinfo_cur_freq[i], cpu_scaling_max_freq[i], get_color(i))
#
i += 1
cpu_index += 1
if cpu_index == cpu_count:
cpu_index = 0