The Application Power Usage Monitor is a Python script that enables monitoring of an application's CPU and memory consumption over time using the psutil
library.
NOTE: Estimating the power consumption of a laptop's CPU based solely on its usage can be challenging due to various factors that influence power consumption. Power consumption depends not only on CPU usage but also on factors like the CPU's clock frequency, voltage, architecture, workload type, efficiency, and other hardware components.
- Real-time monitoring of CPU usage (as a percentage) and memory usage (in megabytes) of a specified application.
- Calculation of average CPU usage based on the number of CPU cores.
- User-friendly input for providing the target application's Process ID (PID).
- Handling of errors, including invalid PIDs and missing processes.
- Python 3.x
psutil
library: You can install it using the following command:
- Clone or download this repository to your local machine.
- Open PyCharm and create a new Python project.
- Copy and paste the script provided in
application_power_usage_monitor.py
into a new Python file within your PyCharm project. - Ensure you have the required
psutil
library installed by running: - In the Python file, run the script by clicking the "Run" button or right-clicking in the editor and selecting "Run".
- Follow the on-screen instructions to provide the Process ID (PID) of the application you want to monitor.
- Press
Ctrl + C
within the terminal or PyCharm console to stop monitoring.
- The script takes a target PID as input and initiates monitoring of the application's resource usage.
- It records the initial CPU and memory usage of the application.
- Within a loop, it calculates the change in CPU and memory usage over a one-second interval.
- The script calculates and displays the elapsed time, average CPU usage (across all cores), and memory usage.
- The monitoring process continues until manually stopped.
Contributions to this project are welcome! If you encounter any issues or have suggestions for improvements, feel free to open an issue or submit a pull request in this repository.
This project is licensed under the MIT License.