↓ Skip to main content

Measuring GPU power, not just jank

·12 mins

Since Haze 2.1, nearby Glass surfaces inside a hazeGlassContainer can smoothly blend into one shared shape, with refraction and lighting following the joined outline. In Haze’s Glass benchmarks on a Pixel 8a, merging two of them roughly doubled GPU power at both 60 Hz and 120 Hz, and adding more members pushed it higher:

60 Hz120 Hz
Two independent surfaces47 mW97 mW
Two-member container101–103 mW193 mW
Four-member container143–147 mW271 mW

By the usual frame-timing measures, containers looked fine. The benchmarks ran on an Android 17 developer preview, and keep the Glass still while the content behind it changes, so the effect has to redraw on every frame. Macrobenchmark’s FrameTimingMetric reports CPU frame duration (frameDurationCpuMs) and deadline overrun (frameOverrunMs, from Android 12). On CPU time, containers even looked slightly cheaper: in frames where the main thread and RenderThread both ran on the little CPU cores, their median RenderThread time was 1.15 ms lower than for independent surfaces, with no Glass-caused jank even at 120 Hz (the few flagged frames were system-side).

This post covers how to measure that GPU cost in your own app, using Haze’s Glass containers as the example.

Why frame time can’t see it
#

frameDurationCpuMs measures the CPU side of a frame: how long the main thread and RenderThread took to produce it. The GPU does its work afterwards. frameOverrunMs measures when each frame completed against its deadline, so it can show the margin shrinking, say from 5 ms early to 2 ms early, before any frame is late. But it reports time, not cost. When GPU work gets heavier, the GPU governor raises the clock to keep frames on time, and the GPU uses more power to do it.

That’s what happened here. At 120 Hz, a four-member container looked likely to become GPU-bound and jank, yet the governor kept frames on time by scaling up the GPU clock:

60 Hz120 Hz
Two independent surfaces76 MHz~200 MHz
Two-member container110 MHz~280 MHz
Four-member container174 MHz~370 MHz

So the extra work isn’t free. You pay for it in battery and in GPU headroom, which isn’t there when something else needs it. On a device with less headroom, the same work could start dropping frames, although I only had one device to measure.

There’s a useful signal in between. HWUI waits for each frame’s GPU work to finish on a thread called “GPU completion”, and containers roughly doubled that wait.

Measuring it in your app
#

Power rails
#

Pixel phones from the Pixel 6 onwards have an On-Device Power Rails Monitor (ODPM). It tracks energy for each subsystem, called a rail: CPU clusters, memory, the display, the GPU and more. It needs Android 10 or higher, and some rails only exist on some devices. You don’t need root to read it through Android Studio, Perfetto or Macrobenchmark.

Two things to know before you use it. First, it measures the whole device, not your app, so anything else running ends up in your numbers. Second, each rail is an energy counter. To get power, take the change in energy over a window and divide by the window’s length. Every power number in this post is that: the average power of the GPU rail while a benchmark ran.

Other manufacturers can expose power rails too, but Perfetto’s docs say whether they do, and at what resolution, is up to the manufacturer.

Look first: Android Studio and Perfetto
#

The quickest way to see whether a screen moves the GPU rail is Android Studio’s Power Profiler, available since Hedgehog. It shows the rails, grouped by subsystem, on the profiler’s timeline.

For more detail, record a Perfetto trace with power rails enabled, plus the gfx ATrace category for the GPU wait and the GPU frequency event, so you can see the governor at work:

buffers {
  size_kb: 102400
  fill_policy: RING_BUFFER
}
duration_ms: 10000
data_sources {
  config {
    name: "android.power"
    android_power_config {
      battery_poll_ms: 250
      collect_power_rails: true
    }
  }
}
data_sources {
  config {
    name: "linux.ftrace"
    ftrace_config {
      ftrace_events: "power/gpu_frequency"
      atrace_categories: "gfx"
    }
  }
}

Save it as gpu_power.pbtx and record 10 seconds of your interaction with Perfetto’s record_android_trace script, which opens the trace in the Perfetto UI when it finishes:

curl -O https://raw.githubusercontent.com/google/perfetto/main/tools/record_android_trace
python3 record_android_trace -c gpu_power.pbtx -o gpu_power.perfetto-trace

In the Pixel 8a’s traces, the GPU rail appears as power.rails.gpu (check your own device’s track names, as Perfetto’s docs don’t list them). Because it counts energy, subtract two samples inside your interaction in the Perfetto UI (in µJ) and divide by the seconds between them to get µW, or query it with trace processor. Haze’s window.sql automates this across every rail for a Macrobenchmark trace (change its measureBlock slice and package filter for your app).

The gfx category brings in the GPU wait: HWUI’s “GPU completion” thread waits on each frame’s GPU work via Fence::waitForever, so filter waitForever slices to that thread in your app. Don’t rely on HWUI’s own gpu_duration and “Reported gpu duration” counters: on this preview build, both read 0.

