38 lines
979 B
Python
38 lines
979 B
Python
import gc
|
|
import time
|
|
|
|
|
|
def show_system_load():
|
|
"""Display basic system load information"""
|
|
gc.collect() # Run garbage collection first
|
|
|
|
mem_free = gc.mem_free()
|
|
mem_alloc = gc.mem_alloc()
|
|
mem_total = mem_free + mem_alloc
|
|
mem_usage = (mem_alloc / mem_total) * 100 if mem_total > 0 else 0
|
|
|
|
print('=== System Load ===')
|
|
print(f'Memory: {mem_alloc}/{mem_total} bytes ({mem_usage:.1f}%)')
|
|
print(f'Free: {mem_free} bytes')
|
|
print(f'Garbage: {gc.mem_free() - mem_free} bytes')
|
|
|
|
try:
|
|
# CPU load approximation (not available on all ports)
|
|
start_time = time.ticks_ms()
|
|
# Do some work to measure CPU
|
|
for i in range(1000):
|
|
_ = i * i
|
|
end_time = time.ticks_ms()
|
|
cpu_time = time.ticks_diff(end_time, start_time)
|
|
print(f'CPU load: ~{cpu_time}ms for 1000 iterations')
|
|
except (AttributeError, TypeError, ValueError) as e:
|
|
print(f'CPU measurement not available: {e}')
|
|
|
|
print('==================')
|
|
|
|
|
|
# Run periodically
|
|
while True:
|
|
show_system_load()
|
|
time.sleep(5)
|