Skip to content

CodeGreen

  • Precise Energy Measurement


    Hardware-level energy monitoring via Intel RAPL, NVIDIA NVML, and AMD ROCm with sub-millisecond resolution.

    Getting Started

  • Multi-Language Support


    Python, C, C++, and Java instrumentation via Tree-sitter with config-driven extensibility.

    Examples

  • Interactive Visualization


    Energy timeline plots with per-function breakdown, hotspot detection, and zoom/pan via Plotly.

    Reports & Visualization

  • Easy Integration


    CLI tool with JSON/CSV/Markdown output, CI/CD energy gating via --budget, and granularity control.

    Installation

Setup & Installation

Quick start guide: installing and configuring CodeGreen.

What is CodeGreen?

CodeGreen is an energy measurement tool that helps developers understand the energy consumption of their software at the function level. It uses Tree-sitter AST parsing for automatic code instrumentation and a C++ backend (NEMB) for hardware-level energy readings with minimal overhead.

Key Features

  • Energy Measurement: Per-function energy attribution via Intel RAPL, NVIDIA NVML, AMD ROCm
  • Quick Measurement: codegreen run measures energy of any shell command (like hyperfine for energy)
  • Code Analysis: Tree-sitter based static analysis across Python, C, C++, Java
  • Visualization: Interactive energy timeline with --export-plot (Plotly HTML with zoom/pan)
  • Granularity Control: Coarse mode (main only) or fine mode (all functions)
  • CI/CD Energy Gating: --budget flag to enforce energy budgets in pipelines
  • Benchmarking: Built-in benchmark suite -- 0.03% error vs perf RAPL on representative workloads

Quick Start

Get started with CodeGreen in just a few steps:

git clone https://github.com/SMART-Dal/codegreen.git
cd codegreen
./install.sh
sudo codegreen init-sensors
codegreen measure python my_script.py
codegreen run python my_script.py --repeat 10
codegreen measure python my_script.py -g fine --export-plot energy.html

Supported Platforms

  • Linux


    Intel RAPL, NVIDIA NVML, and AMD ROCm/RAPL energy monitoring.

  • macOS


    Apple Silicon and Intel Mac energy monitoring support.

  • Windows


    Windows energy monitoring via supported hardware interfaces.

Hardware sensor availability varies by platform.

Citing CodeGreen

If you use CodeGreen in your research, please cite:

Rajput, S., Widmayer, T., Shang, Z., Kechagia, M., Sarro, F., & Sharma, T. (2024). Enhancing energy-awareness in deep learning through fine-grained energy measurement. ACM Transactions on Software Engineering and Methodology, 33(8), 1-34.

Full citation & BibTeX

Community

License

CodeGreen is released under the MPL 2.0 License. See the License page for details.