Track it: Macrobenchmark
#

A trace shows whether there’s a cost; a benchmark catches it changing. Macrobenchmark’s PowerMetric reads the same rails, and TraceSectionMetric sums the GPU wait (androidx.benchmark:benchmark-macro-junit4, see the setup guide):

@get:Rule
val benchmarkRule = MacrobenchmarkRule()

@OptIn(ExperimentalMetricApi::class)
@Test
fun scrollFeed() = benchmarkRule.measureRepeated(
  packageName = "com.example.app",
  metrics = buildList {
    add(FrameTimingMetric())
    // HWUI's "GPU completion" thread waits on each frame's GPU fence here.
    add(TraceSectionMetric("waitForever", TraceSectionMetric.Mode.Sum, label = "gpuCompletionWait"))
    if (PowerMetric.deviceSupportsHighPrecisionTracking()) {
      add(PowerMetric(PowerMetric.Power(mapOf(PowerCategory.GPU to PowerCategoryDisplayLevel.BREAKDOWN))))
    }
  },
  iterations = 8,
  setupBlock = { startActivityAndWait() },
) {
  // The interaction you want to measure.
}

A few non-obvious details:

  • Device support: PowerMetric is experimental, needs API 29, and requires power rails (Pixel 6 and newer in its docs). Guarding with deviceSupportsHighPrecisionTracking() lets the benchmark still record frame timing and GPU wait on other devices.
  • Units: powerComponentGpuUw is named for microwatts, but in androidx.benchmark 1.6.0-alpha02 it reports milliwatts (Haze’s first iteration logged 43.593 while the trace’s GPU rail averaged 43,593 µW).
  • Breakdown: BREAKDOWN reports each rail separately: powerComponentGpuUw covers power.rails.gpu alone, and powerComponentGpuL2Uw covers the GPU’s L2 cache on the Pixel 8a (TOTAL sums them into powerCategoryGpuUw).
  • GPU wait: Mode.Sum outputs gpuCompletionWaitSumMs and gpuCompletionWaitCount. Because TraceSectionMetric matches by app rather than thread, verify in one trace that the slices sit on “GPU completion” and match your frame count (in Haze, 181 slices for 180 frames matched a thread-filtered query).

Haze’s Glass benchmarks now record GPU power and GPU wait through #1979, and every iteration’s powerComponentGpuUw matched power.rails.gpu from the same trace. GPU wait has a catch, though: because it’s time, a higher clock can mask extra work. In another 60 Hz session:

BenchmarkGPU powerGPU wait per frame
Two independent surfaces43.3 mW4.13 ms
Two-member container100.7 mW8.26 ms
Four-member container146.4 mW8.32 ms

Two- and four-member containers waited almost the same while GPU power rose 45%, consistent with the clock climbing from 110 to 174 MHz.

Comparing builds
#

Absolute power varies with the device, session and temperature, so compare builds against a control in the same session. On the Pixel 8a, that took:

  • Fixed-performance mode: Enable adb shell cmd power set-fixed-performance-mode-enabled true. Even with it on, this Pixel 8a didn’t lock the GPU clock or pin CPU threads: the 60 Hz and 120 Hz clock jumps and little-core timings above were all recorded under it.
  • Randomised same-round pairs: Run builds in random order per round (median of 8 iterations) and compare each build against the control from its own round.
  • A cool, quiet device: Wait until the battery is ≤ 30 °C between invocations, and stop noisy background apps. On the Android 17 preview, the Google app could stall Perfetto unless disabled.
  • Every rail, not just the GPU: Sum CPU and whole-device rails when a change could shift work off the GPU, and rerun anything surprising.

Haze’s GPU-power A/B scripts do some of this for its Glass benchmarks. They install each build’s APK under one fixed benchmark APK, turn on fixed-performance mode, disable the Google app, wait for the battery to cool before each run, and report every build against the control from its round. The schedule of rounds is yours to write, and the report only shows GPU power.

Even with paired rounds, the control drifts between rounds: across 10 rounds, it spread 6.4% (two members), 6.8% (four members) and 16.0% (two independent surfaces). Read paired results round by round rather than by average alone: #1991 cut two-member GPU power by only 2.8% (within the 4.9% control spread of its own four-round session), yet beat its same-round control in all four rounds without changing a pixel.

Narrowing down where the power goes
#

Knowing a screen uses more GPU power doesn’t tell you why. On Haze, three steps isolated it.

Rule out render passes and area
#

A two-member container ran 7 render passes (Skia’s OpsTasks) per frame against 13 for two independent surfaces, over a similar total area (966×759 px vs 2 × 525×622 px, about 12% more pixels). Fewer passes over roughly the same pixel count couldn’t explain doubling GPU power, which pointed at the work inside each pixel.

Estimate shader cost offline
#

Arm’s Mali Offline Compiler (malioc) on an approximate GLSL translation of Haze’s AGSL shaders confirmed that per-pixel cost (the Pixel 8a’s GPU is an Arm Mali-G715):

