Skip to content

Commit 89a2ea2

Browse files
authored
Merge pull request #235 from GetStream/feature/baselineprofile
Update baseline profiles
2 parents 4e9c82e + af00ca9 commit 89a2ea2

File tree

14 files changed

+21466
-832
lines changed

14 files changed

+21466
-832
lines changed

app/build.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ plugins {
77
id(libs.plugins.android.application.get().pluginId)
88
id(libs.plugins.kotlin.android.get().pluginId)
99
id(libs.plugins.compose.compiler.get().pluginId)
10+
id(libs.plugins.baseline.profile.get().pluginId)
1011
}
1112

1213
android {
@@ -15,7 +16,7 @@ android {
1516

1617
defaultConfig {
1718
applicationId = "io.getstream.webrtc.sample.compose"
18-
minSdk = Configurations.minSdk
19+
minSdk = Configurations.appMinSdk
1920
targetSdk = Configurations.targetSdk
2021
versionName = Configurations.versionName
2122

@@ -89,4 +90,6 @@ dependencies {
8990

9091
// logger
9192
implementation(libs.stream.log)
93+
94+
baselineProfile(project(":benchmark"))
9295
}

app/src/release/generated/baselineProfiles/baseline-prof.txt

Lines changed: 10662 additions & 0 deletions
Large diffs are not rendered by default.

app/src/release/generated/baselineProfiles/startup-prof.txt

Lines changed: 10662 additions & 0 deletions
Large diffs are not rendered by default.

benchmark/build.gradle.kts

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,49 @@ import io.getstream.Configurations
1919
plugins {
2020
id("com.android.test")
2121
id("org.jetbrains.kotlin.android")
22+
id(libs.plugins.baseline.profile.get().pluginId)
2223
}
2324

2425
android {
2526
namespace = "io.getstream.webrtc.android.benchmark"
2627
compileSdk = Configurations.compileSdk
2728

28-
compileOptions {
29-
sourceCompatibility = JavaVersion.VERSION_11
30-
targetCompatibility = JavaVersion.VERSION_11
31-
}
32-
3329
defaultConfig {
3430
minSdk = 24
3531
targetSdk = Configurations.targetSdk
3632
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
3733
}
3834

39-
buildTypes {
40-
// This benchmark buildType is used for benchmarking, and should function like your
41-
// release build (for example, with minification on). It"s signed with a debug key
42-
// for easy local/CI testing.
43-
create("benchmark") {
44-
isDebuggable = true
45-
signingConfig = getByName("debug").signingConfig
46-
matchingFallbacks += listOf("release")
47-
}
35+
compileOptions {
36+
sourceCompatibility = JavaVersion.VERSION_11
37+
targetCompatibility = JavaVersion.VERSION_11
38+
}
39+
40+
buildFeatures {
41+
buildConfig = true
4842
}
4943

5044
targetProjectPath = ":app"
5145
experimentalProperties["android.experimental.self-instrumenting"] = true
46+
testOptions.managedDevices.devices {
47+
maybeCreate<com.android.build.api.dsl.ManagedVirtualDevice>("pixel6Api33").apply {
48+
device = "Pixel 6"
49+
apiLevel = 33
50+
systemImageSource = "aosp"
51+
}
52+
}
53+
}
54+
55+
// This is the plugin configuration. Everything is optional. Defaults are in the
56+
// comments. In this example, you use the GMD added earlier and disable connected devices.
57+
baselineProfile {
58+
// This specifies the managed devices to use that you run the tests on.
59+
managedDevices.clear()
60+
managedDevices += "pixel6Api33"
61+
62+
// This enables using connected devices to generate profiles. The default is true.
63+
// When using connected devices, they must be rooted or API 33 and higher.
64+
useConnectedDevices = true
5265
}
5366

5467
dependencies {
@@ -57,9 +70,3 @@ dependencies {
5770
implementation(libs.androidx.benchmark.macro)
5871
implementation(libs.androidx.profileinstaller)
5972
}
60-
61-
androidComponents {
62-
beforeVariants(selector().all()) {
63-
it.enable = it.buildType == "benchmark"
64-
}
65-
}

benchmark/src/main/java/io/getstream/webrtc/android/benchmark/BaselineProfileGenerator.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package io.getstream.webrtc.android.benchmark
1919
import android.os.Build
2020
import androidx.annotation.RequiresApi
2121
import androidx.benchmark.macro.junit4.BaselineProfileRule
22+
import androidx.test.uiautomator.By
2223
import org.junit.Rule
2324
import org.junit.Test
2425

@@ -34,13 +35,15 @@ class BaselineProfileGenerator {
3435
fun startup() =
3536
baselineProfileRule.collect(
3637
packageName = "io.getstream.webrtc.sample.compose",
38+
stableIterations = 2,
39+
maxIterations = 8,
3740
includeInStartupProfile = true,
3841
) {
39-
pressHome()
40-
// This block defines the app's critical user journey. Here we are interested in
41-
// optimizing for app startup. But you can also navigate and scroll
42-
// through your most important UI.
4342
startActivityAndWait()
43+
4444
device.waitForIdle()
45+
46+
device.waitForObject(By.text(getPermissionText()), 5_000)?.click()
47+
device.waitForObject(By.text(getPermissionText()), 5_000)?.click()
4548
}
4649
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2014-2024 Stream.io Inc. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.getstream.webrtc.android.benchmark
18+
19+
import android.os.Build
20+
import androidx.test.uiautomator.BySelector
21+
import androidx.test.uiautomator.UiDevice
22+
import androidx.test.uiautomator.UiObject2
23+
import androidx.test.uiautomator.Until
24+
25+
internal fun getPermissionText(): String {
26+
return when {
27+
Build.VERSION.SDK_INT <= 28 -> "ALLOW"
28+
Build.VERSION.SDK_INT == 29 -> "Allow only while using the app"
29+
else -> "While using the app"
30+
}
31+
}
32+
33+
internal fun UiDevice.waitForObject(selector: BySelector, timeout: Long = 5_000): UiObject2? {
34+
if (wait(Until.hasObject(selector), timeout)) {
35+
return findObject(selector)
36+
}
37+
return null
38+
}

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ plugins {
44
alias(libs.plugins.android.library) apply false
55
alias(libs.plugins.kotlin.android) apply false
66
alias(libs.plugins.compose.compiler) apply false
7+
alias(libs.plugins.baseline.profile) apply false
78
alias(libs.plugins.nexusPlugin)
89
alias(libs.plugins.spotless)
910
alias(libs.plugins.dokka)

buildSrc/src/main/kotlin/io/getstream/Configurations.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package io.getstream
22

33
object Configurations {
4-
const val compileSdk = 34
5-
const val targetSdk = 34
4+
const val compileSdk = 35
5+
const val targetSdk = 35
66
const val minSdk = 21
7+
const val appMinSdk = 24
78
const val majorVersion = 1
89
const val minorVersion = 2
910
const val patchVersion = 3

gradle/libs.versions.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[versions]
22
streamLog = "1.1.4"
3-
landscapist = "2.4.1"
3+
landscapist = "2.4.2"
44
jvmTarget = "11"
55
androidGradlePlugin = "8.6.1"
66
androidxActivity = "1.9.3"
@@ -20,7 +20,7 @@ kotlinxCoroutines = "1.9.0"
2020
okhttp = "4.12.0"
2121
retrofit = "2.9.0"
2222
spotless = "6.21.0"
23-
androidxMacroBenchmark = "1.3.3"
23+
androidxMacroBenchmark = "1.4.0-alpha05"
2424
androidxProfileinstaller = "1.4.1"
2525
androidxUiAutomator = "2.3.0"
2626

@@ -63,5 +63,6 @@ kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
6363
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
6464
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
6565
dokka = { id = "org.jetbrains.dokka", version = "1.9.20" }
66+
baseline-profile = { id = "androidx.baselineprofile", version.ref = "androidxMacroBenchmark" }
6667
nexusPlugin = { id = "io.github.gradle-nexus.publish-plugin", version = "2.0.0" }
6768
kotlinBinaryCompatibilityValidator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version = "0.16.3" }

stream-webrtc-android-compose/build.gradle.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ plugins {
77
id(libs.plugins.android.library.get().pluginId)
88
id(libs.plugins.kotlin.android.get().pluginId)
99
id(libs.plugins.compose.compiler.get().pluginId)
10+
id(libs.plugins.baseline.profile.get().pluginId)
1011
}
1112

1213
rootProject.extra.apply {
@@ -48,6 +49,13 @@ android {
4849
enableStrongSkippingMode = true
4950
reportsDestination = layout.buildDirectory.dir("compose_compiler")
5051
}
52+
53+
baselineProfile {
54+
baselineProfileOutputDir = "."
55+
filter {
56+
include("io.getstream.webrtc.android.compose.**")
57+
}
58+
}
5159
}
5260

5361
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
@@ -69,4 +77,6 @@ dependencies {
6977
implementation(libs.androidx.compose.runtime)
7078
implementation(libs.androidx.compose.foundation)
7179
implementation(libs.androidx.compose.material)
80+
81+
baselineProfile(project(":benchmark"))
7282
}

0 commit comments

Comments
 (0)