-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
188 lines (166 loc) · 7.73 KB
/
Copy pathmain.py
File metadata and controls
188 lines (166 loc) · 7.73 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import time
import psutil
import os
import threading
import platform
import socket
import sys
iterations = 420000
current_iteration = 0
stop_loading = False
commands = {"show_all": True}
def parse_args():
global commands
args = sys.argv[1:]
for arg in args:
if arg.startswith("--omit="):
omit_sections = arg.split("=")[1].split(",")
for section in omit_sections:
commands[section.strip()] = False
if arg.startswith("--iterations="):
global iterations
iterations = int(arg.split("=")[1])
if "show_all" in commands:
commands = {key: False for key in commands}
commands["show_all"] = True
def simulate_hash_work():
time.sleep(0.000001) # Simulate hash calculation time
def safe_call(func, default="Permission Denied"):
try:
return func()
except (PermissionError, RuntimeError, AttributeError):
return default
def print_progress_bar(iteration, total, length=40):
percent = ("{0:.1f}").format(100 * (iteration / float(total)))
filled_length = int(length * iteration // total)
bar = '█' * filled_length + '-' * (length - filled_length)
print(f'\rProgress: |{bar}| {percent}% Complete', end='\r')
if iteration == total:
print()
def hash_rate_test(iterations):
global current_iteration
print(f"Running hash rate test with {iterations} iterations...please wait")
start_time = time.time()
memory_before = psutil.Process(os.getpid()).memory_info().rss / 1024 / 1024 # in MB
hash_times = []
for i in range(iterations):
start_hash_time = time.time()
simulate_hash_work()
end_hash_time = time.time()
hash_times.append(end_hash_time - start_hash_time)
current_iteration = i + 1
end_time = time.time()
memory_after = psutil.Process(os.getpid()).memory_info().rss / 1024 / 1024 # in MB
total_time_taken = end_time - start_time
hash_rate = iterations / total_time_taken
average_time_per_hash = total_time_taken / iterations
min_time_per_hash = min(hash_times)
max_time_per_hash = max(hash_times)
average_hash_time = sum(hash_times) / len(hash_times)
# Display collected information
if commands.get("time", True):
print(f"\nTotal time taken: {total_time_taken:.6f} seconds")
print(f"Hash rate: {hash_rate:.2f} hashes/second")
print(f"Average time per hash: {average_time_per_hash:.10f} seconds")
print(f"Min time for a single hash: {min_time_per_hash:.10f} seconds")
print(f"Max time for a single hash: {max_time_per_hash:.10f} seconds")
print(f"Average hash time: {average_hash_time:.10f} seconds")
# Additional information with error handling
cpu_usage = safe_call(lambda: f"{psutil.cpu_percent(interval=1)}%")
disk_usage = safe_call(lambda: f"{psutil.disk_usage('/').percent}% used, {psutil.disk_usage('/').free / 1024 / 1024:.2f} MB free")
network_io = safe_call(lambda: f"Sent = {psutil.net_io_counters().bytes_sent / 1024 / 1024:.2f} MB, Received = {psutil.net_io_counters().bytes_recv / 1024 / 1024:.2f} MB")
swap_memory = safe_call(lambda: f"{psutil.swap_memory().percent}% used, {psutil.swap_memory().free / 1024 / 1024:.2f} MB free")
cpu_temp = safe_call(lambda: psutil.sensors_temperatures()['coretemp'][0].current if 'coretemp' in psutil.sensors_temperatures() else 'N/A')
uptime = safe_call(lambda: time.time() - psutil.boot_time())
processes = len(psutil.pids())
load_avg = safe_call(lambda: os.getloadavg() if hasattr(os, 'getloadavg') else "Not available")
fs_type = safe_call(lambda: [partition.fstype for partition in psutil.disk_partitions()])
total_threads = sum(p.num_threads() for p in psutil.process_iter())
context_switches = safe_call(lambda: psutil.cpu_stats().ctx_switches)
interrupts = safe_call(lambda: psutil.cpu_stats().interrupts)
boot_time = safe_call(lambda: time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(psutil.boot_time())))
hostname = socket.gethostname()
# Display additional information
additional_info = [
f"CPU Usage: {cpu_usage}",
f"Disk Usage: {disk_usage}",
f"Network I/O: {network_io}",
f"Swap Memory: {swap_memory}",
f"CPU Temperature: {cpu_temp} °C",
f"System Uptime: {uptime if isinstance(uptime, str) else f'{uptime / 3600:.2f} hours'}",
f"Number of Processes: {processes}",
f"Load Average: {load_avg}",
f"Filesystem Type: {fs_type}",
f"Total Number of Threads: {total_threads}",
f"Context Switches: {context_switches}",
f"Interrupts: {interrupts}",
f"Boot Time: {boot_time}",
f"Hostname: {hostname}",
]
# Clear console
print("\n" * 10)
# Print final organized log
print(f"Running hash rate test with {iterations} iterations...")
print(f"Iterations: {iterations}")
print(f"Number of threads used: {os.cpu_count()}")
print(f"Start time: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))}")
print(f"End time: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(end_time))}")
if commands.get("time", True):
print(f"Total time taken: {total_time_taken:.6f} seconds")
print(f"Hash rate: {hash_rate:.2f} hashes/second")
print(f"Average time per hash: {average_time_per_hash:.10f} seconds")
print(f"Min time for a single hash: {min_time_per_hash:.10f} seconds")
print(f"Max time for a single hash: {max_time_per_hash:.10f} seconds")
print(f"Average hash time: {average_hash_time:.10f} seconds")
if commands.get("memory", True):
print("\nMemory Usage:")
print(f"Memory usage before test: {memory_before:.2f} MB")
print(f"Memory usage after test: {memory_after:.2f} MB")
if commands.get("system_info", True):
print("\nSystem Information:")
print(f"Platform: {platform.system()}")
print(f"Release: {platform.release()}")
print(f"Version: {platform.version()}")
print(f"Machine: {platform.machine()}")
print(f"Processor: {platform.processor()}")
print(f"CPU Count: {os.cpu_count()} logical cores")
print(f"Physical Memory: {psutil.virtual_memory().total / 1024 / 1024:.2f} MB")
print(f"Python version: {platform.python_version()}")
if commands.get("additional_info", True):
print("\nAdditional Information:")
for info in additional_info:
print(info)
def loading_animation():
frames = [
"[ ]", "[* ]", "[** ]", "[*** ]", "[**** ]", "[***** ]", "[******]",
"[ **** ]", "[ ** ]", "[ ]", "[ ** ]", "[ **** ]", "[******]",
"[***** ]", "[**** ]", "[*** ]", "[** ]", "[* ]", "[ ]",
"[ *]", "[ **]", "[ ***]", "[ ****]", "[ *****]", "[******]",
"[ **** ]", "[ ** ]", "[ ]", "[ ** ]", "[ **** ]", "[******]",
"[***** ]", "[**** ]", "[*** ]", "[** ]", "[* ]", "[ ]"
]
while not stop_loading:
for frame in frames:
if stop_loading:
break
print(frame, end="\r")
time.sleep(0.1)
def update_progress_bar():
while not stop_loading:
print_progress_bar(current_iteration, iterations)
time.sleep(0.2)
if __name__ == "__main__":
parse_args()
# Create and start loading thread
loading_thread = threading.Thread(target=loading_animation)
progress_thread = threading.Thread(target=update_progress_bar)
loading_thread.start()
progress_thread.start()
# Run the hash rate test while the loading animation is displayed
try:
hash_rate_test(iterations)
finally:
stop_loading = True
# Wait for loading and progress threads to complete
loading_thread.join()
progress_thread.join()