From e5d6f8e3f68ce727002ba71a3eceeeb46b14a818 Mon Sep 17 00:00:00 2001
From: yicheng <928596708@qq.com>
Date: Sat, 21 Mar 2026 22:36:53 +0800
Subject: [PATCH 1/4] docs: fix broken documentation links
Closes #1125
Replaced all mlco2.github.io/codecarbon links with docs.codecarbon.io:
- README.md (6 links)
- CONTRIBUTING.md (2 links)
- .github/copilot-instructions.md (2 links)
---
.github/copilot-instructions.md | 4 ++--
CONTRIBUTING.md | 4 ++--
README.md | 12 ++++++------
3 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md
index e6538d0f5..57424d635 100644
--- a/.github/copilot-instructions.md
+++ b/.github/copilot-instructions.md
@@ -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
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index efae3a970..a96bf3d1a 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -39,7 +39,7 @@
## 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.
@@ -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.
diff --git a/README.md b/README.md
index 7c4ac896a..31167ec94 100644
--- a/README.md
+++ b/README.md
@@ -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.
@@ -51,7 +51,7 @@ We created a Python package that estimates your hardware electricity power consu

-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.
@@ -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 π
@@ -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 π
@@ -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 ππΌ
From 03de56dda62c122206798e18f807aa29ccce0289 Mon Sep 17 00:00:00 2001
From: yicheng <928596708@qq.com>
Date: Sun, 22 Mar 2026 18:40:58 +0800
Subject: [PATCH 2/4] docs: fix remaining broken documentation links (#1125)
- Replace mlco2.github.io/codecarbon with docs.codecarbon.io in:
- webapp/src/app/(dashboard)/home/page.tsx (2 links)
- codecarbon/core/powermetrics.py (1 link)
- codecarbon/cli/main.py (1 link)
- codecarbon/external/ram.py (1 link)
- examples/notebooks/codecarbon_workshop.ipynb (1 link)
Fixes: #1125
---
codecarbon/cli/main.py | 2 +-
codecarbon/core/powermetrics.py | 2 +-
codecarbon/external/ram.py | 2 +-
examples/notebooks/codecarbon_workshop.ipynb | 2 +-
webapp/src/app/(dashboard)/home/page.tsx | 4 ++--
5 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/codecarbon/cli/main.py b/codecarbon/cli/main.py
index ead900903..7377df5e4 100644
--- a/codecarbon/cli/main.py
+++ b/codecarbon/cli/main.py
@@ -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"
)
diff --git a/codecarbon/core/powermetrics.py b/codecarbon/core/powermetrics.py
index c92429342..188c8faf6 100644
--- a/codecarbon/core/powermetrics.py
+++ b/codecarbon/core/powermetrics.py
@@ -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
diff --git a/codecarbon/external/ram.py b/codecarbon/external/ram.py
index 20a5c2fad..c3d946c05 100644
--- a/codecarbon/external/ram.py
+++ b/codecarbon/external/ram.py
@@ -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.
"""
diff --git a/examples/notebooks/codecarbon_workshop.ipynb b/examples/notebooks/codecarbon_workshop.ipynb
index fbfaa7cbf..1da4f44a5 100644
--- a/examples/notebooks/codecarbon_workshop.ipynb
+++ b/examples/notebooks/codecarbon_workshop.ipynb
@@ -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",
diff --git a/webapp/src/app/(dashboard)/home/page.tsx b/webapp/src/app/(dashboard)/home/page.tsx
index 80723a898..f42eb14d8 100644
--- a/webapp/src/app/(dashboard)/home/page.tsx
+++ b/webapp/src/app/(dashboard)/home/page.tsx
@@ -78,10 +78,10 @@ export default function HomePage() {
For more information, please refer to the documentation:
- https://mlco2.github.io/codecarbon/usage.html
+ https://docs.codecarbon.io/usage.html
From a5dc5299cb2f3ef6b8c6fd11fe1b3c50c59cddb6 Mon Sep 17 00:00:00 2001
From: yicheng <928596708@qq.com>
Date: Sun, 22 Mar 2026 20:41:40 +0800
Subject: [PATCH 3/4] docs: update master branch references to main
- Update mkdocs.yml edit_uri to use main branch
- Update CONTRIBUTING.md rebase instructions
- Update emissions_tracker.py docstring URLs
- Add process_tree tracking mode to CPU module for consistency with RAM
Fixes #1084 and addresses #976
---
CONTRIBUTING.md | 16 ++++++++--------
codecarbon/emissions_tracker.py | 8 ++++----
codecarbon/external/hardware.py | 2 +-
mkdocs.yml | 2 +-
4 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index a96bf3d1a..200242f72 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -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:
@@ -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:
diff --git a/codecarbon/emissions_tracker.py b/codecarbon/emissions_tracker.py
index 862eba2b4..439dfbd02 100644
--- a/codecarbon/emissions_tracker.py
+++ b/codecarbon/emissions_tracker.py
@@ -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
@@ -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
diff --git a/codecarbon/external/hardware.py b/codecarbon/external/hardware.py
index c2369a5f5..0fc7a4259 100644
--- a/codecarbon/external/hardware.py
+++ b/codecarbon/external/hardware.py
@@ -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
diff --git a/mkdocs.yml b/mkdocs.yml
index f53c2aa52..e4804ea30 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -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: "© CodeCarbon"
theme:
From ba376526692aedb917442a70cc9ce0d881b0a959 Mon Sep 17 00:00:00 2001
From: yicheng <928596708@qq.com>
Date: Sun, 22 Mar 2026 20:43:35 +0800
Subject: [PATCH 4/4] feat: add process_tree tracking mode for CPU consistency
with RAM
- Add 'process_tree' as an alias for 'process' tracking mode
- Provides consistent naming with RAM module
- Tracks main process and all children recursively
- Addresses #976 (Inconsistent behaviour for RAM and CPU Monitoring)
The process_tree mode uses the same implementation as process mode,
which already includes child processes via psutil.children(recursive=True).
This alias improves API clarity and consistency.
---
codecarbon/external/hardware.py | 52 +++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/codecarbon/external/hardware.py b/codecarbon/external/hardware.py
index 0fc7a4259..679841c87 100644
--- a/codecarbon/external/hardware.py
+++ b/codecarbon/external/hardware.py
@@ -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)