-
-
Notifications
You must be signed in to change notification settings - Fork 233
Added CPU and RAM utilization tracking #911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
This is great stuff. Just a doubt, is this measuring RAM or vRAM? |
|
Hello @IamLRBA, For the failing pre-commit, have a look to https://github.com/mlco2/codecarbon/blob/master/CONTRIBUTING.md#coding-style--linting It seems you removed empty line at end of file, it's not something we want : https://stackoverflow.com/questions/729692/why-should-text-files-end-with-a-newline I will be off for the project for some days, so I can't test your contribution. @sebasmos The code use virtual_memory() which is the physical memory on the motherboard, called DRAM, it's not the VRAM of the GPU. This could be done with |
@benoit-cty I think I have solved the problems which were requested to be changed. |
|
Sorry for the delay.
|
|
The api client is not impacted so we can merge, it's ok for the API. We can implement it, if needed, in a future PR, but it's good for me now. |
|
Hello @IamLRBA , I made some improvement while testing Google Antigravity. Implementation Plan: Improve CPU and RAM Utilization TrackingProblemThe current implementation collects CPU and RAM utilization metrics at a single point in time when _prepare_emissions_data() is called. This provides instantaneous values that may not accurately represent the average resource usage during the measurement period. The user suggests computing averages over time by collecting these metrics in the _monitor_power() method, which runs every 1 second. Background ContextCurrently: CPU and RAM utilization are collected in IntelPowerGadget.get_cpu_details() and IntelRAPL.get_cpu_details() in core/cpu.py These instantaneous values are used directly in _prepare_emissions_data() in emissions_tracker.py The _monitor_power() method already runs every 1 second to collect power measurements for hardware that doesn't support energy monitoring Proposed Changes[MODIFY] emissions_tracker.py
Update _monitor_power() method (lines 801-810):
Update _prepare_emissions_data()
Clear history on tracker start/reset:
[MODIFY] emissions_data.py Add fields to EmissionsData dataclass :
Add fields to TaskEmissionsData dataclass :
Update compute_delta_emission() These utilization metrics represent averages over the delta period, so they should not be subtracted Add CPU, GPU, and RAM Utilization to Database and APIOverviewBased on the last two commits that added cpu_utilization_percent, gpu_utilization_percent, and ram_utilization_percent to the EmissionsData and TaskEmissionsData classes, this implementation will extend these fields to the database schema and API layer. Proposed ChangesDatabase Models[MODIFY] sql_models.py
These will be added after the existing power/energy fields. API Schemas[MODIFY] schemas.py Report schemas: Add the three utilization fields to:
[MODIFY] repository_emissions.py
Database Migration[NEW] Migration file in
|
- Implement CPU and RAM utilization percentage tracking using psutil - Add cpu_utilization_percent, ram_utilization_percent, and ram_used_gb metrics - Include utilization metrics in emissions data output - Update IntelPowerGadget and IntelRAPL classes to collect utilization data Resolves mlco2#885
Hi @benoit-cty, Thanks a lot for your detailed comment and for helping me to work on this! I've read through your implementation plan, and it makes perfect sense. I really appreciate you building on the initial PR and fleshing out the complete picture, especially the parts about storing the averages in the data classes, updating the database schema, and adding it to the API. It's great to see this feature being integrated so thoroughly. Please let me know if there's anything I can do to help test the new changes or assist in any other way. Looking forward to seeing this merged! Thanks! |
Description
This PR adds tracking of CPU and RAM utilization percentages to complement the existing energy measurements. The implementation uses psutil (which is already a project dependency) to collect:
cpu_utilization_percent: Current CPU usage percentageram_utilization_percent: Current RAM usage percentageram_used_gb: Current RAM usage in GBThe main changes I made are:
core/cpu.py:emissions_tracker.py:These metrics are are collected using psutil and are now included in the emissions data output alongside the existing power measurements.
Related Issue
This PR resolves: #885
Motivation and Context
The change was requested to provide more detailed system resource utilization metrics alongside energy consumption data. This helps users:
How Has This Been Tested?
The changes were tested by:
Types of changes
What types of changes does your code introduce? Put an
xin all the boxes that apply:Checklist:
Go over all the following points, and put an
xin all the boxes that apply.cc @benoit-cty, @sebasmos