← back to Exo
better bench system info
f9f76129a13cae64da260641db931d7954eb9c16 · 2024-12-12 11:34:37 +0000 · Alex Cheema
Files touched
Diff
commit f9f76129a13cae64da260641db931d7954eb9c16
Author: Alex Cheema <alexcheema123@gmail.com>
Date: Thu Dec 12 11:34:37 2024 +0000
better bench system info
---
.github/bench.py | 124 ++++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 101 insertions(+), 23 deletions(-)
diff --git a/.github/bench.py b/.github/bench.py
index 965180bf..b4c5df33 100644
--- a/.github/bench.py
+++ b/.github/bench.py
@@ -17,15 +17,15 @@ def check_system_state():
# Add macOS-specific checks
try:
- # Check powermetrics
+ # Check powermetrics with sudo
try:
- power_metrics = subprocess.run(['powermetrics', '-n', '1', '-i', '1000', '--show-process-energy'],
- capture_output=True, text=True)
- except:
- # Try with sudo if direct access fails
- power_metrics = subprocess.run(['sudo', 'powermetrics', '-n', '1', '-i', '1000', '--show-process-energy'],
- capture_output=True, text=True)
- print("\nPower Metrics:", power_metrics.stdout, flush=True)
+ power_metrics = subprocess.run(
+ ['sudo', 'powermetrics', '-n', '1', '-i', '1000', '--samplers', 'cpu_power'],
+ capture_output=True, text=True
+ )
+ print("\nPower Metrics:", power_metrics.stdout, flush=True)
+ except Exception as e:
+ print(f"Error getting power metrics: {e}", flush=True)
# Check thermal state
thermal_state = subprocess.run(['pmset', '-g', 'therm'], capture_output=True, text=True)
@@ -35,9 +35,17 @@ def check_system_state():
arch = subprocess.run(['arch'], capture_output=True, text=True)
print("\nArchitecture:", arch.stdout, flush=True)
- # Check MLX compilation mode
- import mlx.core as mx
- print("\nMLX Build Info:", mx.build_info(), flush=True)
+ # Check MLX compilation mode - only if mlx is available
+ try:
+ import mlx.core as mx
+ if hasattr(mx, 'build_info'):
+ print("\nMLX Build Info:", mx.build_info(), flush=True)
+ else:
+ print("\nMLX Build Info: Not available in this version", flush=True)
+ except ImportError:
+ print("\nMLX: Not installed", flush=True)
+ except Exception as e:
+ print(f"\nError checking MLX: {e}", flush=True)
except Exception as e:
print(f"Error in macOS checks: {e}", flush=True)
@@ -45,13 +53,77 @@ def check_system_state():
# CPU Info
print("\nCPU Information:", flush=True)
try:
- cpu_freq = psutil.cpu_freq()
- print(f"CPU Frequency - Current: {cpu_freq.current:.2f}MHz, Min: {cpu_freq.min:.2f}MHz, Max: {cpu_freq.max:.2f}MHz", flush=True)
- print(f"CPU Usage per Core: {psutil.cpu_percent(percpu=True)}%", flush=True)
+ if platform.system() == 'Darwin' and platform.processor() == 'arm':
+ # Use sysctl for Apple Silicon Macs
+ cpu_info = subprocess.run(['sysctl', 'machdep.cpu'], capture_output=True, text=True)
+ if cpu_info.returncode == 0:
+ print(f"CPU Info (Apple Silicon):", cpu_info.stdout, flush=True)
+
+ # Parse powermetrics output for clearer CPU frequency display
+ try:
+ power_metrics = subprocess.run(
+ ['sudo', 'powermetrics', '-n', '1', '-i', '100', '--samplers', 'cpu_power'],
+ capture_output=True, text=True
+ )
+ if power_metrics.returncode == 0:
+ output = power_metrics.stdout
+ print("\nDetailed CPU Frequency Information:")
+
+ # Extract cluster frequencies and max frequencies
+ current_cluster = None
+ max_freqs = {'E': 0, 'P0': 0, 'P1': 0}
+
+ for line in output.split('\n'):
+ # Track which cluster we're processing
+ if "E-Cluster" in line:
+ current_cluster = 'E'
+ elif "P0-Cluster" in line:
+ current_cluster = 'P0'
+ elif "P1-Cluster" in line:
+ current_cluster = 'P1'
+
+ # Get current frequencies
+ if "HW active frequency:" in line:
+ freq = line.split(':')[1].strip()
+ if freq != "0 MHz":
+ print(f"Current {current_cluster}-Cluster Frequency: {freq}")
+
+ # Get max frequencies from residency lines
+ if current_cluster and "active residency:" in line and "MHz:" in line:
+ try:
+ # Extract all frequency values
+ freqs = []
+ parts = line.split('MHz:')[:-1] # Skip last part as it's not a frequency
+ for part in parts:
+ freq_str = part.split()[-1]
+ try:
+ freq = float(freq_str)
+ freqs.append(freq)
+ except ValueError:
+ continue
+ if freqs:
+ max_freqs[current_cluster] = max(max_freqs[current_cluster], max(freqs))
+ except Exception:
+ continue
+
+ # Print max frequencies
+ print("\nMaximum Available Frequencies:")
+ for cluster, max_freq in max_freqs.items():
+ if max_freq > 0:
+ print(f"{cluster}-Cluster Max: {max_freq:.0f} MHz")
+
+ except Exception as e:
+ print(f"Error parsing powermetrics: {e}", flush=True)
+ else:
+ # Use psutil for other systems
+ cpu_freq = psutil.cpu_freq()
+ print(f"CPU Frequency - Current: {cpu_freq.current:.2f}MHz, Min: {cpu_freq.min:.2f}MHz, Max: {cpu_freq.max:.2f}MHz", flush=True)
+
+ print(f"\nCPU Usage per Core: {psutil.cpu_percent(percpu=True)}%", flush=True)
# Check if running in low power mode
power_mode = subprocess.run(['pmset', '-g'], capture_output=True, text=True)
- print("Power Settings:", power_mode.stdout, flush=True)
+ print("\nPower Settings:", power_mode.stdout, flush=True)
except Exception as e:
print(f"Error getting CPU info: {e}", flush=True)
@@ -88,27 +160,33 @@ def check_system_state():
try:
current_process = psutil.Process()
print(f"Process Nice Value: {current_process.nice()}", flush=True)
- print(f"Process IO Nice Value: {current_process.ionice()}", flush=True)
- print(f"Process CPU Affinity: {current_process.cpu_affinity()}", flush=True)
+ # Only try to get ionice if the platform supports it
+ if hasattr(current_process, 'ionice'):
+ print(f"Process IO Nice Value: {current_process.ionice()}", flush=True)
except Exception as e:
print(f"Error getting process priority info: {e}", flush=True)
# System Load
print("\nSystem Load:", flush=True)
try:
- print(f"Load Average: {psutil.getloadavg()}", flush=True)
+ load_avg = psutil.getloadavg()
+ print(f"Load Average: {load_avg}", flush=True)
# Get top processes by CPU and Memory
- print("\nTop Processes:", flush=True)
+ print("\nTop Processes by CPU Usage:", flush=True)
processes = []
for proc in psutil.process_iter(['pid', 'name', 'cpu_percent', 'memory_percent']):
try:
- processes.append(proc.info)
+ pinfo = proc.info
+ if pinfo['cpu_percent'] is not None and pinfo['memory_percent'] is not None:
+ processes.append(pinfo)
except (psutil.NoSuchProcess, psutil.AccessDenied):
- pass
+ continue
- sorted_by_cpu = sorted(processes, key=lambda x: x['cpu_percent'], reverse=True)[:5]
- print("Top 5 CPU-consuming processes:", json.dumps(sorted_by_cpu, indent=2), flush=True)
+ # Sort and display top 5 CPU-consuming processes
+ sorted_by_cpu = sorted(processes, key=lambda x: x['cpu_percent'] or 0, reverse=True)[:5]
+ for proc in sorted_by_cpu:
+ print(f"PID: {proc['pid']}, Name: {proc['name']}, CPU: {proc['cpu_percent']}%, Memory: {proc['memory_percent']:.1f}%")
except Exception as e:
print(f"Error getting system load info: {e}", flush=True)
← 8c6d37d9 m4 cluster test
·
back to Exo
·
try a different taskpolicy eeecdcb4 →