feat: replace logging with custom log_all function and truncate benchmark log on start
This commit is contained in:
+5
-9
@@ -1,18 +1,14 @@
|
||||
import psutil
|
||||
import time
|
||||
|
||||
LOG_FILE = 'usage.log'
|
||||
INTERVAL = 5 # seconds
|
||||
|
||||
try:
|
||||
with open(LOG_FILE, 'a') as log:
|
||||
with open('usage.log', 'a') as log_file:
|
||||
while True:
|
||||
cpu_percent = psutil.cpu_percent(interval=1)
|
||||
mem = psutil.virtual_memory()
|
||||
log_entry = f"CPU: {cpu_percent}%, Memory: {mem.percent}%\n"
|
||||
log.write(log_entry)
|
||||
log.flush()
|
||||
print(log_entry.strip())
|
||||
time.sleep(INTERVAL - 1)
|
||||
log_file.write(log_entry)
|
||||
log_file.flush()
|
||||
time.sleep(4)
|
||||
except KeyboardInterrupt:
|
||||
print('Monitoring stopped by user.')
|
||||
print("Monitoring stopped by user.")
|
||||
|
||||
Reference in New Issue
Block a user