Skip to content
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

Enable microbenchmark config and add a TraceSectionMetric sample #257

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions MicrobenchmarkSample/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies {
implementation(libs.core)
implementation(libs.material)


androidTestImplementation(libs.espresso)
androidTestImplementation(libs.test.ext)

Expand Down
2 changes: 2 additions & 0 deletions MicrobenchmarkSample/benchmarkable/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ dependencies {
implementation(libs.constraintlayout)
implementation(libs.kotlin.stdlib)
implementation(libs.recyclerview)
implementation(libs.perfetto.binary)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct? Adding it to the target implementation?

implementation(libs.perfetto.tracing)

androidTestImplementation(libs.espresso)
androidTestImplementation(libs.test.ext)
Expand Down
11 changes: 7 additions & 4 deletions MicrobenchmarkSample/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
[versions]
agp = "8.1.0"
agp = "8.1.2"
appcompat = "1.6.1"
benchmark = "1.2.0-beta02"
benchmark = "1.2.0-rc01"
cardView = "1.0.0"
constraintLayout = "2.1.4"
core = "1.10.1"
kotlin = "1.8.22"
core = "1.12.0"
kotlin = "1.9.0"
material = "1.9.0"
recyclerView = "1.3.1"

androidxTest = "1.5.2"
androidxTestRules = "1.5.0"
espressoCore = "3.5.1"
jUnit = "4.13.2"
perfetto = "1.0.0-rc01"
testExt = "1.1.5"

[libraries]
Expand All @@ -26,6 +27,8 @@ espresso = { group = "androidx.test.espresso", name = "espresso-core", version.r
junit = { group = "junit", name = "junit", version.ref = "jUnit" }
kotlin-stdlib = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib", version.ref = "kotlin" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
perfetto-binary = { group = "androidx.tracing", name = "tracing-perfetto-binary", version.ref = "perfetto"}
perfetto-tracing = { group = "androidx.tracing", name = "tracing-perfetto", version.ref = "perfetto"}
recyclerview = { group = "androidx.recyclerview", name = "recyclerview", version.ref = "recyclerView" }
test-ext = { group = "androidx.test.ext", name = "junit", version.ref = "testExt" }
test-rules = { group = "androidx.test", name = "rules", version.ref = "androidxTestRules" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package com.example.benchmark

import android.graphics.Bitmap
import android.graphics.BitmapFactory
import androidx.benchmark.ExperimentalBenchmarkConfigApi
import androidx.benchmark.MicrobenchmarkConfig
import androidx.benchmark.junit4.BenchmarkRule
import androidx.benchmark.junit4.measureRepeated
import androidx.test.ext.junit.runners.AndroidJUnit4
Expand All @@ -33,8 +35,11 @@ private const val JETPACK = "images/jetpack.png"
@RunWith(AndroidJUnit4::class)
class BitmapBenchmark {

@OptIn(ExperimentalBenchmarkConfigApi::class)
@get:Rule
val benchmarkRule = BenchmarkRule()
val benchmarkRule = BenchmarkRule(
MicrobenchmarkConfig(shouldEnableTraceAppTag = true, shouldEnablePerfettoSdkTracing = true)
)

private val context = InstrumentationRegistry.getInstrumentation().targetContext

Expand Down
Loading