一句话:提出模块化能耗测量平台 CodeGreen,以异步解耦架构与 AST 自动插桩实现高精度、跨平台、低开销的软件能耗测量。
现有软件能耗分析工具因与特定硬件或语言紧耦合,不得不在测量精度与开销之间权衡。CodeGreen 是模块化能耗测量平台,用异步生产者—消费者架构将插桩与测量解耦:原生能耗测量后端(NEMB)独立轮询 Intel RAPL、NVIDIA NVML、AMD ROCm 等硬件传感器,轻量时间戳标记提供可调粒度。它借助 Tree-sitter AST 查询为 Python、C++、C 和 Java 自动插桩,并可扩展到其他 Tree-sitter 语法,自动定位循环、方法、类等作用域。在 Computer Language Benchmarks Game 上验证,与 RAPL 基准真值的相关系数 R²=0.9934,能耗—工作负载线性度 R²=0.9997,兼顾细粒度精度与跨平台可移植性。
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 R2 = 0.9934 correlation with RAPL ground truth and R2 = 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 demo, and documentation are publicly available [18].