Skip to content

Commit

Permalink
Enable App Startup Insights for startup benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
keyboardsurfer committed Oct 1, 2024
1 parent d272bad commit 97be938
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,26 @@ package com.example.macrobenchmark.benchmark

import android.content.Intent
import android.os.Bundle
import androidx.benchmark.ExperimentalBenchmarkConfigApi
import androidx.benchmark.ExperimentalConfig
import androidx.benchmark.StartupInsightsConfig
import androidx.benchmark.macro.CompilationMode
import androidx.benchmark.macro.FrameTimingMetric
import androidx.benchmark.macro.MacrobenchmarkScope
import androidx.benchmark.macro.StartupMode
import androidx.benchmark.macro.StartupTimingMetric
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
import androidx.benchmark.perfetto.ExperimentalPerfettoCaptureApi
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.uiautomator.By
import com.example.macrobenchmark.benchmark.permissions.allowNotifications
import com.example.macrobenchmark.benchmark.util.DEFAULT_ITERATIONS
import com.example.macrobenchmark.benchmark.util.TARGET_PACKAGE
import com.example.macrobenchmark.benchmark.permissions.allowNotifications
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@OptIn(ExperimentalBenchmarkConfigApi::class, ExperimentalPerfettoCaptureApi::class)
@RunWith(AndroidJUnit4::class)
class LoginBenchmark {

Expand Down Expand Up @@ -89,6 +94,7 @@ class LoginBenchmark {
packageName = TARGET_PACKAGE,
metrics = listOf(StartupTimingMetric(), FrameTimingMetric()),
compilationMode = CompilationMode.DEFAULT,
experimentalConfig = ExperimentalConfig(startupInsightsConfig = StartupInsightsConfig(true)),
startupMode = StartupMode.COLD,
iterations = DEFAULT_ITERATIONS,
setupBlock = setupBlock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
package com.example.macrobenchmark.benchmark.startup

import android.content.Intent
import androidx.benchmark.ExperimentalBenchmarkConfigApi
import androidx.benchmark.ExperimentalConfig
import androidx.benchmark.StartupInsightsConfig
import androidx.benchmark.macro.StartupMode
import androidx.benchmark.macro.StartupTimingMetric
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
import androidx.benchmark.perfetto.ExperimentalPerfettoCaptureApi
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import androidx.test.uiautomator.By
Expand All @@ -36,10 +40,12 @@ class FullyDrawnStartupBenchmark {
@get:Rule
val benchmarkRule = MacrobenchmarkRule()

@OptIn(ExperimentalBenchmarkConfigApi::class, ExperimentalPerfettoCaptureApi::class)
@Test
fun startup() = benchmarkRule.measureRepeated(
packageName = TARGET_PACKAGE,
metrics = listOf(StartupTimingMetric()),
experimentalConfig = ExperimentalConfig(startupInsightsConfig = StartupInsightsConfig(true)),
startupMode = StartupMode.COLD,
iterations = DEFAULT_ITERATIONS,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@

package com.example.macrobenchmark.benchmark.startup

import androidx.benchmark.ExperimentalBenchmarkConfigApi
import androidx.benchmark.ExperimentalConfig
import androidx.benchmark.StartupInsightsConfig
import androidx.benchmark.macro.BaselineProfileMode
import androidx.benchmark.macro.CompilationMode
import androidx.benchmark.macro.StartupMode
import androidx.benchmark.macro.StartupTimingMetric
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
import androidx.test.filters.SdkSuppress
import androidx.benchmark.perfetto.ExperimentalPerfettoCaptureApi
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
import com.example.macrobenchmark.benchmark.util.DEFAULT_ITERATIONS
import com.example.macrobenchmark.benchmark.util.TARGET_PACKAGE
Expand Down Expand Up @@ -55,16 +58,15 @@ class HotStartupBenchmark : AbstractStartupBenchmark(StartupMode.HOT)
* Base class for benchmarks with different startup modes.
* Enables app startups from various states of baseline profile or [CompilationMode]s.
*/
@OptIn(ExperimentalBenchmarkConfigApi::class, ExperimentalPerfettoCaptureApi::class)
abstract class AbstractStartupBenchmark(private val startupMode: StartupMode) {
@get:Rule
val benchmarkRule = MacrobenchmarkRule()

@Test
@SdkSuppress(minSdkVersion = 24)
fun startupNoCompilation() = startup(CompilationMode.None())

@Test
@SdkSuppress(minSdkVersion = 24)
fun startupPartialCompilation() = startup(
CompilationMode.Partial(
baselineProfileMode = BaselineProfileMode.Disable,
Expand All @@ -73,7 +75,6 @@ abstract class AbstractStartupBenchmark(private val startupMode: StartupMode) {
)

@Test
@SdkSuppress(minSdkVersion = 24)
fun startupPartialWithBaselineProfiles() =
startup(CompilationMode.Partial(baselineProfileMode = BaselineProfileMode.Require))

Expand All @@ -83,6 +84,7 @@ abstract class AbstractStartupBenchmark(private val startupMode: StartupMode) {
private fun startup(compilationMode: CompilationMode) = benchmarkRule.measureRepeated(
packageName = TARGET_PACKAGE,
metrics = listOf(StartupTimingMetric()),
experimentalConfig = ExperimentalConfig(startupInsightsConfig = StartupInsightsConfig(true)),
compilationMode = compilationMode,
iterations = DEFAULT_ITERATIONS,
startupMode = startupMode,
Expand All @@ -92,4 +94,4 @@ abstract class AbstractStartupBenchmark(private val startupMode: StartupMode) {
) {
startActivityAndWait()
}
}
}

0 comments on commit 97be938

Please sign in to comment.