|
|
|
@ -19,45 +19,24 @@ package com.google.samples.apps.nowinandroid.startup
|
|
|
|
|
import androidx.benchmark.macro.BaselineProfileMode.Disable
|
|
|
|
|
import androidx.benchmark.macro.BaselineProfileMode.Require
|
|
|
|
|
import androidx.benchmark.macro.CompilationMode
|
|
|
|
|
import androidx.benchmark.macro.StartupMode
|
|
|
|
|
import androidx.benchmark.macro.StartupMode.COLD
|
|
|
|
|
import androidx.benchmark.macro.StartupMode.HOT
|
|
|
|
|
import androidx.benchmark.macro.StartupMode.WARM
|
|
|
|
|
import androidx.benchmark.macro.StartupTimingMetric
|
|
|
|
|
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
|
|
|
|
|
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
|
|
|
|
|
import com.google.samples.apps.nowinandroid.PACKAGE_NAME
|
|
|
|
|
import com.google.samples.apps.nowinandroid.allowNotifications
|
|
|
|
|
import com.google.samples.apps.nowinandroid.foryou.forYouWaitForContent
|
|
|
|
|
import org.junit.Rule
|
|
|
|
|
import org.junit.Test
|
|
|
|
|
import org.junit.runner.RunWith
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Enables app startups from various states of baseline profile or [CompilationMode]s.
|
|
|
|
|
* Run this benchmark from Studio to see startup measurements, and captured system traces
|
|
|
|
|
* for investigating your app's performance from a cold state.
|
|
|
|
|
*/
|
|
|
|
|
@RunWith(AndroidJUnit4ClassRunner::class)
|
|
|
|
|
class ColdStartupBenchmark : AbstractStartupBenchmark(COLD)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Run this benchmark from Studio to see startup measurements, and captured system traces
|
|
|
|
|
* for investigating your app's performance from a warm state.
|
|
|
|
|
*/
|
|
|
|
|
@RunWith(AndroidJUnit4ClassRunner::class)
|
|
|
|
|
class WarmStartupBenchmark : AbstractStartupBenchmark(WARM)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Run this benchmark from Studio to see startup measurements, and captured system traces
|
|
|
|
|
* for investigating your app's performance from a hot state.
|
|
|
|
|
*/
|
|
|
|
|
@RunWith(AndroidJUnit4ClassRunner::class)
|
|
|
|
|
class HotStartupBenchmark : AbstractStartupBenchmark(HOT)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Base class for benchmarks with different startup modes.
|
|
|
|
|
* Enables app startups from various states of baseline profile or [CompilationMode]s.
|
|
|
|
|
*/
|
|
|
|
|
abstract class AbstractStartupBenchmark(private val startupMode: StartupMode) {
|
|
|
|
|
class StartupBenchmark {
|
|
|
|
|
@get:Rule
|
|
|
|
|
val benchmarkRule = MacrobenchmarkRule()
|
|
|
|
|
|
|
|
|
@ -80,9 +59,10 @@ abstract class AbstractStartupBenchmark(private val startupMode: StartupMode) {
|
|
|
|
|
metrics = listOf(StartupTimingMetric()),
|
|
|
|
|
compilationMode = compilationMode,
|
|
|
|
|
iterations = 10,
|
|
|
|
|
startupMode = startupMode,
|
|
|
|
|
startupMode = COLD,
|
|
|
|
|
setupBlock = {
|
|
|
|
|
pressHome()
|
|
|
|
|
allowNotifications()
|
|
|
|
|
},
|
|
|
|
|
) {
|
|
|
|
|
startActivityAndWait()
|
|
|
|
|