From 5d158ce441e68b1779d51108dbb2560f61d60596 Mon Sep 17 00:00:00 2001 From: Ben Weiss Date: Mon, 2 Oct 2023 11:05:50 +0200 Subject: [PATCH] Add TraceSectionMetric sample --- .../macrobenchmark/startup/SampleStartupBenchmark.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/MacrobenchmarkSample/macrobenchmark/src/main/java/com/example/macrobenchmark/startup/SampleStartupBenchmark.kt b/MacrobenchmarkSample/macrobenchmark/src/main/java/com/example/macrobenchmark/startup/SampleStartupBenchmark.kt index d3e8c4cb..5c2cac95 100644 --- a/MacrobenchmarkSample/macrobenchmark/src/main/java/com/example/macrobenchmark/startup/SampleStartupBenchmark.kt +++ b/MacrobenchmarkSample/macrobenchmark/src/main/java/com/example/macrobenchmark/startup/SampleStartupBenchmark.kt @@ -16,7 +16,10 @@ package com.example.macrobenchmark.startup +import androidx.benchmark.macro.ExperimentalMetricApi import androidx.benchmark.macro.StartupTimingMetric +import androidx.benchmark.macro.TraceSectionMetric +import androidx.benchmark.macro.TraceSectionMetric.Mode import androidx.benchmark.macro.junit4.MacrobenchmarkRule import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.LargeTest @@ -33,10 +36,17 @@ class SampleStartupBenchmark { @get:Rule val benchmarkRule = MacrobenchmarkRule() + @OptIn(ExperimentalMetricApi::class) @Test fun startup() = benchmarkRule.measureRepeated( packageName = TARGET_PACKAGE, - metrics = listOf(StartupTimingMetric()), + metrics = listOf( + StartupTimingMetric(), + TraceSectionMetric("activityStart", Mode.First), + TraceSectionMetric("activityResume", Mode.First), + TraceSectionMetric("Choreographer#doFrame %", Mode.Sum), + + ), iterations = DEFAULT_ITERATIONS, setupBlock = { // Press home button before each run to ensure the starting activity isn't visible.