Skip to content

add time-weighted power statistics analysis stage - #81

Merged
lasch merged 1 commit into
mainfrom
power
Feb 10, 2026
Merged

lasch merged 1 commit into
mainfrom
power

Conversation

@WarningRan

Copy link
Copy Markdown
Collaborator

Add Power Statistics Analysis Pipeline Stage

Summary

This PR introduces a new pipeline stage to analyze power consumption statistics. It provides time-weighted insights by correlating power counter data with kernel execution timelines, allowing for a clear distinction between "active computation" and "idle" power profiles.

Key Features

  • Scenario-Based Analysis: Automatically separates statistics for periods with and without kernel execution (identified by Cmpt Exec).
  • Time-Weighted Calculations: Prevents statistical bias from non-uniform sampling frequencies by weighting power values by their duration.
  • Dual-Perspective Metrics:
    • Non-Zero (NZ) Metrics: Focuses on "operational" power by excluding zero values (e.g., mean_non_zero, median_non_zero).
    • Total Average: Includes all samples (including zeros) to represent the true energy footprint (avg_total).
  • Command-Line Integration: Controlled via the new --power-stats flag.

Output Example

INFO Power with kernels: min_non_zero=6.52W, max=99.69W, mean_non_zero=36.09W, median_non_zero=35.77W, avg_total=35.96W (time-weighted, dur_total=115598.64ms, dur_non_zero=115171.07ms)
INFO Power without kernels: min_non_zero=6.52W, max=99.69W, mean_non_zero=11.09W, median_non_zero=11.08W, avg_total=11.09W (time-weighted, dur_total=908597.91ms, dur_non_zero=908573.36ms)

Implementation Details

Core Algorithm: Period Splitting

The implementation employs a "Timeline Slicing" approach:

  1. Power Period Construction: Converts instantaneous counter samples into continuous duration blocks.
  2. Kernel Timeline Merging: Merges overlapping kernel events to create a canonical "Busy" timeline.
  3. Fragmenting: Slices each power block by the kernel timeline to categorize energy usage accurately.

Metrics Definition

  • mean_non_zero: Weighted Mean = sum(Power_nz * Duration_nz) / sum(Duration_nz). It reflects hardware intensity during active/powered states.
  • avg_total: The true time-weighted average including zeros. Essential for total energy (Energy = Average_Power * Total_Time) calculations.

Changes

  • New Analysis Module: Created power_stats.py containing PowerStatisticsContext and the core analysis logic.
  • CLI & Pipeline Integration: Added --power-stats argument to acelyzer.py and registered the new stage in the event pipeline.
  • Pipeline Exposure: Updated pipeline/__init__.py to export the new context and dispatch functions.
  • Profile Updates:
  • Enabled the analysis by default in everything.json.
  • Added the entry to torch_minimal.json (disabled by default) for consistency.

Usage

To enable power statistics in your trace analysis:

acelyzer -i trace.json --power-stats

@WarningRan WarningRan added the enhancement New feature or request label Feb 4, 2026

@lasch lasch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @WarningRan
A self-contained stage to extract power stats. 👍

A few of the items in the drain() for-loops (e.g. Step 1) might be possible to move into the same function that collects the power_counters (might require changing the position of the overall pipeline step to a place after events are sorted by time stamp. That could remove the need to do the extra sorting and get rid of that first for loop.)

But that's functional sugar and optimization like that can be done later.

May I ask you to address the flake8 warnings. They're currently passing the tests but a pending PR #82 will enforce the code formatting and this could then force other people to fix code formatting for changes they didn't make.

@WarningRan
WarningRan force-pushed the power branch 2 times, most recently from 4b98a24 to 186352d Compare February 9, 2026 16:12
Signed-off-by: Zhuoran-Liu <zhuoran.liu@ibm.com>
@lasch
lasch merged commit 4d75f8f into main Feb 10, 2026
2 checks passed
@lasch
lasch deleted the power branch February 10, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants