-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcpu_explorer.py
More file actions
77 lines (61 loc) · 2.77 KB
/
Copy pathcpu_explorer.py
File metadata and controls
77 lines (61 loc) · 2.77 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
72
73
74
75
76
77
import subprocess
CMD_CPU_MODEL = r"grep -m 1 'model name' /proc/cpuinfo | cut -d ':' -f2"
CMD_GET_CORES = r"lscpu | grep 'Core(s) per socket: ' | cut -d ':' -f2"
CMD_GET_THREADS = r"lscpu | grep '^CPU(s): ' | cut -d ':' -f2"
CMD_CPU_MIN_FREQ = r"lscpu | grep 'CPU min MHz' | cut -d ':' -f2"
CMD_CPU_MAX_FREQ = r"lscpu | grep 'CPU max MHz' | cut -d ':' -f2"
CMD_CPU_CUR_FREQ = r"dmidecode -t processor | grep 'Current Speed' | cut -d ':' -f2"
CMD_MANUF = r'dmidecode -t 2 | grep Manufacturer: | cut -d ":" -f2'
CMD_MODEL = r'dmidecode -t 2 | grep "Product Name:" | cut -d ":" -f2'
def get_cpu_model():
output = subprocess.run(CMD_CPU_MODEL,
shell=True,
stdout=subprocess.PIPE)
return output.stdout.decode().rstrip().strip()
def get_cores():
output = subprocess.run(CMD_GET_CORES,
shell=True,
stdout=subprocess.PIPE)
return output.stdout.decode().rstrip().strip()
def get_threads():
output = subprocess.run(CMD_GET_THREADS,
shell=True,
stdout=subprocess.PIPE)
return output.stdout.decode().rstrip().strip()
def get_frequency():
min_freq = subprocess.run(CMD_CPU_MIN_FREQ,
shell=True,
stdout=subprocess.PIPE)
min_freq = min_freq.stdout.decode().strip().rstrip()
max_freq = subprocess.run(CMD_CPU_MAX_FREQ,
shell=True,
stdout=subprocess.PIPE)
max_freq = max_freq.stdout.decode().strip().rstrip()
cur_freq = subprocess.run(CMD_CPU_CUR_FREQ,
shell=True,
stdout=subprocess.PIPE)
cur_freq = cur_freq.stdout.decode().strip().rstrip()
output = [cur_freq, max_freq, min_freq]
# output = [float(f) for f in output]
# output = [f"{f/1000:.2f}GHz" if f>1000 else f"{f:.2f}MHz" for f in output]
return output
def get_mobo_manufacturer():
output = subprocess.run(CMD_MANUF,
shell=True,
stdout=subprocess.PIPE)
return output.stdout.decode().rstrip().strip()
def get_mobo_model():
output = subprocess.run(CMD_MODEL,
shell=True,
stdout=subprocess.PIPE)
return output.stdout.decode().rstrip().strip()
def print_cpu_info():
freq = get_frequency()
output = ""
output += f"Model: {get_cpu_model()}\n"
output += f"Topology: {get_cores()} cores/{get_threads()} threads\n"
output += f"Frequency: {freq[0]} (min. {freq[2]}, max. {freq[1]})\n"
output += f"Motherboard model: {get_mobo_manufacturer()} {get_mobo_model()}\n"
return output
if __name__ == "__main__":
print(print_cpu_info())