Quick Start¶
Get up and running with CodeGreen in minutes.
1. Install¶
2. Initialize Sensors¶
3. Verify Setup¶
If you see energy values (Joules/Watts), sensors are working.
4. Measure Your Code¶
Coarse Mode (default)¶
Total program energy -- instruments only main entry/exit:
Fine Mode¶
Per-function energy breakdown -- instruments all functions:
With Visualization¶
Export an interactive energy timeline:
Open energy.html in a browser to see:
- Per-function energy bar chart with hotspot detection
- Zoomable timeline with hover tooltips
- Summary stats (total energy, wall time, power)
Quick Energy Measurement (any command)¶
Measure the energy of any shell command without instrumentation, similar to hyperfine:
With JSON output and energy budget enforcement:
C/C++ Programs¶
Java Programs¶
How It Works¶
When you run codegreen measure:
- Tree-sitter AST Parsing: Identifies function boundaries and instrumentation points
- Code Instrumentation: Injects lightweight checkpoint calls
- Background Polling: C++ thread samples hardware sensors at 1ms intervals
- Execution: Your code runs with ~100-200ns overhead per checkpoint
- Time-Series Correlation: Binary search + linear interpolation matches checkpoints to energy readings
- Attribution: Energy difference between enter/exit checkpoints = function energy
Checkpoints are timestamp markers (~100ns), not synchronous hardware reads (~5-20us). This achieves 25-100x lower overhead than traditional profiling.
5. Analyze Results¶
Output includes:
- Total Energy: Consumption in Joules
- Average Power: Draw in Watts
- Function Breakdown: Per-function energy with invocation counts (fine mode)
- Hotspot Detection: Functions consuming >90th percentile energy highlighted
Next Steps¶
- CLI Reference - All commands and options
- Configuration - Customize measurement settings
- Reports & Visualization - Energy timeline plots
- CI/CD Integration - Continuous energy monitoring