#!/usr/bin/env python3 """ Check and display system resource limits and current usage """ import os import subprocess import resource import psutil def check_file_descriptors(): """Check file descriptor limits and usage""" print("🔍 FILE DESCRIPTOR LIMITS") print("=" * 40) # Get current limits soft_limit, hard_limit = resource.getrlimit(resource.RLIMIT_NOFILE) print(f"Current soft limit: {soft_limit:,}") print(f"Current hard limit: {hard_limit:,}") # Get current usage pid = os.getpid() try: result = subprocess.run(['lsof', '-p', str(pid)], capture_output=True, text=True) open_files = len(result.stdout.strip().split('\n')) - 1 print(f"Current open files: {open_files}") print(f"Usage: {open_files/soft_limit*100:.1f}% of soft limit") except: print("Could not determine current usage") print() # Recommendations if soft_limit < 10000: print("âš ī¸ RECOMMENDATION: Your soft limit is quite low") print(" Consider increasing it with: ulimit -n 65536") elif soft_limit < 65536: print("â„šī¸ RECOMMENDATION: Consider increasing soft limit for heavy processing") print(" Command: ulimit -n 65536") else: print("✅ File descriptor limits look good") print() def check_memory(): """Check memory usage""" print("🧠 MEMORY USAGE") print("=" * 40) memory = psutil.virtual_memory() swap = psutil.swap_memory() print(f"RAM: {memory.percent:.1f}% used ({memory.used/1024**3:.1f}GB / {memory.total/1024**3:.1f}GB)") print(f"Swap: {swap.percent:.1f}% used ({swap.used/1024**3:.1f}GB / {swap.total/1024**3:.1f}GB)") if memory.percent > 80: print("âš ī¸ High RAM usage detected") if swap.percent > 50: print("âš ī¸ High swap usage detected") print() def check_processes(): """Check running processes""" print("🔄 PROCESS INFORMATION") print("=" * 40) # CPU info print(f"CPU cores: {os.cpu_count()}") print(f"CPU usage: {psutil.cpu_percent(interval=1):.1f}%") # Load average try: load1, load5, load15 = os.getloadavg() print(f"Load average: {load1:.2f}, {load5:.2f}, {load15:.2f}") except: print("Load average: unavailable") print() def recommend_settings(): """Recommend optimal settings""" print("đŸŽ¯ RECOMMENDED SETTINGS") print("=" * 40) cpu_count = os.cpu_count() memory_gb = psutil.virtual_memory().total / (1024**3) print(f"For your system ({cpu_count} cores, {memory_gb:.1f}GB RAM):") print() # Layout workers if memory_gb < 16: layout_workers = min(2, cpu_count // 2) print(f"--layout-workers {layout_workers} (conservative for {memory_gb:.1f}GB RAM)") elif memory_gb < 32: layout_workers = min(4, cpu_count // 2) print(f"--layout-workers {layout_workers} (balanced for {memory_gb:.1f}GB RAM)") else: layout_workers = min(6, cpu_count // 2) print(f"--layout-workers {layout_workers} (aggressive for {memory_gb:.1f}GB RAM)") # Local workers local_workers = max(1, cpu_count - 2) print(f"--local-workers {local_workers} (CPU cores - 2)") print() print("Full command suggestion:") print("python cli.py --all --hybrid --split-simple --refinement-mode \\") print(" --inlier-threshold 0.15 --inlier-ratio-threshold 0.2 \\") print(" --fallback-one-at-a-time --enable-cost-tracking --cost-report \\") print(f" --parallel-layouts --layout-workers {layout_workers} --local-workers {local_workers}") print() def main(): print("🔧 SYSTEM RESOURCE CHECK") print("=" * 50) print() check_file_descriptors() check_memory() check_processes() recommend_settings() print("💡 TROUBLESHOOTING TIPS:") print("- If you get 'Too many open files': restart terminal and run 'ulimit -n 65536'") print("- If memory usage is high: reduce --layout-workers") print("- If processing is slow: check if swap usage is very high") print("- Monitor with: Activity Monitor or 'top' command") if __name__ == "__main__": main()