-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_throttled
executable file
·55 lines (48 loc) · 1.84 KB
/
get_throttled
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
#!/usr/bin/env python3
# See: https://gist.github.com/dasl-/f875535b2b71bcab0f1215a1b39b52cf
import pprint
import subprocess
throttled_output = subprocess.check_output(('vcgencmd', 'get_throttled')).decode("utf-8")
throttled_output = throttled_output.strip()
if throttled_output[-3:] == '0x0':
throttled_output = '0x00000'
throttled_output = throttled_output[-5:]
throttling_map = {
'under_voltage_detected': 0,
'arm_frequency_capped': 0,
'currently_throttled': 0,
'soft_temperature_limit_active': 0,
'under_voltage_has_occurred': 0,
'arm_frequency_capping_has_occurred': 0,
'throttling_has_occurred': 0,
'soft_temperature_limit_has_occurred': 0,
}
index_offset = 16
for i in range(len(throttled_output)):
char = throttled_output[i]
# Ex:
# '1' -> '0001'
# 'd' or 'D' -> '1101'
binary = bin(int(char, 16))[2:].zfill(4)
for j in range(len(binary)):
if binary[j] == '1':
bit_index = index_offset + len(binary) - j - 1
if bit_index == 0:
throttling_map['under_voltage_detected'] = 1
elif bit_index == 1:
throttling_map['arm_frequency_capped'] = 1
elif bit_index == 2:
throttling_map['currently_throttled'] = 1
elif bit_index == 3:
throttling_map['soft_temperature_limit_active'] = 1
elif bit_index == 16:
throttling_map['under_voltage_has_occurred'] = 1
elif bit_index == 17:
throttling_map['arm_frequency_capping_has_occurred'] = 1
elif bit_index == 18:
throttling_map['throttling_has_occurred'] = 1
elif bit_index == 19:
throttling_map['soft_temperature_limit_has_occurred'] = 1
index_offset -= 4
pp = pprint.PrettyPrinter(sort_dicts=False)
pp.pprint(throttling_map)