-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcpuinfo.py
More file actions
71 lines (50 loc) · 1.75 KB
/
cpuinfo.py
File metadata and controls
71 lines (50 loc) · 1.75 KB
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
#!/usr/bin/env python3
"""
formatter for cpuinfo plugin
"""
from util.util import SHOW_TEMPERATURE, convert_bytes
from plugins import cpuinfo
cpuinfo_class = cpuinfo.Cpuinfo()
def main():
"""
returns the data, but formatted.
"""
data = cpuinfo_class.get_data()
cpu_temperature = data["temperature"]
if SHOW_TEMPERATURE and cpu_temperature:
cpu_temperature = str(cpu_temperature)
cpu_temperature += " °C"
arch_model_temp_line = (
f"{cpu_temperature:>8} | CPU: {data['architecture']} {data['model']}"
)
else:
arch_model_temp_line = f"| CPU: {data['architecture']} {data['model']}"
cores_count_text = (
f"Cores: {data['cores']['physical']}C/{data['cores']['logical']}T"
if data["cores"]["physical"] != 0
else f"Cores: {data['cores']['logical']}"
)
# this fuckery can only happen on arm platforms since for some
# fucking reason some retard thought it would be a good idea for
# the cpuinfo file to be different on x86 and arm platforms
# fuck you.
cache_line = " | Cache: No data\n"
if data["cache"]["level"]:
cache_line = f" | Cache: {data['cache']['level']}"
if data["cache"]["size"]:
cache_line += f" {convert_bytes(data['cache']['size'])}\n"
output_text = [
f" --- /proc/cpuinfo {'-' * 47}\n",
f" Usage: {data['usage']:>5}% {arch_model_temp_line}" + "\n",
f" {cores_count_text} | Frequency: {data['frequency']:>7} MHz",
]
output_text[2] += cache_line
# output_text[2] = output_text[2] + cache_line
return "".join(output_text)
def end():
"""
clean up when the program exits
"""
cpuinfo_class.close_files()
if __name__ == "__main__":
main()