Skip to content

Commit fcdebcc

Browse files
Merge pull request #6 from HoodedUnicorn/test
Test
2 parents ac7c16b + 9a4fb4f commit fcdebcc

File tree

2 files changed

+63
-66
lines changed

2 files changed

+63
-66
lines changed

FPS-Monitor.py

Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,86 @@
1-
import platform
2-
31
import pygame
42
import sys
53
import psutil
64
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)
814

915

1016
def fpsrun():
1117
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"))
1319
return fps_text
1420

1521

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-
4022
def get_cpu_usage():
23+
cpu_info = cpuinfo.get_cpu_info()['brand_raw']
4124
cpu_usage = psutil.cpu_percent()
42-
return str(cpu_usage) + "%"
4325

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
4435

4536
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
5145

5246

5347
def get_gpu_usage():
5448
gpu_stats = gpustat.GPUStatCollection.new_query()
5549
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
5752

5853

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+
6660

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:
8072
for event in pygame.event.get():
8173
if event.type == pygame.QUIT:
74+
pygame.quit()
8275
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+
8485
pygame.display.update()
86+
clock.tick(60)

README.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ This is a Python script that uses the Pygame library to display the current FPS
1111
* Pygame
1212
* Psutil
1313
* Gpustat
14+
* cpuinfo
15+
* sys
1416

1517
<h2>Installation :computer: </h2>
1618

1719

1820
<h3>Install via NPM packages :factory:</h3>
1921

20-
* Install the dependencies by running `pip install pygame psutil gpustat` in the command line. <br>
22+
* Install the dependencies by running `pip install pygame psutil gpustat cpuinfo` in the command line. <br>
2123
* Install package via NPM package manager `npm i @hoodedunicorn/python-fps-monitor` <br>
2224
* Run the script using `python FPS-Monitor.py`
2325

@@ -33,6 +35,7 @@ To exit the script, simply close the window or press the 'X' button in the top r
3335
<h2>Additional Features :space_invader: </h2>
3436

3537
You can customize the script to display additional information such as GPU memory usage or CPU temperature. You can also change the font, text color and background color of the window to match your personal preferences.
38+
<br>
3639

3740
<h2>Limitations :warning: </h2>
3841

@@ -42,12 +45,4 @@ This script is only compatible with NVidia GPUs. It will not work with other typ
4245

4346
This script is a useful tool for monitoring the performance of your system while running resource-intensive applications such as games or video editing software. It is easy to install and customize, making it a valuable addition to any developer or gamer's toolbox.
4447

45-
<h2>Versions :pizza:</h2>
46-
47-
<h3>FPS Monitor version 1.0.1</h3>
48-
49-
![fpsmon101](https://user-images.githubusercontent.com/68126304/215294225-68794013-7587-4482-b29c-59bf37cabce5.PNG)
50-
51-
<h3>FPS Monitor version 1.0.0</h3>
52-
53-
![fpsmon100](https://user-images.githubusercontent.com/68126304/215294191-982f19c5-c9e5-441d-8929-cf3a4285fc5f.PNG)
48+
[<h2>Versions :pizza:</h2>](Versions.md)

0 commit comments

Comments
 (0)