Status Update
Comments
cc...@google.com <cc...@google.com> #2
Thank you for the report.
When the compile time fluctuate this much, it could be caused by the JVM getting close to max memory and the GC portion of the compile time goes up.
As you have a dump, then you can easily reproduce the same build with different settings using tools/compiledump.py
. tools/compiledump.py
use the curl -O https://storage.googleapis.com/r8-releases/raw/8.3.35/r8lib.jar
(for version 8.3.35), and then add --r8-jar r8lib.jar
to the commands below. The commands all pass -da
which disables assertions. tools/compiledump.py
enabled assertions by default, but that makes compilation even slower, and AGP does not do that.
- Are you seeing the same loooooong compile time locally when running
tools/compiledump.py -da -d <dump>
? - If so you can try to pass the
-verbose:gc
to the JVM when running, should be doable like this:tools/compiledump.py -da -J=-verbose:gc -d <dump>
. Seems like the output is not streamed so you will have to wait for the command to finish. - If that shows massive GC, you can try different heap sizes, to see if changing that affects compilation time, e.g. like this:
tools/compiledump.py -da --xmx 8G -J=-verbose:gc -d <dump>
If possible you can share the dump privately with
sh...@gmail.com <sh...@gmail.com> #3
The CI calculates the values for xmx etc... depending on the current machine. The one use here should have enough resources to build the app without issues.
This is what it calculated for this particular machine, which has 32 GB of RAM (properties written inside of ~/.gradle/gradle.proprties
).
org.gradle.jvmargs = -Dfile.encoding=UTF-8 -XX:+HeapDumpOnOutOfMemoryError -XX:MaxMetaspaceSize=1g -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -Xmx16854m -Xms16854m
kotlin.daemon.jvmargs = -Dfile.encoding=UTF-8 -XX:+HeapDumpOnOutOfMemoryError -XX:MaxMetaspaceSize=1g -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -Xmx7223m -Xms7223m
I let gradle and kotlin use 75% of the total memory, 70% of that is for gradle, the remaining 30% for kotlin.
I once ran the build with -Dcom.android.tools.r8.printmemory
, but the CI stopped after it reached its limit of 3.5 hours. This is what I saw:
R8 is running with total memory:17683185664
R8 is running with free memory:14891000672
R8 is running with max memory:17683185664
I have multiple zips inside the directory of dumpinputtodirectory
and compiledump.py
takes roughly 10 minutes to process the largest one. Even when I pass --Xmx 8G
.
I'll try to play a bit with the memory settings and see if that's the problem, as you suspect. I could also try to run R8 in a separate process as mentioned
I'll try to can figure this out and I'll see if I can share the dump in case I can't find anything.
Thank you for the prompt response.
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) }