-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGPU_Check.py
More file actions
145 lines (128 loc) · 4.42 KB
/
GPU_Check.py
File metadata and controls
145 lines (128 loc) · 4.42 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# import GPUtil
# def is_gpu_present():
# gpus = GPUtil.getGPUs()
# if gpus:
# print(f"GPU Detected: {gpus[0].name}")
# return True
# else:
# print("No GPU detected.")
# return False
# # Example usage
# if is_gpu_present():
# print("System has a GPU.")
# else:
# print("System does not have a GPU.")
# #SysMonitor
# import psutil
# import GPUtil
# import platform
# import time
# import threading
# # System Info Collector
# def get_size(bytes):
# for unit in ['', 'K', 'M', 'G', 'T', 'P']:
# if bytes < 1024:
# return f"{bytes:.2f}{unit}B"
# bytes /= 1024
# def get_system_info():
# try:
# info = {}
# info['platform'] = platform.system()
# info['platform-version'] = platform.version()
# info['processor'] = platform.processor()
# info['ram'] = get_size(psutil.virtual_memory().total)
# info['cpu_usage'] = psutil.cpu_percent(interval=1) # Add interval for accurate reading
# info['memory_usage'] = psutil.virtual_memory().percent
# info['disk_usage'] = psutil.disk_usage('/').percent
# gpus = GPUtil.getGPUs()
# if gpus:
# info['gpu'] = gpus[0].name
# info['gpu_load'] = gpus[0].load * 100
# else:
# info['gpu'] = "No GPU detected"
# info['gpu_load'] = 0
# return info
# except Exception as e:
# print(f"Error fetching system info: {e}")
# return None
# # Real-Time Display of System Parameters
# def display_real_time_info():
# while True:
# info = get_system_info()
# if info:
# print("\n--- Real-Time System Information ---")
# print(f"Platform: {info['platform']} {info['platform-version']}")
# print(f"Processor: {info['processor']}")
# print(f"Total RAM: {info['ram']}")
# print(f"CPU Usage: {info['cpu_usage']}%")
# print(f"Memory Usage: {info['memory_usage']}%")
# print(f"Disk Usage: {info['disk_usage']}%")
# print(f"GPU: {info['gpu']}")
# print(f"GPU Load: {info['gpu_load']}%")
# else:
# print("Error: Unable to fetch system information.")
# time.sleep(5) # Update every 5 seconds
# # Start Real-Time Display in a Separate Thread
# real_time_thread = threading.Thread(target=display_real_time_info, daemon=True)
# real_time_thread.start()
# # Main Execution
# print("System monitoring started. Press Ctrl+C to stop.")
# while True:
# # time.sleep(1)
# import psutil
# import GPUtil
# import platform
# def check_cpu():
# try:
# cpu_usage = psutil.cpu_percent(interval=1)
# print(f"CPU Usage: {cpu_usage}%")
# return True
# except Exception as e:
# print(f"Error checking CPU: {e}")
# return False
# def check_ram():
# try:
# memory = psutil.virtual_memory()
# print(f"Total RAM: {memory.total / (1024 ** 3):.2f} GB")
# print(f"RAM Usage: {memory.percent}%")
# return True
# except Exception as e:
# print(f"Error checking RAM: {e}")
# return False
# def check_disk():
# try:
# disk = psutil.disk_usage('/')
# print(f"Total Disk Space: {disk.total / (1024 ** 3):.2f} GB")
# print(f"Disk Usage: {disk.percent}%")
# return True
# except Exception as e:
# print(f"Error checking Disk: {e}")
# return False
# def check_gpu():
# try:
# gpus = GPUtil.getGPUs()
# if gpus:
# for gpu in gpus:
# print(f"GPU Detected: {gpu.name}")
# print(f"GPU Load: {gpu.load * 100:.2f}%")
# return True
# else:
# print("No GPU detected.")
# return False
# except Exception as e:
# print(f"Error checking GPU: {e}")
# return False
# def check_system_components():
# print("Checking system components...\n")
# cpu_status = check_cpu()
# ram_status = check_ram()
# disk_status = check_disk()
# gpu_status = check_gpu()
# print("\nSystem Component Availability:")
# print(f"CPU Available: {'Yes' if cpu_status else 'No'}")
# print(f"RAM Available: {'Yes' if ram_status else 'No'}")
# print(f"Disk Available: {'Yes' if disk_status else 'No'}")
# print(f"GPU Available: {'Yes' if gpu_status else 'No'}")
# # Example usage
# if __name__ == "__main__":
# check_system_components()