Skip to content

Commit ab3a578

Browse files
authored
Introduce baseline profile plugin and update baseline profiles (#754)
* Bump benchmark and ui automator versions * Introduce baseline profile plugin * Setting up productFlavors for the benchmark module * Setup baseline plugin for library build logic conventions * Add baseline profile filters for each module * Update baseline profiles
1 parent 4ebe249 commit ab3a578

File tree

23 files changed

+61391
-54593
lines changed

23 files changed

+61391
-54593
lines changed

bash/baseline-profile-amender.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
awk '/getstream/ && !/compose/ && /core/ && !/android-xml/ && !/dogfooding/ && !/ui-common/ && !/datastore/' dogfooding/src/main/baseline-prof.txt > stream-video-android-core/src/main/baseline-prof.txt
16-
awk '/getstream/ && /compose/ && !/core/ && !/android-xml/ && !/dogfooding/ && !/ui-common/ && !/datastore/' dogfooding/src/main/baseline-prof.txt > stream-video-android-compose/src/main/baseline-prof.txt
17-
awk '/getstream/ && !/compose/ && !/core/ && /android-xml/ && !/dogfooding/ && !/ui-common/ && !/datastore/' dogfooding/src/main/baseline-prof.txt > stream-video-android-xml/src/main/baseline-prof.txt
18-
awk '/getstream/ && !/compose/ && !/core/ && !/android-xml/ && !/dogfooding/ && /ui-common/ && !/datastore/' dogfooding/src/main/baseline-prof.txt > stream-video-android-ui-common/src/main/baseline-prof.txt
19-
awk '/getstream/ && !/compose/ && !/core/ && !/android-xml/ && !/dogfooding/ && !/ui-common/ && /datastore/' dogfooding/src/main/baseline-prof.txt > stream-video-android-datastore/src/main/baseline-prof.txt
15+
awk '/getstream/ && !/compose/ && /core/ && !/android-xml/ && !/dogfooding/ && !/ui-common/ && !/datastore/' dogfooding/src/main/generated/baselineProfiles/baseline-prof.txt > stream-video-android-core/src/main/baseline-prof.txt
16+
awk '/getstream/ && /compose/ && !/core/ && !/android-xml/ && !/dogfooding/ && !/ui-common/ && !/datastore/' dogfooding/src/main/generated/baselineProfiles/baseline-prof.txt > stream-video-android-compose/src/main/baseline-prof.txt
17+
awk '/getstream/ && !/compose/ && !/core/ && /android-xml/ && !/dogfooding/ && !/ui-common/ && !/datastore/' dogfooding/src/main/generated/baselineProfiles/baseline-prof.txt > stream-video-android-xml/src/main/baseline-prof.txt
18+
awk '/getstream/ && !/compose/ && !/core/ && !/android-xml/ && !/dogfooding/ && /ui-common/ && !/datastore/' dogfooding/src/main/generated/baselineProfiles/baseline-prof.txt > stream-video-android-ui-common/src/main/baseline-prof.txt
19+
awk '/getstream/ && !/compose/ && !/core/ && !/android-xml/ && !/dogfooding/ && !/ui-common/ && /datastore/' dogfooding/src/main/generated/baselineProfiles/baseline-prof.txt > stream-video-android-datastore/src/main/baseline-prof.txt

benchmark/build.gradle.kts

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ import io.getstream.video.android.Configuration
1717

1818
@Suppress("DSL_SCOPE_VIOLATION")
1919
plugins {
20-
id("com.android.test")
21-
id("org.jetbrains.kotlin.android")
20+
id(libs.plugins.android.test.get().pluginId)
21+
id(libs.plugins.kotlin.android.get().pluginId)
22+
id(libs.plugins.baseline.profile.get().pluginId)
2223
id("io.getstream.spotless")
2324
}
2425

@@ -36,25 +37,68 @@ android {
3637
}
3738

3839
defaultConfig {
39-
minSdk = 23
40+
minSdk = Configuration.minSdk
4041
targetSdk = Configuration.targetSdk
4142
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
4243
testInstrumentationRunnerArguments["androidx.benchmark.suppressErrors"] = "EMULATOR"
4344
}
4445

46+
buildFeatures {
47+
buildConfig = true
48+
}
49+
4550
buildTypes {
4651
// This benchmark buildType is used for benchmarking, and should function like your
47-
// release build (for example, with minification on). It"s signed with a debug key
52+
// release build (for example, with minification on). It's signed with a debug key
4853
// for easy local/CI testing.
4954
create("benchmark") {
55+
// Keep the build type debuggable so we can attach a debugger if needed.
5056
isDebuggable = true
51-
signingConfig = getByName("debug").signingConfig
52-
matchingFallbacks += listOf("release")
57+
isMinifyEnabled = false
58+
isShrinkResources = false
59+
signingConfig = signingConfigs.getByName("debug")
60+
matchingFallbacks.add("release")
61+
proguardFiles("benchmark-rules.pro")
62+
buildConfigField("Boolean", "BENCHMARK", "true")
63+
}
64+
}
65+
66+
flavorDimensions("environment")
67+
productFlavors {
68+
create("dogfooding") {
69+
dimension = "environment"
70+
proguardFiles("benchmark-rules.pro")
71+
buildConfigField("Boolean", "BENCHMARK", "true")
72+
}
73+
create("production") {
74+
dimension = "environment"
75+
proguardFiles("benchmark-rules.pro")
76+
buildConfigField("Boolean", "BENCHMARK", "true")
5377
}
5478
}
5579

5680
targetProjectPath = ":dogfooding"
57-
experimentalProperties["android.experimental.self-instrumenting"] = true
81+
82+
testOptions.managedDevices.devices {
83+
maybeCreate<com.android.build.api.dsl.ManagedVirtualDevice>("pixel6api31").apply {
84+
device = "Pixel 6"
85+
apiLevel = 31
86+
systemImageSource = "aosp"
87+
}
88+
}
89+
}
90+
91+
// This is the plugin configuration. Everything is optional. Defaults are in the
92+
// comments. In this example, you use the GMD added earlier and disable connected devices.
93+
baselineProfile {
94+
95+
// This specifies the managed devices to use that you run the tests on. The default
96+
// is none.
97+
managedDevices += "pixel6api31"
98+
99+
// This enables using connected devices to generate profiles. The default is true.
100+
// When using connected devices, they must be rooted or API 33 and higher.
101+
useConnectedDevices = false
58102
}
59103

