Skip to content

Add first alpha of App Startup Insights #296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MacrobenchmarkSample/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
agp = "8.5.2"
activity = "1.9.2"
appcompat = "1.7.0"
benchmark = "1.3.1"
benchmark = "1.4.0-alpha01"
composeBom = "2024.09.02"
constraintLayout = "2.1.4"
core = "1.13.1"
Original file line number Diff line number Diff line change
@@ -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 {

@@ -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,
Original file line number Diff line number Diff line change
@@ -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
@@ -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,
) {
Original file line number Diff line number Diff line change
@@ -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
@@ -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,
@@ -73,7 +75,6 @@ abstract class AbstractStartupBenchmark(private val startupMode: StartupMode) {
)

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

@@ -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,
@@ -92,4 +94,4 @@ abstract class AbstractStartupBenchmark(private val startupMode: StartupMode) {
) {
startActivityAndWait()
}
}
}