-
Notifications
You must be signed in to change notification settings - Fork 1
/
cpu_usage.py
59 lines (40 loc) · 1.23 KB
/
cpu_usage.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
import time
import os
import subprocess
try:
import psutil;
except:
print("psutil not installed");
print("Trying to install psutil")
import subprocess
subprocess.call(['pip', 'install', 'psutil' ])
finally:
import psutil;
num_cores = psutil.cpu_count(logical=True);
def cpu_usage():
cpu_percentage = psutil.cpu_percent();
return cpu_percentage
def per_cpu_usage():
per_cpu_percentage = psutil.cpu_percent(percpu=True);
for i in range(num_cores):
print(f"Core ID {i+1} usage is {per_cpu_percentage[i]}");
def per_cpu_freq():
per_cpu_frequency = psutil.cpu_freq();
print(f"Core ID Frequency is {per_cpu_frequency}")
'''
gpu_check = subprocess.check_output("lspci -k | grep -A 2 -E '(VGA|3D)'", shell=True)
gpu_check = gpu_check.decode("utf-8").strip().split("\n")
print(len(gpu_check))
for i in range(len(gpu_check)):
if "Kernel driver in use" in gpu_check[i]:
gpu_driver = gpu_check[i]
print(len(gpu_driver))
'''
#while True:
# cpu_percent = psutil.cpu_percent();
# per_cpu_percent = psutil.cpu_percent(percpu=True);
# for i in range(num_cores):
# print(f"Core ID {i+1} usage is {per_cpu_percent[i]}");
# print(f"CPU usage: {cpu_percent}%");
# time.sleep(1);
# print(f"\033[F" * (num_cores+2), end="")