Table of Contents
Fetching ...

CodeGreen: Towards Improving Precision and Portability in Software Energy Measurement

Saurabhsingh Rajput, Tushar Sharma

Abstract

Accurate software energy measurement is critical for optimizing energy, yet existing profilers force a trade-off between measurement accuracy and overhead due to tight coupling with supported specific hardware or languages. We present CodeGreen, a modular energy measurement platform that decouples instrumentation from measurement via an asynchronous producer-consumer architecture. We implement a Native Energy Measurement Backend (NEMB) that polls hardware sensors (Intel RAPL, NVIDIA NVML, AMD ROCm) independently, while lightweight timestamp markers enable tunable granularity. CodeGreen leverages Tree-sitter AST queries for automated instrumentation across Python, C++, C, and Java, with straightforward extension to any Tree-sitter-supported grammar, enabling developers to target specific scopes (loops, methods, classes) without manual intervention. Validation against "Computer Language Benchmarks Game" demonstrates $R^2 = 0.9934$ correlation with RAPL ground truth and $R^2 = 0.9997$ energy-workload linearity. By bridging fine-grained measurement precision with cross-platform portability, CodeGreen enables practical algorithmic energy optimization across heterogeneous environments. Source code, video demonstration, and documentation for the tool are publicly available at: https://smart-dal.github.io/codegreen/.

CodeGreen: Towards Improving Precision and Portability in Software Energy Measurement

Abstract

Accurate software energy measurement is critical for optimizing energy, yet existing profilers force a trade-off between measurement accuracy and overhead due to tight coupling with supported specific hardware or languages. We present CodeGreen, a modular energy measurement platform that decouples instrumentation from measurement via an asynchronous producer-consumer architecture. We implement a Native Energy Measurement Backend (NEMB) that polls hardware sensors (Intel RAPL, NVIDIA NVML, AMD ROCm) independently, while lightweight timestamp markers enable tunable granularity. CodeGreen leverages Tree-sitter AST queries for automated instrumentation across Python, C++, C, and Java, with straightforward extension to any Tree-sitter-supported grammar, enabling developers to target specific scopes (loops, methods, classes) without manual intervention. Validation against "Computer Language Benchmarks Game" demonstrates correlation with RAPL ground truth and energy-workload linearity. By bridging fine-grained measurement precision with cross-platform portability, CodeGreen enables practical algorithmic energy optimization across heterogeneous environments. Source code, video demonstration, and documentation for the tool are publicly available at: https://smart-dal.github.io/codegreen/.
Paper Structure (20 sections, 12 figures, 1 table)

This paper contains 20 sections, 12 figures, 1 table.

Figures (12)

  • Figure 1: CodeGreen architecture
  • Figure 2: CodeGreen Website: The official website at https://smart-dal.github.io/codegreen/ provides installation guides, API references, usage examples, and demo videos.
  • Figure 3: Installation: Running ./install.sh automatically detects the host architecture, compiles NEMB, and installs Python bindings and CLI tools.
  • Figure 4: Command Overview: The codegreen --help command displays the complete CLI interface, categorizing subcommands into measurement (measure, benchmark), analysis (analyze), and system management (init-sensors, config, doctor, info) tasks.
  • Figure 5: Sensor Initialization: The codegreen init-sensors command detects Intel RAPL, NVIDIA NVML, and AMD ROCm interfaces, configuring non-root access permissions.
  • ...and 7 more figures