|
1 | | -import platform |
2 | | - |
3 | 1 | import pygame |
4 | 2 | import sys |
5 | 3 | import psutil |
6 | 4 | import gpustat |
7 | | -from GPUtil import GPUtil |
| 5 | +import cpuinfo |
| 6 | + |
| 7 | + |
| 8 | +pygame.init() |
| 9 | +height = 700 |
| 10 | +width = 300 |
| 11 | +screen = pygame.display.set_mode((height, width)) |
| 12 | +clock = pygame.time.Clock() |
| 13 | +font = pygame.font.SysFont("Century Gothic", 16) |
8 | 14 |
|
9 | 15 |
|
10 | 16 | def fpsrun(): |
11 | 17 | fps = str(int(clock.get_fps())) |
12 | | - fps_text = font.render(fps, 1, pygame.Color("white")) |
| 18 | + fps_text = font.render("FPS: " + fps, 1, pygame.Color("white")) |
13 | 19 | return fps_text |
14 | 20 |
|
15 | 21 |
|
16 | | -class SystemInfo: |
17 | | - def __init__(self): |
18 | | - self.gpu_usage = None |
19 | | - self.gpu_name = None |
20 | | - self.cpu_usage = None |
21 | | - self.cpu_name = None |
22 | | - |
23 | | - |
24 | | -sys_info = SystemInfo() |
25 | | - |
26 | | -# Get GPU usage and name |
27 | | -gpu_percent = GPUtil.getGPUs()[0].load |
28 | | -sys_info.gpu_usage = gpu_percent |
29 | | -sys_info.gpu_name = GPUtil.getGPUs()[0].name |
30 | | - |
31 | | -# Get CPU usage and name |
32 | | -sys_info.cpu_usage = psutil.cpu_percent() |
33 | | -sys_info.cpu_name = platform.processor() |
34 | | - |
35 | | -# Print the information |
36 | | -print("GPU: ", sys_info.gpu_name, " Usage: ", sys_info.gpu_usage, "%") |
37 | | -print("CPU: ", sys_info.cpu_name, " Usage: ", sys_info.cpu_usage, "%") |
38 | | - |
39 | | - |
40 | 22 | def get_cpu_usage(): |
| 23 | + cpu_info = cpuinfo.get_cpu_info()['brand_raw'] |
41 | 24 | cpu_usage = psutil.cpu_percent() |
42 | | - return str(cpu_usage) + "%" |
43 | 25 |
|
| 26 | + if 'AMD' in cpu_info: |
| 27 | + color = pygame.Color("red") |
| 28 | + elif 'Intel' in cpu_info: |
| 29 | + color = pygame.Color("blue") |
| 30 | + else: |
| 31 | + color = pygame.Color("white") |
| 32 | + |
| 33 | + cpu_usage_text = font.render("CPU Usage: " + str(cpu_usage) + "%", 1, color) |
| 34 | + return cpu_usage_text |
44 | 35 |
|
45 | 36 | def get_cpu_name(): |
46 | | - # Get CPU information |
47 | | - cpu_percent = psutil.cpu_percent() |
48 | | - cpu_name = psutil.cpu_freq().name |
49 | | - logical_cpus = psutil.cpu_count() |
50 | | - physical_cpus = psutil.cpu_count(logical=False) |
| 37 | + cpu_name = cpuinfo.get_cpu_info()['brand_raw'] |
| 38 | + if 'AMD' in cpu_name: |
| 39 | + cpu_name_text = font.render("CPU Name: " + cpu_name, 1, pygame.Color("red")) |
| 40 | + elif 'Intel' in cpu_name: |
| 41 | + cpu_name_text = font.render("CPU Name: " + cpu_name, 1, pygame.Color("blue")) |
| 42 | + else: |
| 43 | + cpu_name_text = font.render("CPU Name: " + cpu_name, 1, pygame.Color("white")) |
| 44 | + return cpu_name_text |
51 | 45 |
|
52 | 46 |
|
53 | 47 | def get_gpu_usage(): |
54 | 48 | gpu_stats = gpustat.GPUStatCollection.new_query() |
55 | 49 | gpu_usage = gpu_stats.gpus[0].utilization |
56 | | - return str(gpu_usage) + "%" |
| 50 | + gpu_usage_text = font.render("GPU Usage: " + str(gpu_usage) + "%", 1, pygame.Color("green")) |
| 51 | + return gpu_usage_text |
57 | 52 |
|
58 | 53 |
|
59 | | -pygame.init() |
60 | | -height = 700 |
61 | | -width = 150 |
62 | | -screen = pygame.display.set_mode((height, width)) |
63 | | -# screen = pygame.display.set_mode((height,width),pygame.RESIZABLE) |
64 | | -clock = pygame.time.Clock() |
65 | | -font = pygame.font.SysFont("Century Gothic", 16) |
| 54 | +def get_gpu_name(): |
| 55 | + gpu_stats = gpustat.GPUStatCollection.new_query() |
| 56 | + gpu_name = gpu_stats.gpus[0].name |
| 57 | + gpu_name_text = font.render("GPU Name: " + gpu_name, 1, pygame.Color("green")) |
| 58 | + return gpu_name_text |
| 59 | + |
66 | 60 |
|
67 | | -gpu_usage_text = font.render(get_gpu_usage(), 1, pygame.Color("white")) |
68 | | -screen.blit(gpu_usage_text, (60, 50)) |
69 | | -cpu_usage_text = font.render(get_cpu_usage(), 1, pygame.Color("white")) |
70 | | -screen.blit(cpu_usage_text, (60, 100)) |
71 | | - |
72 | | -i = 0 |
73 | | -while i <= 10: |
74 | | - screen.fill((0, 0, 0)) |
75 | | - gpu_usage_text = font.render("GPU: " + sys_info.gpu_name + " Usage: " + str(sys_info.gpu_usage) + "%", True, (255, 255, 255)) |
76 | | - cpu_usage_text = font.render("CPU: " + sys_info.cpu_name + " Usage: " + str(sys_info.cpu_usage) + "%", True, (255, 255, 255)) |
77 | | - screen.blit(fpsrun(), (60, 50)) |
78 | | - screen.blit(gpu_usage_text, (60, 80)) |
79 | | - screen.blit(cpu_usage_text, (60, 110)) |
| 61 | +def get_ram_info(): |
| 62 | + ram_info = psutil.virtual_memory() |
| 63 | + return "Total RAM: " + str(ram_info.total // (1024**2)) + "MB" |
| 64 | + |
| 65 | + |
| 66 | +def get_ram_usage(): |
| 67 | + ram_usage = psutil.virtual_memory().percent |
| 68 | + return str(ram_usage) + "%" |
| 69 | + |
| 70 | + |
| 71 | +while True: |
80 | 72 | for event in pygame.event.get(): |
81 | 73 | if event.type == pygame.QUIT: |
| 74 | + pygame.quit() |
82 | 75 | sys.exit() |
83 | | - clock.tick(60) |
| 76 | + screen.fill(pygame.Color("black")) |
| 77 | + screen.blit(fpsrun(), (20, 20)) |
| 78 | + screen.blit(get_cpu_name(), (20, 50)) |
| 79 | + screen.blit(get_cpu_usage(), (20, 70)) |
| 80 | + screen.blit(get_gpu_name(), (20, 100)) |
| 81 | + screen.blit(get_gpu_usage(), (20, 120)) |
| 82 | + screen.blit(font.render("RAM Info: " + get_ram_info(), 1, pygame.Color("orange")), (20, 150)) |
| 83 | + screen.blit(font.render("RAM Usage: " + get_ram_usage(), 1, pygame.Color("orange")), (20, 170)) |
| 84 | + |
84 | 85 | pygame.display.update() |
| 86 | + clock.tick(60) |
0 commit comments