Skip to content

Commit

Permalink
Merge pull request #835 from DroidKaigi/baseline
Browse files Browse the repository at this point in the history
Baseline profile
  • Loading branch information
takahirom authored Oct 3, 2022
2 parents d256db3 + b89d96c commit d968339
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@ app-android/src/prod/google-services.json
keystore.properties
prod.keystore

# Baseline profile
app-android/src/main/baseline-prof.txt
3 changes: 3 additions & 0 deletions app-android/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ mkdir src/prod/
cp $1/google-services.json src/prod/google-services.json

cd ..
./gradlew :benchmark:pixel2Api31BenchmarkAndroidTest
cp benchmark/build/outputs/managed_device_android_test_additional_output/pixel2Api31/BaselineProfileGenerator_startup-baseline-prof.txt app-android/src/main/baseline-prof.txt

./gradlew app-android:assembleProdRelease -Pbuildkonfig.flavor=prod
./gradlew app-android:bundleProdRelease -Pbuildkonfig.flavor=prod
16 changes: 15 additions & 1 deletion benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.android.build.api.dsl.ManagedVirtualDevice

plugins {
id("com.android.test")
id("org.jetbrains.kotlin.android")
Expand All @@ -23,6 +25,7 @@ android {

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
missingDimensionStrategy("network", "dev")
testInstrumentationRunnerArguments["androidx.benchmark.suppressErrors"] = "EMULATOR"
}

buildTypes {
Expand All @@ -32,7 +35,17 @@ android {
matchingFallbacks += listOf("release")
}
}

testOptions {
managedDevices {
devices {
create ("pixel2Api31", ManagedVirtualDevice::class) {
device = "Pixel 2"
apiLevel = 31
systemImageSource = "aosp"
}
}
}
}
targetProjectPath = ":app-android"
experimentalProperties["android.experimental.self-instrumenting"] = true
}
Expand All @@ -42,6 +55,7 @@ dependencies {
implementation(libs.androidxTestEspressoEspressoCore)
implementation(libs.androidxTestUiAutomator)
implementation(libs.androidxMacroBenchmark)
implementation(libs.androidxProfileinstaller)
}

androidComponents {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.github.droidkaigi.confsched2022.baselineprofile

import androidx.benchmark.macro.ExperimentalBaselineProfilesApi
import androidx.benchmark.macro.junit4.BaselineProfileRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.uiautomator.By
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@ExperimentalBaselineProfilesApi
@RunWith(AndroidJUnit4::class)
class BaselineProfileGenerator {

@get:Rule val baselineProfileRule = BaselineProfileRule()

@Test
fun startup() =
baselineProfileRule.collectBaselineProfile(
packageName = "io.github.droidkaigi.confsched2022.dev",
profileBlock = {
startActivityAndWait()
}
)
}
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ androidxTestExt = "1.1.3"
androidxTestEspresso = "3.4.0"
androidxTestUiAutomator = "2.2.0"
androidxMacroBenchmark = "1.2.0-alpha04"
androidxProfileinstaller = "1.2.0-beta01"
dagger = "2.44"
spotless = "6.11.0"
ktlint = "0.45.2"
Expand Down Expand Up @@ -155,6 +156,7 @@ androidxTestExtJunit = { module = "androidx.test.ext:junit", version.ref = "andr
androidxTestEspressoEspressoCore = { module = "androidx.test.espresso:espresso-core", version.ref = "androidxTestEspresso" }
androidxTestUiAutomator = {module = "androidx.test.uiautomator:uiautomator", version.ref = "androidxTestUiAutomator"}
androidxMacroBenchmark = { module = "androidx.benchmark:benchmark-macro-junit4", version.ref = "androidxMacroBenchmark" }
androidxProfileinstaller = { group = "androidx.profileinstaller", name = "profileinstaller", version.ref = "androidxProfileinstaller" }
hiltAndroidTesting = { group = "com.google.dagger", name = "hilt-android-testing", version.ref = "dagger" }
robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectric" }
kluentAndroid = { module = "org.amshove.kluent:kluent-android", version.ref = "kluent" }
Expand Down

0 comments on commit d968339

Please sign in to comment.