Skip to content

Commit 7f335a9

Browse files
committed
feat(macrobenchmark): Measure SentryAndroid.init as its own metric
SentryAndroid.init wraps itself in an android.os.Trace section (#5901), and macrobenchmark sets atrace_apps=["*"] on API 29+, so the section reaches the perfetto trace on the api-35 device we run. TraceSectionMetric turns it into a reported metric. This is the metric worth watching: timeToInitialDisplay measures the whole cold start, so an SDK-init change has to be tens of milliseconds to clear the noise, while this isolates init itself.
1 parent 0549454 commit 7f335a9

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

  • sentry-android-integration-tests/sentry-uitest-android-macrobenchmark/src/main/java/io/sentry/uitest/android/macrobenchmark

‎sentry-android-integration-tests/sentry-uitest-android-macrobenchmark/src/main/java/io/sentry/uitest/android/macrobenchmark/SentryStartupBenchmark.kt‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package io.sentry.uitest.android.macrobenchmark
22

33
import android.util.Log
44
import androidx.benchmark.macro.CompilationMode
5+
import androidx.benchmark.macro.ExperimentalMetricApi
56
import androidx.benchmark.macro.StartupMode
67
import androidx.benchmark.macro.StartupTimingMetric
8+
import androidx.benchmark.macro.TraceSectionMetric
79
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
810
import androidx.test.ext.junit.runners.AndroidJUnit4
911
import androidx.test.platform.app.InstrumentationRegistry
@@ -33,11 +35,17 @@ class SentryStartupBenchmark {
3335

3436
@get:Rule val benchmarkRule = MacrobenchmarkRule()
3537

38+
@OptIn(ExperimentalMetricApi::class)
3639
@Test
3740
fun startupFullCompilation() =
3841
benchmarkRule.measureRepeated(
3942
packageName = TARGET_PACKAGE,
40-
metrics = listOf(StartupTimingMetric()),
43+
// TraceSectionMetric picks up the android.os.Trace section SentryAndroid.init wraps
44+
// itself in. The sample app auto-inits from its ContentProvider, so this lands inside
45+
// the cold-start window being measured. Unlike timeToInitialDisplay this isolates SDK
46+
// startup from the rest of the app, so a regression shows up without having to clear
47+
// cold-start noise.
48+
metrics = listOf(StartupTimingMetric(), TraceSectionMetric(SENTRY_INIT_SECTION)),
4149
compilationMode = CompilationMode.Full(),
4250
startupMode = StartupMode.COLD,
4351
iterations = 12,
@@ -48,6 +56,10 @@ class SentryStartupBenchmark {
4856

4957
companion object {
5058
private const val TARGET_PACKAGE = "io.sentry.samples.android"
59+
60+
/** Matches the `Trace.beginSection` name in `SentryAndroid.init`. */
61+
private const val SENTRY_INIT_SECTION = "SentryAndroid.init"
62+
5163
private const val BENCHMARK_DATA_SUFFIX = "-benchmarkData.json"
5264

5365
/** Kept in sync with `scripts/parse-macrobenchmark-log.py`. */

0 commit comments

Comments
 (0)