CodeGreen¶
-
Precise Energy Measurement
Hardware-level energy monitoring via RAPL (Linux), IOReport (macOS), EMI (Windows), NVML, and ROCm with sub-millisecond resolution.
-
Multi-Language Support
Python, C, C++, and Java instrumentation via Tree-sitter with config-driven extensibility.
-
Interactive Visualization
Energy timeline plots with per-function breakdown, hotspot detection, and zoom/pan via Plotly.
-
Easy Integration
CLI tool with JSON/CSV/Markdown output, CI/CD energy gating via
--budget, and granularity control.
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 RAPL (Linux), IOReport + kpc (macOS), EMI (Windows), NVML, ROCm
- Quick Measurement:
codegreen runmeasures energy of any shell command with hardware-level precision - 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:
--budgetflag 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:
Supported Platforms¶
-
Linux
Intel RAPL, NVIDIA NVML, and AMD ROCm/RAPL energy monitoring.
-
macOS
Apple Silicon energy via IOReport (CPU/GPU/ANE/DRAM) + kpc hardware perf counters. Pre-built ARM64 wheels on PyPI.
-
Windows 11
RAPL energy via EMI (inbox intelpep.sys driver). PKG, cores, iGPU, DRAM domains. Zero driver install.
Pre-built wheels for Linux x86_64 and macOS ARM64. Windows and other platforms: install from source.
Citing CodeGreen¶
If you use CodeGreen in your research, please cite:
Rajput, S., & Sharma, T. (2026). CodeGreen: Towards Improving Precision and Portability in Software Energy Measurement. arXiv preprint arXiv:2603.17924.
Community¶
- GitHub - Source code and issues
- Discussions - Community discussions
License¶
CodeGreen is released under the MPL 2.0 License. See the License page for details.