From 050841dd78b8ae043b6ad1e88684c9ce9808dcd6 Mon Sep 17 00:00:00 2001 From: sickprodigy Date: Thu, 6 Nov 2025 18:12:44 -0500 Subject: [PATCH] refactor: Remove MemoryMonitor class and related methods from memory_check.py --- Scripts/memory_check.py | 67 ----------------------------------------- 1 file changed, 67 deletions(-) diff --git a/Scripts/memory_check.py b/Scripts/memory_check.py index 8f7c826..8c384a1 100644 --- a/Scripts/memory_check.py +++ b/Scripts/memory_check.py @@ -1,72 +1,5 @@ import gc -class MemoryMonitor: - """Monitor and display Pico W memory usage.""" - - def __init__(self, interval=300): - """ - Initialize memory monitor. - - Args: - interval: Seconds between memory checks (default: 300 = 5 minutes) - """ - self.interval = interval - self.last_check = 0 - self.initial_free = None # Track initial free memory - - def should_run(self, current_time): - """Check if it's time to run memory check.""" - if current_time - self.last_check >= self.interval: - self.last_check = current_time - return True - return False - - def run(self): - """Check and display memory usage.""" - # Force garbage collection before checking - gc.collect() - - # Get memory stats - free = gc.mem_free() - allocated = gc.mem_alloc() - total = free + allocated - - # Store initial free memory on first run - if self.initial_free is None: - self.initial_free = free - - # Calculate memory leak (if any) - leaked = self.initial_free - free if self.initial_free else 0 - - # Print memory report - print("\n" + "="*50) - print("Pico W Memory (RAM):") - print("="*50) - print("Total: {:.1f} KB".format(total / 1024)) - print("Used: {:.1f} KB ({:.1f}%)".format( - allocated / 1024, - (allocated/total)*100 - )) - print("Free: {:.1f} KB ({:.1f}%)".format( - free / 1024, - (free/total)*100 - )) - - # Show memory leak warning if detected - if leaked > 5120: # More than 5 KB leaked - print("⚠️ Leaked: {:.1f} KB since startup".format(leaked / 1024)) - - print("="*50 + "\n") - - # Return memory info for other uses (like web server) - return { - 'total_kb': total / 1024, - 'used_kb': allocated / 1024, - 'free_kb': free / 1024, - 'usage_percent': (allocated/total)*100, - 'leaked_kb': leaked / 1024 if leaked > 0 else 0 - } - def check_memory_once(): """One-time memory check (for startup diagnostics).""" gc.collect()