Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Application-Specific Power Consumption Monitor

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.

Features

  • 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

Requirements

  • macOS (tested on macOS 24.1.0)
  • Python 3.6 or higher
  • psutil Python package
  • powermetrics command-line tool (built into macOS)

Installation

  1. Clone or download this repository
  2. Create and activate a virtual environment (recommended):
# Create a virtual environment
python3 -m venv venv

# Activate the virtual environment
source venv/bin/activate
  1. Install the required Python packages:
pip install -r requirements.txt

Usage

The 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

Command-line Arguments

  • -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)

How It Works

This tool uses a combination of techniques to estimate application-specific power consumption:

  1. It uses the psutil library to monitor the CPU and memory usage of the target application
  2. It uses macOS's built-in powermetrics tool to collect system-wide power metrics
  3. It correlates the application's CPU usage with the system's total power consumption to estimate the application's share of power usage
  4. When available, it uses process-specific energy information provided by powermetrics

Limitations

  • 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

Output

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

License

This project is open source and available under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages