This program measures the power consumption of a specific application on macOS by correlating the application's CPU and GPU usage with system power metrics.
- Monitors power consumption of a specific application by name or process ID
- Provides real-time power consumption estimates
- Calculates average and maximum power consumption
- Saves detailed monitoring data to a JSON file for further analysis
- Works on macOS with Apple Silicon or Intel processors
- macOS (tested on macOS 24.1.0)
- Python 3.6 or higher
psutilPython packagepowermetricscommand-line tool (built into macOS)
- Clone or download this repository
- Create and activate a virtual environment (recommended):
# Create a virtual environment
python3 -m venv venv
# Activate the virtual environment
source venv/bin/activate- Install the required Python packages:
pip install -r requirements.txtThe program requires sudo privileges to access the powermetrics tool. Make sure your virtual environment is activated:
# Activate the virtual environment (if not already activated)
source venv/bin/activate
# Monitor by application name
sudo python3 Power.py -n "Safari"
# Monitor by process ID
sudo python3 Power.py -p 1234
# Specify monitoring duration and interval
sudo python3 Power.py -n "Chrome" -d 300 -i 2
# To view graph
sudo python3 Power.py -n "Cursor" -g-n, --name: Application name to monitor-p, --pid: Process ID to monitor-i, --interval: Sampling interval in seconds (default: 1.0)-d, --duration: Monitoring duration in seconds (default: 60)
This tool uses a combination of techniques to estimate application-specific power consumption:
- It uses the
psutillibrary to monitor the CPU and memory usage of the target application - It uses macOS's built-in
powermetricstool to collect system-wide power metrics - It correlates the application's CPU usage with the system's total power consumption to estimate the application's share of power usage
- When available, it uses process-specific energy information provided by
powermetrics
- The power consumption estimates are approximations based on CPU usage correlation
- GPU power attribution is simplified and may not be accurate for GPU-intensive applications
- Background system processes may affect the accuracy of measurements
- Requires sudo privileges to access detailed power metrics
The program displays real-time power consumption information and saves detailed data to a JSON file. The JSON file includes:
- Application information (name, PID)
- Monitoring parameters (duration, interval)
- Summary statistics (average power, maximum power, total energy)
- Detailed time-series data for further analysis
This project is open source and available under the MIT License.