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

Configure baseline profiles in the baselineProfile lambda #1060

Merged
merged 12 commits into from
Apr 23, 2024
Merged
18 changes: 15 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ android {
// To publish on the Play store a private signing key is required, but to allow anyone
// who clones the code to sign and run the release variant, use the debug signing key.
// TODO: Abstract the signing configuration to a separate file to avoid hardcoding this.
signingConfig = signingConfigs.named("debug").get()
// Ensure Baseline Profile is fresh for release builds.
baselineProfile.automaticGenerationDuringBuild = true
signingConfig = signingConfigs.getByName("debug")
}
}

Expand All @@ -71,6 +69,20 @@ android {
namespace = "com.google.samples.apps.nowinandroid"
}

baselineProfile {
saveInSrc = false
// Don't build on every iteration of a full assemble.
// Instead enable generation directly for the release build variant.
automaticGenerationDuringBuild = false
mergeIntoMain = true
variants {
create("release") {
// Ensure Baseline Profile is fresh for release builds.
automaticGenerationDuringBuild = true
}
}
}

dependencies {
implementation(projects.feature.interests)
implementation(projects.feature.foryou)
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.android.build.api.dsl.ManagedVirtualDevice
import com.google.samples.apps.nowinandroid.configureFlavors

plugins {
Expand Down Expand Up @@ -46,7 +47,7 @@ android {
}

testOptions.managedDevices.devices {
create<com.android.build.api.dsl.ManagedVirtualDevice>("pixel6Api33") {
create<ManagedVirtualDevice>("pixel6Api33") {
device = "Pixel 6"
apiLevel = 33
keyboardsurfer marked this conversation as resolved.
Show resolved Hide resolved
systemImageSource = "aosp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.samples.apps.nowinandroid.foryou

import android.util.Log
import androidx.benchmark.macro.MacrobenchmarkScope
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Until
Expand All @@ -25,6 +26,8 @@ import com.google.samples.apps.nowinandroid.waitAndFindObject
import com.google.samples.apps.nowinandroid.waitForObjectOnTopAppBar
import org.junit.Assert.fail

private const val TAG = "ForYouActions"
keyboardsurfer marked this conversation as resolved.
Show resolved Hide resolved

fun MacrobenchmarkScope.forYouWaitForContent() {
// Wait until content is loaded by checking if topics are loaded
device.wait(Until.gone(By.res("loadingWheel")), 5_000)
keyboardsurfer marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -41,6 +44,11 @@ fun MacrobenchmarkScope.forYouWaitForContent() {
*/
fun MacrobenchmarkScope.forYouSelectTopics(recheckTopicsIfChecked: Boolean = false) {
val topics = device.findObject(By.res("forYou:topicSelection"))
val withChildren = topics.childCount != 0
if (!withChildren) {
keyboardsurfer marked this conversation as resolved.
Show resolved Hide resolved
// TODO: Ensure ForYou has topics.
fail("No topics found, can't scroll for baseline profile generation.")
}

// Set gesture margin from sides not to trigger system gesture navigation
val horizontalMargin = 10 * topics.visibleBounds.width() / 100
Expand All @@ -51,9 +59,6 @@ fun MacrobenchmarkScope.forYouSelectTopics(recheckTopicsIfChecked: Boolean = fal
var visited = 0

while (visited < 3) {
if (topics.childCount == 0) {
fail("No topics found, can't generate profile for ForYou page.")
}
// Selecting some topics, which will populate items in the feed.
val topic = topics.children[index % topics.childCount]
// Find the checkable element to figure out whether it's checked or not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@

package com.google.samples.apps.nowinandroid.interests

import android.util.Log
import androidx.benchmark.macro.MacrobenchmarkScope
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Until
import com.google.samples.apps.nowinandroid.flingElementDownUp
import com.google.samples.apps.nowinandroid.waitForObjectOnTopAppBar
import org.junit.Assert.fail

private const val TAG = "InterestsActions"
keyboardsurfer marked this conversation as resolved.
Show resolved Hide resolved

fun MacrobenchmarkScope.goToInterestsScreen() {
device.findObject(By.text("Interests")).click()
Expand All @@ -35,7 +39,12 @@ fun MacrobenchmarkScope.goToInterestsScreen() {
fun MacrobenchmarkScope.interestsScrollTopicsDownUp() {
device.wait(Until.hasObject(By.res("interests:topics")), 5_000)
val topicsList = device.findObject(By.res("interests:topics"))
device.flingElementDownUp(topicsList)
if (topicsList != null) {
// TODO: Ensure topics are availble.
device.flingElementDownUp(topicsList)
} else {
fail("No topics found, can't scroll during baseline profile generation.")
}
}

fun MacrobenchmarkScope.interestsWaitForTopics() {
Expand Down
Loading