ShaderArithmeticLoad/storeRegister spill
Independent8.9 cycles0 cycles0 B
Merged (longest path)61 cycles143 cycles280 B

Every merged pixel loops over all container members to compute distance, weights, optics, sample offset and lighting, which is why four members cost more than two.

Measure ceilings with removal variants
#

malioc estimates static cycle counts, not milliwatts on a live frame. Before investing in a real fix, build a quick variant with the suspected work stripped out and measure it against the control to see the ceiling:

VariantTwo membersFour membersNotes
Strip merged features at once−37%−43%Combined ceiling for shader fixes
Skip idle members (compiled out)−11.9%−10.3%Theoretical ceiling
Skip idle members (runtime branch)−2.7%−1.1%Within noise; dropped
Compile out unused standalone paths~−5%~−2%GPU L2 rail fell 26% / 21%, but GPU power barely moved

Two rows saved wasted effort early. Skipping idle members looked promising when compiled out of the shader, yet guarding the same work with a runtime branch saved almost nothing on the GPU. And stripping unused standalone code from the merged shader cut GPU L2 cache power by over 20% while barely moving the main GPU rail.

What landed
#

Using those measurements, three changes landed on main for the next Haze release (60 Hz GPU power, each measured against its own control):

PRChangeTwo membersFour members
#1988Exact circular-corner gradient−9.1%−12.5%
#1991Shared gradient for refraction and lighting−2.8%−4.8%
#1992Retained rim layer between frames (9.3 MB GPU memory)−8.6%−15.9%

PRs #1988 and #1991 apply to circular-corner containers, which these benchmarks measure; Haze 2.2’s continuous-corner merged shaders keep central-difference gradients because they sit close to Android 15’s program-size limit. PR #1992 retains the settled rim on Android regardless of corner shape.

There isn’t a single same-session run comparing pre-fix code directly with main. Across separate 60 Hz sessions on the Pixel 8a:

BenchmarkPre-fixAfter #1992Change
Two independent surfaces47.4 mW43.9 mW−7%
Two-member container103.3 mW79.5 mW−23%
Four-member container144.5 mW106.9 mW−26%

Relative to independent surfaces, the merging premium dropped from 2.18× to 1.81× for two members and from 3.05× to 2.44× for four. Merging still carries a real GPU cost, so use hazeGlassContainer where surfaces actually need to merge.

The softer rim
#

The first version of #1992 looked better on the power numbers, and worse on screen.

It cached the rim at the effect’s input resolution. In Haze’s default Balanced mode, that’s about 0.79× full resolution. At two members it saved 9.8%, more than the version that shipped. But it softened the rim’s edges. The largest pixel difference was 37/255, and 1,998 pixels changed by more than 8/255.

Three crops of a Glass container's top-left corner on a dark blue background. The left and middle crops look almost the same. The right crop is black except for a bright line tracing the rounded corner and top edge.
Left: the rim drawn directly. Middle: the rim cached at the effect’s input resolution. Right: their difference, amplified 8×. Click to zoom.

The version that shipped caches at screen resolution instead. Its largest difference is 21/255, and all 610 pixels that changed by more than 8/255 are on the rim’s edge, consistent with compositing an 8-bit texture at a subpixel position.

Going by power alone, the softer version would have looked like the better fix at two members. When you trade quality for power, check the pixels too.

The saving that cost more
#

The next idea was to bake the settled shape’s distance, gradient and thickness into a texture on the CPU so the shader only reads the texture. Measured against Haze’s main branch, it cut GPU power by 12.1% for two members and 17.1% for four in every round, with no visible change.

By the GPU rail alone, that’s a win. Because baking moves work to the CPU, the CPU and whole-device rails in the same traces matter too. Here they are across two benchmarks where a container settles repeatedly:

BenchmarkGPUCPUWhole device
Press−0.7 mW+381 mW+397 mW (+29%)
Join and leave+2.1 mW+502 mW+537 mW (+40%)

The bakes ran on the Pixel 8a’s fastest CPU core, and giving the bake thread background priority didn’t move most of the work off it. Baking at half resolution and reusing textures cut the extra whole-device cost to +75 mW and +130 mW, but every settle still cost more than it saved. Even with the Glass settled and only the content behind it changing, where the GPU saved 10–22 mW, the CPU rails rose by at least as much. It hasn’t shipped.

GPU power is one rail. When a change moves work somewhere else, add up every rail, not just the GPU’s.

Limits
#

All of these numbers come from one Pixel 8a on an Android 17 developer preview. The milliwatts are specific to that hardware and session, so don’t compare them across phones, and Perfetto’s docs note that power-rail hardware still “is not yet available on most production phones”.

What transfers is how the signals fit together. Frame timing tells you when you miss a deadline. GPU wait shows the GPU working harder until the governor raises the clock. Power rails show what keeping those frames on time actually costs, as long as you check the other rails and the pixels too.