60104
dependencies {
@@ -63,9 +107,3 @@ dependencies {
63107
implementation(libs.androidx.profileinstaller)
64108
implementation(libs.androidx.benchmark.macro)
65109
}
66-
67-
androidComponents {
68-
beforeVariants(selector().all()) {
69-
it.enable = it.buildType == "benchmark"
70-
}
71-
}

benchmark/src/main/kotlin/io/getstream/video/android/benchmark/BaselineProfileGenerator.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ internal class BaselineProfileGenerator {
3434

3535
@Test
3636
fun startup() =
37-
baselineProfileRule.collectBaselineProfile(
37+
baselineProfileRule.collect(
3838
packageName = packageName,
3939
stableIterations = 2,
4040
maxIterations = 8,
41+
includeInStartupProfile = true,
4142
) {
4243
startActivityAndWait()
4344
device.waitForIdle()

benchmark/src/main/kotlin/io/getstream/video/android/benchmark/Const.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616

1717
package io.getstream.video.android.benchmark
1818

19-
internal const val packageName = "io.getstream.video.android"
19+
internal const val packageName = "io.getstream.video.android.dogfooding"

build-logic/convention/src/main/kotlin/AndroidLibraryComposeConventionPlugin.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import io.getstream.video.kotlinOptions
55
import org.gradle.api.Plugin
66
import org.gradle.api.Project
77
import org.gradle.kotlin.dsl.configure
8+
import org.gradle.kotlin.dsl.dependencies
89

910
class AndroidLibraryComposeConventionPlugin : Plugin<Project> {
1011
override fun apply(target: Project) {
@@ -13,6 +14,7 @@ class AndroidLibraryComposeConventionPlugin : Plugin<Project> {
1314
pluginManager.apply("org.jetbrains.kotlin.android")
1415
pluginManager.apply("binary-compatibility-validator")
1516
pluginManager.apply("org.jetbrains.dokka")
17+
pluginManager.apply("androidx.baselineprofile")
1618
pluginManager.apply("app.cash.paparazzi")
1719

1820
extensions.configure<LibraryExtension> {
@@ -22,6 +24,10 @@ class AndroidLibraryComposeConventionPlugin : Plugin<Project> {
2224
kotlinOptions {
2325
freeCompilerArgs = freeCompilerArgs + listOf("-Xexplicit-api=strict")
2426
}
27+
28+
dependencies {
29+
add("baselineProfile", project(":benchmark"))
30+
}
2531
}
2632
}
2733
}

build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class AndroidLibraryConventionPlugin : Plugin<Project> {
1515
pluginManager.apply("org.jetbrains.kotlin.android")
1616
pluginManager.apply("binary-compatibility-validator")
1717
pluginManager.apply("org.jetbrains.dokka")
18+
pluginManager.apply("androidx.baselineprofile")
1819

1920
extensions.configure<LibraryExtension> {
2021
configureKotlinAndroid(this)
@@ -29,6 +30,10 @@ class AndroidLibraryConventionPlugin : Plugin<Project> {
2930
// kotlinOptions {
3031
// freeCompilerArgs = freeCompilerArgs + listOf("-Xexplicit-api=strict")
3132
// }
33+
34+
dependencies {
35+
add("baselineProfile", project(":benchmark"))
36+
}
3237
}
3338
}
3439
}

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ plugins {
2424
alias(libs.plugins.firebase.crashlytics) apply false
2525
alias(libs.plugins.hilt) apply false
2626
alias(libs.plugins.play.publisher) apply false
27+
alias(libs.plugins.baseline.profile) apply false
2728
}
2829

2930
subprojects {

buildSrc/src/main/kotlin/io/getstream/video/android/Configuration.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package io.getstream.video.android
22

33
object Configuration {
4-
const val compileSdk = 33
5-
const val targetSdk = 33
4+
const val compileSdk = 34
5+
const val targetSdk = 34
66
const val minSdk = 24
77
const val majorVersion = 0
88
const val minorVersion = 3

dogfooding/benchmark-rules.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-dontobfuscate
2+
-dontwarn com.google.errorprone.annotations.InlineMe

dogfooding/build.gradle.kts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ plugins {
3131
id(libs.plugins.kotlin.serialization.get().pluginId)
3232
id(libs.plugins.hilt.get().pluginId)
3333
id(libs.plugins.play.publisher.get().pluginId)
34+
id(libs.plugins.baseline.profile.get().pluginId)
3435
kotlin("kapt")
3536
}
3637

@@ -102,9 +103,12 @@ android {
102103
buildConfigField("Boolean", "BENCHMARK", "false")
103104
}
104105
create("benchmark") {
106+
isDebuggable = true
107+
isMinifyEnabled = false
108+
isShrinkResources = false
105109
signingConfig = signingConfigs.getByName("debug")
106110
matchingFallbacks += listOf("release")
107-
isDebuggable = false
111+
proguardFiles("benchmark-rules.pro")
108112
buildConfigField("Boolean", "BENCHMARK", "true")
109113
}
110114
}
@@ -129,6 +133,10 @@ android {
129133
baseline = file("lint-baseline.xml")
130134
}
131135

136+
baselineProfile {
137+
mergeIntoMain = true
138+
}
139+
132140
playConfigs {
133141
val serviceAccountCredentialsFile: File = rootProject.file(".sign/service-account-credentials.json")
134142
if (serviceAccountCredentialsFile.exists()) {
@@ -246,4 +254,6 @@ dependencies {
246254

247255
// memory detection
248256
debugImplementation(libs.leakCanary)
257+
258+
baselineProfile(project(":benchmark"))
249259
}

0 commit comments

Comments
 (0)