13

I configured a benchmark module and created a baseline profile for the project and saved it in the app according to the instructions here https://developer.android.com/studio/profile/baselineprofiles.

I've also added the benchmark:

@RunWith(AndroidJUnit4::class)
class BaselineProfileBenchmark {
    @get:Rule
    val benchmarkRule = MacrobenchmarkRule()

    @Test
    fun startupNoCompilation() {
        startup(CompilationMode.None())
    }

    @Test
    fun startupBaselineProfile() {
        startup(
            CompilationMode.Partial(
                baselineProfileMode = BaselineProfileMode.Require
            )
        )
    }

    private fun startup(compilationMode: CompilationMode) {
        benchmarkRule.measureRepeated(
            packageName = "com.example.app",
            metrics = listOf(StartupTimingMetric()),
            iterations = 10,
            startupMode = StartupMode.COLD,
            compilationMode = compilationMode
        ) {
            pressHome()
            startActivityAndWait()
        }
    }
}

startupBaselineProfile() test fails with an exception "Baseline profiles aren't supported on this device version". I tried to run it on different Pixel and Samsung devices with the latest Android version, but the same exception is thrown everywhere.

Do these baseline profiles wok at all?

mlykotom
  • 4,850
  • 1
  • 22
  • 27
Paul Chernenko
  • 696
  • 5
  • 21
  • 1
    What Android version have you run them? There's currently a bug with Android 12L (API 32). Could you try different OS version? If it's not that, then could you try latest version of profile installer, which is 1.2.0-alpha02? Thanks! – mlykotom Apr 08 '22 at 10:25
  • @mlykotom Do you have a link to the Android 12L bug you mentioned? I get the same error on a Pixel 3 running Android 12. – Graham Borland Apr 19 '22 at 15:06
  • 1
    Here's the bug you can track https://issuetracker.google.com/issues/228222110 – mlykotom Apr 20 '22 at 11:04
  • @mlykotom I was using version 1.0.4, switching to 1.2.0-alpha02 helps and it works on Android 12. Thanks! – Paul Chernenko Apr 20 '22 at 14:00
  • posted it as an answer you can accept if it answered your question :) – mlykotom Apr 21 '22 at 07:25

2 Answers2

12

Update October 2022

Use androidx.profileinstaller version 1.3.0-alpha01 or later that fixes the problem (or 1.2.1 when released).

Original Answer

Currently baseline profiles has some known issues:

  • can't benchmark them on Android 12L (Api 32) - b/228222110
  • you need latest alpha version of profileinstaller, which is 1.2.0-alpha02

Note, that the profileinstaller may be added with a library (e.g. jetpack compose) so make sure you add it to your dependencies to override the version.

mlykotom
  • 4,850
  • 1
  • 22
  • 27
3

Make sure to add the profileinstaller dependency to the target module (usually it's you app module)

implementation "androidx.profileinstaller:profileinstaller:1.2.0-beta01"
Georgy
  • 364
  • 2
  • 14