Skip to content

Commit

Permalink
Generate baseline profile
Browse files Browse the repository at this point in the history
  • Loading branch information
floschu committed Oct 19, 2024
1 parent e15de46 commit ffb80f1
Show file tree
Hide file tree
Showing 10 changed files with 31,587 additions and 6 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ simple hydration reminder app
* `KEYSTORE_KEY_ALIAS`: key alias
* `KEYSTORE_KEY_PASSWORD`: key password
* `KEYSTORE_STORE_PASSWORD`: store password
* Push a new commit with version tag (e.g. `v2.0.0-b36`) to `develop` branch
* Push a new commit with version tag (e.g. `v2.0.0-b36`) to `develop` branch

## baseline profile

Generate a new profile with `./gradlew :app:generateReleaseBaselineProfile`.
10 changes: 7 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins {
alias(libs.plugins.ksp)
alias(libs.plugins.ktlint)
id("kotlin-parcelize")
alias(libs.plugins.baselineprofile)
}

android {
Expand Down Expand Up @@ -47,15 +48,15 @@ android {

storePassword = localProperties.getProperty("signingStorePassword")
?: System.getenv("SIGNING_STORE_PASSWORD")
?: null
?: null

keyAlias = localProperties.getProperty("signingKeyAlias")
?: System.getenv("SIGNING_KEY_ALIAS")
?: null
?: null

keyPassword = localProperties.getProperty("signingKeyPassword")
?: System.getenv("SIGNING_KEY_PASSWORD")
?: null
?: null
}
}

Expand Down Expand Up @@ -130,4 +131,7 @@ dependencies {
implementation(libs.room.runtime)
implementation(libs.room.ktx)
ksp(libs.room.compiler)

implementation(libs.profileinstaller)
baselineProfile(project(":baselineprofile"))
}
15,738 changes: 15,738 additions & 0 deletions app/src/release/generated/baselineProfiles/baseline-prof.txt

Large diffs are not rendered by default.

15,738 changes: 15,738 additions & 0 deletions app/src/release/generated/baselineProfiles/startup-prof.txt

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions baselineprofile/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
plugins {
alias(libs.plugins.android.test)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.baselineprofile)
}

android {
namespace = "at.florianschuster.hydro.baselineprofile"
compileSdk = 34

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = "1.8"
}

defaultConfig {
minSdk = 31
targetSdk = 34

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

targetProjectPath = ":app"
}

// This is the configuration block for the Baseline Profile plugin.
// You can specify to run the generators on a managed devices or connected devices.
baselineProfile {
useConnectedDevices = true
}

dependencies {
implementation(libs.junit)
implementation(libs.espresso.core)
implementation(libs.uiautomator)
implementation(libs.benchmark.macro.junit4)
}

androidComponents {
onVariants { variant ->
val artifactsLoader = variant.artifacts.getBuiltArtifactsLoader()
@Suppress("UnstableApiUsage")
variant.instrumentationRunnerArguments.put(
"targetAppId",
variant.testedApks.map { artifactsLoader.load(it)?.applicationId }
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package at.florianschuster.hydro.baselineprofile

import androidx.benchmark.macro.junit4.BaselineProfileRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

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

@get:Rule
val rule = BaselineProfileRule()

@Test
fun generate() {
rule.collect(
packageName = InstrumentationRegistry.getArguments().getString("targetAppId")
?: throw Exception("targetAppId not passed as instrumentation runner arg"),
includeInStartupProfile = true
) {
pressHome()
startActivityAndWait()
}
}
}
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ plugins {
alias libs.plugins.kotlin.serialization apply false
alias libs.plugins.ksp apply false
alias libs.plugins.ktlint apply false
alias(libs.plugins.android.test) apply false
alias(libs.plugins.baselineprofile) apply false
}
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ kotlin.code.style=official
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.nonTransitiveRClass=true
org.gradle.configuration-cache=true
12 changes: 12 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ lottieCompose = "6.0.1"
navigationReimagined = "1.5.0"
room = "2.6.1"
androidGradlePlugin = "8.6.1"
junit = "1.2.1"
espressoCore = "3.6.1"
uiautomator = "2.3.0"
baselineprofile = "1.3.3"
profileinstaller = "1.4.1"

[libraries]
activity-compose = { module = "androidx.activity:activity-compose", version.ref = "activityCompose" }
Expand All @@ -39,6 +44,11 @@ room-runtime = { module = "androidx.room:room-runtime", version.ref = "room" }
ui-test-manifest = { module = "androidx.compose.ui:ui-test-manifest" }
ui-tooling = { module = "androidx.compose.ui:ui-tooling" }
ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview" }
junit = { group = "androidx.test.ext", name = "junit", version.ref = "junit" }
espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
uiautomator = { group = "androidx.test.uiautomator", name = "uiautomator", version.ref = "uiautomator" }
benchmark-macro-junit4 = { group = "androidx.benchmark", name = "benchmark-macro-junit4", version.ref = "baselineprofile" }
profileinstaller = { group = "androidx.profileinstaller", name = "profileinstaller", version.ref = "profileinstaller" }

[plugins]
android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }
Expand All @@ -47,3 +57,5 @@ kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "ko
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version = "2.0.0" }
ksp = { id = "com.google.devtools.ksp", version = "2.0.21-1.0.25" }
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version = "11.6.1" }
android-test = { id = "com.android.test", version.ref = "androidGradlePlugin" }
baselineprofile = { id = "androidx.baselineprofile", version.ref = "baselineprofile" }
3 changes: 2 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ dependencyResolutionManagement {
}

rootProject.name = "hydro"
include(":app")
include(":app")
include(":baselineprofile")

0 comments on commit ffb80f1

Please sign in to comment.