androidperformancebaseline-profilemacrobenchmarkcompilationmode

Android application with baselineprofile macro benchmark is failing with profileinstaller library issue


I am trying to improve performance for my application by trying baseprofile but unable to run it. Configured the project with gradle 8.2 and

'androidx.profileinstaller:profileinstaller:1.3.1'
'androidx.benchmark:benchmark-macro-junit4:1.2.2'

I was able to generate baseline-prof.txt using emulator but could not test performance by running the benchmark snippet

@RunWith(AndroidJUnit4::class)
@LargeTest
class StartupBenchmarks {

    @get:Rule
    val rule = MacrobenchmarkRule()

    @Test
    fun startupCompilationNone() =
        benchmark(CompilationMode.None())

    @Test
    fun startupCompilationBaselineProfiles() =
        benchmark(CompilationMode.Partial(BaselineProfileMode.Require))

    private fun benchmark(compilationMode: CompilationMode) {
        rule.measureRepeated(
            packageName = "com.example.android",
            metrics = listOf(StartupTimingMetric()),
            compilationMode = compilationMode,
            startupMode = StartupMode.COLD,
            iterations = 1,
            setupBlock = {
                pressHome()
            },
            measureBlock = {
                startActivityAndWait()
                device.wait(Until.hasObject(By.text("Exit")),10_000)
            }
        )
    }
}

Getting the below errors for the benchmark tests

startupCompilationNone()

java.lang.RuntimeException: The baseline profile install broadcast was not received. This most likely means that the profileinstaller library is missing from the target apk.

startupCompilationBaselineProfiles()

java.lang.IllegalStateException: The DROP_SHADER_CACHE broadcast was not received. This most likely means that the `androidx.profileinstaller` library used by the target apk is old. Please use `1.3.0-alpha02` or newer. For more information refer to the release notes at https://developer.android.com/jetpack/androidx/releases/profileinstaller.

Not sure what is going wrong, I am trying with all the latest available libs and also tested with multiple devices Pixel, motoE, OnePlus with disabling battery optimization.

Any direction of help is highly appreciated


Solution

  • The issue was unrelated to the above error. The profileinstaller issue getting in Test results tab was misleading. Found there was a proguard TypeToken issue in gson. Adding the below lines in progaurd fixed the issue

    -keep class com.google.gson.reflect.TypeToken
    -keep class * extends com.google.gson.reflect.TypeToken
    -keep public class * implements java.lang.reflect.Type