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..200242f72 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. @@ -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/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 ![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. @@ -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 πŸ‘‡πŸΌ 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/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..679841c87 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 @@ -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) 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/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: 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