Assigned
Status Update
Comments
cc...@google.com <cc...@google.com> #2
Update: according to the trace, dex2oat starts at the same moment as the application. So i guess, the problem lays in xiaomi firmware that starts the optimization with the application during benchmark
sh...@gmail.com <sh...@gmail.com> #3
I have encountered the same issue, found the root cause and propose a fix below. I would have prepared a PR but according to the Contribution Guide, benchmark
is not open for contributions.
Root cause
Whenever there is only one counter value for a slice, powerUs
evaluates to NULL
because of division by 0 in
(max(c.value) - min(c.value))/((max(c.ts) - min(c.ts)) / 1000000) AS powerUs
which is a part of the power query (see
SELECT
t.name,
max(c.value) - min(c.value) AS energyUws,
(max(c.value) - min(c.value))/((max(c.ts) - min(c.ts)) / 1000000) AS powerUs
FROM counter c
JOIN counter_track t ON c.track_id = t.id
WHERE t.name GLOB 'power.*'
AND c.ts >= ${slice.ts} AND c.ts <= ${slice.endTs}
GROUP BY t.name
Which eventually leads to the NullPointerException
.
Fix
The fix is then to fallback to 0 for powerUs
if NULL
:
COALESCE((max(c.value) - min(c.value))/((max(c.ts) - min(c.ts)) / 1000000), 0) AS powerUs
Description
Component used: macrobenchmark Version used: 1.3.3 Devices/Android versions reproduced on: pixel 8 pro api 34
Macrobenchmark using PowerMetric randomly crashes after completing measurements. Most of the times (> 50%) it does work. I know that the feature is experimental, but maybe the report could help somehow
java.lang.NullPointerException: null cannot be cast to non-null type kotlin.Double at androidx.benchmark.macro.perfetto.PowerQuery$getRailMetrics$1.invoke(PowerQuery.kt:142) at androidx.benchmark.macro.perfetto.PowerQuery$getRailMetrics$1.invoke(PowerQuery.kt:138) at kotlin.sequences.TransformingSequence$iterator$1.next(Sequences.kt:210) at kotlin.sequences.SequencesKt___SequencesKt.toList(_Sequences.kt:811) at androidx.benchmark.macro.perfetto.PowerQuery.getRailMetrics(PowerQuery.kt:145) at androidx.benchmark.macro.perfetto.PowerQuery.getPowerMetrics(PowerQuery.kt:98) at androidx.benchmark.macro.PowerMetric.getPowerMetrics(Metric.kt:812) at androidx.benchmark.macro.PowerMetric.getMeasurements$benchmark_macro_release(Metric.kt:795) at androidx.benchmark.macro.MacrobenchmarkPhaseKt$runPhase$2$4.invoke(MacrobenchmarkPhase.kt:169) at androidx.benchmark.macro.MacrobenchmarkPhaseKt$runPhase$2$4.invoke(MacrobenchmarkPhase.kt:163) at androidx.benchmark.perfetto.PerfettoTraceProcessor.loadTrace(PerfettoTraceProcessor.kt:152) at androidx.benchmark.macro.MacrobenchmarkPhaseKt.runPhase(MacrobenchmarkPhase.kt:163) at androidx.benchmark.macro.MacrobenchmarkKt$macrobenchmark$4.invoke(Macrobenchmark.kt:267) at androidx.benchmark.macro.MacrobenchmarkKt$macrobenchmark$4.invoke(Macrobenchmark.kt:264) at androidx.benchmark.perfetto.PerfettoTraceProcessor$Companion.runServer-VtjQ1oo(PerfettoTraceProcessor.kt:133) at androidx.benchmark.perfetto.PerfettoTraceProcessor$Companion.runServer(PerfettoTraceProcessor.kt:108) at androidx.benchmark.macro.MacrobenchmarkKt.macrobenchmark(Macrobenchmark.kt:264) at androidx.benchmark.macro.MacrobenchmarkKt.macrobenchmarkWithStartupMode(Macrobenchmark.kt:401) at androidx.benchmark.macro.junit4.MacrobenchmarkRule.measureRepeated(MacrobenchmarkRule.kt:108) at androidx.benchmark.macro.junit4.MacrobenchmarkRule.measureRepeated$default(MacrobenchmarkRule.kt:99) at ...
I am using power metrics like this
@OptIn(ExperimentalMetricApi::class) @Test fun scrollPerformance() = benchmarkRule.measureRepeated( packageName = PACKAGE_NAME, metrics = listOf( FrameTimingMetric(), PowerMetric(PowerMetric.Type.Power()), PowerMetric(PowerMetric.Type.Energy()), PowerMetric(PowerMetric.Type.Battery()), MemoryUsageMetric(MemoryUsageMetric.Mode.Max), MemoryUsageMetric(MemoryUsageMetric.Mode.Last), ), iterations = 10, setupBlock = { killProcess() pressHome() startActivityAndWait() } ) { swipeMainFeed(times = 5) }