Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ The repository includes VS Code launch configurations in CONTRIBUTING.md for:
- Testing codecarbon CLI monitor

### Getting Help
- **FAQ**: https://mlco2.github.io/codecarbon/faq.html
- **Documentation**: https://mlco2.github.io/codecarbon/
- **FAQ**: https://docs.codecarbon.io/faq.html
- **Documentation**: https://docs.codecarbon.io/
- **Issues**: https://github.com/mlco2/codecarbon/issues

## Architecture Overview
Expand Down
20 changes: 10 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<!-- TOC --><a name="have-a-question"></a>
## </a> Have a Question?

Please see the [FAQ](https://mlco2.github.io/codecarbon/faq.html) for questions.
Please see the [FAQ](https://docs.codecarbon.io/faq.html) for questions.


<!-- TOC --><a name="found-a-bug"></a>
Expand Down Expand Up @@ -148,7 +148,7 @@ To test CodeCarbon, it is useful to stress your computer to make it use its full

- 7Zip is often already installed, running it with `7z b` makes a quick CPU test.
- [GPU-burn](https://github.com/wilicc/gpu-burn) will load test the GPU for a configurable duration.
- To test the CPU : `stress-ng --cpu 0 --cpu-method matrixprod --metrics-brief --rapl --perf -t 60s` See [our documentation](https://mlco2.github.io/codecarbon/test_on_scaleway.html) to install it.
- To test the CPU : `stress-ng --cpu 0 --cpu-method matrixprod --metrics-brief --rapl --perf -t 60s` See [our documentation](https://docs.codecarbon.io/test_on_scaleway.html) to install it.
- To do useful computation while testing [Folding At Home](https://foldingathome.org/) is a good option.
- [OCCT](https://www.ocbase.com/download) is a proprietary tool but free for non-commercial use and avaliable for Windows and Linux.

Expand Down Expand Up @@ -284,19 +284,19 @@ uv run --only-group doc task docs

to regenerate the html files. For local preview with live reload, run `uv run --only-group doc task docs-serve`.

### Rebase your branch on master
### Rebase your branch on main

Before creating a PR, please make sure to rebase your branch on master to avoid merge conflicts and make the review easier. You can do it with the following command:
Before creating a PR, please make sure to rebase your branch on main to avoid merge conflicts and make the review easier. You can do it with the following command:
```sh
# Be careful, this command will delete every local changes you have, make sure to commit or stash them before running it
TARGET_BRANCH=master
TARGET_BRANCH=main
current_branch=$(git symbolic-ref --short HEAD)
git switch $TARGET_BRANCH && git pull
git switch $current_branch --force && git fetch origin $TARGET_BRANCH
git rebase $TARGET_BRANCH
```

In case of a conflict during a rebase, "incoming" refers to your branch, and "current" refers to master. This is because the commits from your branch are being applied to master, so they are incoming. In case of a merge, it's the opposite!
In case of a conflict during a rebase, "incoming" refers to your branch, and "current" refers to main. This is because the commits from your branch are being applied to main, so they are incoming. In case of a merge, it's the opposite!

Check if everything is fine:

Expand All @@ -309,19 +309,19 @@ Push force
git push --force-with-lease
```

### Rebase your branch on master
### Rebase your branch on main

Before creating a PR, please make sure to rebase your branch on master to avoid merge conflicts and make the review easier. You can do it with the following command:
Before creating a PR, please make sure to rebase your branch on main to avoid merge conflicts and make the review easier. You can do it with the following command:
```sh
# Be careful, this command will delete every local changes you have, make sure to commit or stash them before running it
TARGET_BRANCH=master
TARGET_BRANCH=main
current_branch=$(git symbolic-ref --short HEAD)
git switch $TARGET_BRANCH && git pull
git switch $current_branch --force && git fetch origin $TARGET_BRANCH
git rebase $TARGET_BRANCH
```

In case of a conflict during a rebase, "incoming" refers to your branch, and "current" refers to master. This is because the commits from your branch are being applied to master, so they are incoming. In case of a merge, it's the opposite!
In case of a conflict during a rebase, "incoming" refers to your branch, and "current" refers to main. This is because the commits from your branch are being applied to main, so they are incoming. In case of a merge, it's the opposite!

Check if everything is fine:

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Estimate and track carbon emissions from your computer, quantify and analyze the

CodeCarbon websites:
- [Main website](https://codecarbon.io) to learn why we do this.
- [Dashboard](https://dashboard.codecarbon.io/) to see your emissions, [read the API doc](https://mlco2.github.io/codecarbon/api.html) before.
- [Documentation](https://mlco2.github.io/codecarbon) to learn how to use the package and our methodology.
- [Dashboard](https://dashboard.codecarbon.io/) to see your emissions, [read the API doc](https://docs.codecarbon.io/api.html) before.
- [Documentation](https://docs.codecarbon.io) to learn how to use the package and our methodology.
- [GitHub](https://github.com/mlco2/codecarbon) to look at the source code and contribute.
- [Discord](https://discord.gg/GS9js2XkJR) to chat with us.

Expand Down Expand Up @@ -51,7 +51,7 @@ We created a Python package that estimates your hardware electricity power consu

![calculation Summary](docs/images/calculation.png)

We explain more about this calculation in the [**Methodology**](https://mlco2.github.io/codecarbon/methodology.html#) section of the documentation.
We explain more about this calculation in the [**Methodology**](https://docs.codecarbon.io/methodology.html#) section of the documentation.

Our hope is that this package will be used widely for estimating the carbon footprint of computing, and for establishing best practices with regards to the disclosure and reduction of this footprint.

Expand All @@ -73,7 +73,7 @@ conda activate your_env
pip install codecarbon
```

To see more installation options please refer to the documentation: [**Installation**](https://mlco2.github.io/codecarbon/installation.html#)
To see more installation options please refer to the documentation: [**Installation**](https://docs.codecarbon.io/installation.html#)

## Start to estimate your impact 📏

Expand Down Expand Up @@ -127,7 +127,7 @@ def your_function_to_track():
```
The package will track the emissions generated by the execution of your function.

There is other ways to use **codecarbon** package, please refer to the documentation to learn more about it: [**Usage**](https://mlco2.github.io/codecarbon/usage.html#)
There is other ways to use **codecarbon** package, please refer to the documentation to learn more about it: [**Usage**](https://docs.codecarbon.io/usage.html#)

## Visualize 📊

Expand All @@ -141,7 +141,7 @@ You can now visualize your experiment emissions on the [dashboard](https://dashb
> - cloud mode
> - comet integration...
>
> Please explore the [**Documentation**](https://mlco2.github.io/codecarbon) to learn about it
> Please explore the [**Documentation**](https://docs.codecarbon.io) to learn about it
> If ever what your are looking for is not yet implemented, let us know through the *issues* and even better become one of our 🦸🏼‍♀️🦸🏼‍♂️ contributors! more info 👇🏼


Expand Down
2 changes: 1 addition & 1 deletion codecarbon/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def config():
overwrite_local_config("api_key", api_key, path=file_path)
show_config(file_path)
print(
"Consult [link=https://mlco2.github.io/codecarbon/usage.html#configuration]configuration documentation[/link] for more configuration options"
"Consult [link=https://docs.codecarbon.io/usage.html#configuration]configuration documentation[/link] for more configuration options"
)


Expand Down
2 changes: 1 addition & 1 deletion codecarbon/core/powermetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _has_powermetrics_sudo() -> bool:
"""Not using PowerMetrics, sudo password prompt detected.
If you want to enable Powermetrics please modify your sudoers file
as described in :
https://mlco2.github.io/codecarbon/methodology.html#power-usage
https://docs.codecarbon.io/methodology.html#power-usage
"""
)
return False
Expand Down
8 changes: 4 additions & 4 deletions codecarbon/emissions_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1147,11 +1147,11 @@ def __init__(
:param cloud_provider: The cloud provider specified for estimating emissions
intensity, defaults to None.
See https://github.com/mlco2/codecarbon/
blob/master/codecarbon/data/cloud/impact.csv
blob/main/codecarbon/data/cloud/impact.csv
for a list of cloud providers
:param cloud_region: The region of the cloud data center, defaults to None.
See https://github.com/mlco2/codecarbon/
blob/master/codecarbon/data/cloud/impact.csv
blob/main/codecarbon/data/cloud/impact.csv
for a list of cloud regions.
:param country_2letter_iso_code: For use with the Electricity Maps emissions API.
See http://api.electricitymap.org/v3/zones for
Expand Down Expand Up @@ -1374,11 +1374,11 @@ def track_emissions(
:param cloud_provider: The cloud provider specified for estimating emissions
intensity, defaults to None.
See https://github.com/mlco2/codecarbon/
blob/master/codecarbon/data/cloud/impact.csv
blob/main/codecarbon/data/cloud/impact.csv
for a list of cloud providers.
:param cloud_region: The region of the cloud data center, defaults to None.
See https://github.com/mlco2/codecarbon/
blob/master/codecarbon/data/cloud/impact.csv
blob/main/codecarbon/data/cloud/impact.csv
for a list of cloud regions.
:param country_2letter_iso_code: For use with the Electricity Maps emissions API.
See http://api.electricitymap.org/v3/zones for
Expand Down
54 changes: 53 additions & 1 deletion codecarbon/external/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def __init__(
rapl_include_dram: bool = False,
rapl_prefer_psys: bool = False,
):
assert tracking_mode in ["machine", "process"]
assert tracking_mode in ["machine", "process", "process_tree"]
self._power_history: List[Power] = []
self._output_dir = output_dir
self._mode = mode
Expand Down Expand Up @@ -330,6 +330,58 @@ def _get_power_from_cpu_load(self):
logger.debug(
f"CPU load {self._tdp} W and {cpu_load:.1f}% ({cpu_load_normalized:.1f}% normalized) => estimation of {power:.2f} W for process {self._pid} and {len(current_cpu_times) - 1} children."
)
elif self._tracking_mode == "process_tree":
# process_tree mode is an alias for process mode
# Both track main process and all children recursively
# This alias is added for consistency with RAM module naming
# Use CPU times for accurate process tree tracking
current_time = time.time()
current_cpu_times: Dict[int, float] = {}

# Get CPU time for main process and all children
try:
processes = [self._process] + self._process.children(recursive=True)
except (psutil.NoSuchProcess, psutil.AccessDenied):
processes = [self._process]

for proc in processes:
try:
cpu_times = proc.cpu_times()
total_cpu_time = cpu_times.user + cpu_times.system
current_cpu_times[proc.pid] = total_cpu_time
except (psutil.NoSuchProcess, psutil.AccessDenied):
logger.debug(
f"Process {proc.pid} disappeared or access denied when getting CPU times."
)

# Calculate CPU usage based on delta
if self._last_measurement_time is not None:
time_delta = current_time - self._last_measurement_time
if time_delta > 0:
total_cpu_delta = 0.0
for pid, cpu_time in current_cpu_times.items():
last_cpu_time = self._last_cpu_times.get(pid, cpu_time)
cpu_delta = cpu_time - last_cpu_time
if cpu_delta > 0:
total_cpu_delta += cpu_delta

cpu_load = (total_cpu_delta / time_delta) * 100
else:
cpu_load = 0.0
else:
cpu_load = 0.0
logger.debug("First measurement, no CPU delta available yet")

# Store for next measurement
self._last_measurement_time = current_time
self._last_cpu_times = current_cpu_times

# Normalize to percentage of total CPU capacity
cpu_load_normalized = cpu_load / self._cpu_count
power = self._tdp * cpu_load_normalized / 100
logger.debug(
f"CPU load {self._tdp} W and {cpu_load:.1f}% ({cpu_load_normalized:.1f}% normalized) => estimation of {power:.2f} W for process tree {self._pid}."
)
else:
raise Exception(f"Unknown tracking_mode {self._tracking_mode}")
return Power.from_watts(power)
Expand Down
2 changes: 1 addition & 1 deletion codecarbon/external/ram.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class RAM(BaseHardware):
In V3, we need to improve the accuracy of the RAM power estimation.
Because the power consumption of RAM is not linear with the amount of memory used,

See https://mlco2.github.io/codecarbon/methodology.html#ram for details on the RAM
See https://docs.codecarbon.io/methodology.html#ram for details on the RAM
power estimation methodology.

"""
Expand Down
2 changes: 1 addition & 1 deletion examples/notebooks/codecarbon_workshop.ipynb
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The URL doesn't seem correct in this file, is it a rendering problem ?

Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@
"### 🚀 Next Steps & Resources:\n",
"\n",
"#### 📚 **Learning Resources:**\n",
"- 📖 [CodeCarbon Documentation](https://mlco2.github.io/codecarbon/)\n",
"- 📖 [CodeCarbon Documentation](https://docs.codecarbon.io/)\n",
"- 📈 [ML CO2 Impact Calculator](https://mlco2.github.io/impact/)\n",
"\n",
"#### 🛠️ **Integration Ideas:**\n",
Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ docs_dir: docs
site_dir: site
repo_url: https://github.com/mlco2/codecarbon
repo_name: mlco2/codecarbon
edit_uri: edit/master/docs/
edit_uri: edit/main/docs/
copyright: "&copy; CodeCarbon"

theme:
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/app/(dashboard)/home/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ export default function HomePage() {
For more information, please refer to the documentation:
<br />
<a
href="https://mlco2.github.io/codecarbon/usage.html"
href="https://docs.codecarbon.io/usage.html"
target="_blank"
>
https://mlco2.github.io/codecarbon/usage.html
https://docs.codecarbon.io/usage.html
</a>
</CardDescription>
</CardHeader>
Expand Down
Loading