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

Cleanup and maintenance #287

Merged
merged 3 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions MacrobenchmarkSample/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

plugins {
alias(libs.plugins.application)
alias(libs.plugins.compose)
alias(libs.plugins.kotlin)
alias(libs.plugins.baselineprofile)
}
Expand All @@ -38,10 +39,6 @@ android {
viewBinding = true
}

composeOptions {
kotlinCompilerExtensionVersion = libs.versions.composeCompiler.get()
}

// [START macrobenchmark_setup_app_build_type]
buildTypes {
getByName("release") {
Expand Down
30 changes: 15 additions & 15 deletions MacrobenchmarkSample/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
[versions]
agp = "8.3.0"
activity = "1.8.2"
appcompat = "1.6.1"
benchmark = "1.2.3"
composeBom = "2024.02.01"
composeCompiler = "1.5.4"
agp = "8.5.2"
activity = "1.9.1"
appcompat = "1.7.0"
benchmark = "1.3.0"
composeBom = "2024.08.00"
constraintLayout = "2.1.4"
core = "1.12.0"
coroutines = "1.7.3"
concurrentFutures = "1.1.0"
core = "1.13.1"
coroutines = "1.8.0"
concurrentFutures = "1.2.0"
curtains = "1.2.4"
dataStore = "1.0.0"
espressoCore = "3.5.1"
jUnit = "1.1.5"
kotlin = "1.9.20"
lifecycle = "2.7.0"
material = "1.11.0"
dataStore = "1.1.1"
espressoCore = "3.6.1"
jUnit = "1.2.1"
kotlin = "2.0.10"
lifecycle = "2.8.4"
material = "1.12.0"
profileInstaller = "1.3.1"
runtimeTracing = "1.0.0-beta01"
tracing = "1.3.0-alpha02"
Expand Down Expand Up @@ -54,6 +53,7 @@ viewmodel = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-ktx", ve

application = { id = "com.android.application", version.ref = "agp" }
baselineprofile = { id = "androidx.baselineprofile", version.ref = "benchmark" }
compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
library = { id = "com.android.library", version.ref = "agp" }
test = { id = "com.android.test", version.ref = "agp" }
kotlin = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Mar 06 15:40:15 GMT 2023
#Fri Aug 30 09:45:14 CEST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@
package com.example.macrobenchmark.baselineprofile

import androidx.benchmark.macro.MacrobenchmarkScope
import androidx.test.uiautomator.UiDevice

const val TARGET_PACKAGE = "com.example.macrobenchmark.target"

/**
* This baseline profile generator creates a baseline profile only for the app startup.
* Clears the application data for the package specified in the [MacrobenchmarkScope].
* @param scope The [MacrobenchmarkScope] providing information about the benchmark,
* including the package name of the app under test.
*/
class StartupOnlyBaselineProfileGenerator: BaselineProfileGeneratorScaffold() {

override fun MacrobenchmarkScope.profileBlock() {
startActivityAndWait()
}
}
fun UiDevice.clearData(scope: MacrobenchmarkScope) {
val command = "pm clear $scope.packageName"
val output = executeShellCommand(command)
// Assert.assertEquals("Success", output)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,41 @@
package com.example.macrobenchmark.baselineprofile

import android.content.Intent
import androidx.benchmark.macro.MacrobenchmarkScope
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.benchmark.macro.junit4.BaselineProfileRule
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Direction
import com.example.macrobenchmark.benchmark.util.findOrFail
import com.example.macrobenchmark.benchmark.util.waitAndFind
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@Ignore // TODO causing stale object excpetion on CI .. why?
@RunWith(AndroidJUnit4::class)
class ComposeActivityBaselineProfileGenerator : BaselineProfileGeneratorScaffold() {
@RunWith(AndroidJUnit4ClassRunner::class)
class ComposeActivityBaselineProfileGenerator {

override fun MacrobenchmarkScope.profileBlock() {
// Start into the Compose Activity
startActivityAndWait(Intent("$TARGET_PACKAGE.COMPOSE_ACTIVITY"))
@get:Rule
val rule = BaselineProfileRule()

// Scrolling through the Compose journey
device.waitAndFind(By.res("myLazyColumn")).also {
it.setGestureMargin(device.displayWidth / 10)
it.fling(Direction.DOWN)
}
@Test
fun generate() {
rule.collect(
packageName = TARGET_PACKAGE,
maxIterations = 15,
stableIterations = 3
) {
// Start into the Compose Activity
startActivityAndWait(Intent("$TARGET_PACKAGE.COMPOSE_ACTIVITY"))

// Scrolling through the Compose journey
device.waitAndFind(By.res("myLazyColumn")).also {
it.setGestureMargin(device.displayWidth / 10)
it.fling(Direction.DOWN)
}

device.findOrFail(By.res("myLazyColumn")).fling(Direction.UP)
device.findOrFail(By.res("myLazyColumn")).fling(Direction.UP)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,33 @@

package com.example.macrobenchmark.baselineprofile

import androidx.benchmark.macro.MacrobenchmarkScope
import android.content.Intent
import androidx.benchmark.macro.junit4.BaselineProfileRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
import androidx.test.uiautomator.By
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

/**
* A scaffold for creating a baseline profile user journey. Implementing classes can
* start generating a profile directly by implementing [MacrobenchmarkScope.profileBlock].
*/
@RunWith(AndroidJUnit4::class)
abstract class BaselineProfileGeneratorScaffold {
@RunWith(AndroidJUnit4ClassRunner::class)
class LoginBaselineProfileGenerator {

@get:Rule
val rule = BaselineProfileRule()

/**
* Generate a baseline profile in this function.
*/
abstract fun MacrobenchmarkScope.profileBlock()

@Test
fun profileGenerator() {
fun generate() {
rule.collect(
packageName = TARGET_PACKAGE,
maxIterations = 15,
stableIterations = 3
) {
profileBlock()
device.clearData(this)
startActivityAndWait(Intent("$packageName.LOGIN_ACTIVITY"))
device.findObject(By.res("userName")).text = "user"
device.findObject(By.res("password")).text = "password"
device.findObject(By.res("login")).click()
device.waitForIdle()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,38 @@
package com.example.macrobenchmark.baselineprofile

import android.content.Intent
import androidx.benchmark.macro.MacrobenchmarkScope
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.benchmark.macro.junit4.BaselineProfileRule
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Direction
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@Ignore // TODO flinging not working, ignore for now to test the pipeline
@RunWith(AndroidJUnit4::class)
class RecyclerViewActivityBaselineProfileGenerator : BaselineProfileGeneratorScaffold() {
@RunWith(AndroidJUnit4ClassRunner::class)
class RecyclerViewActivityBaselineProfileGenerator {

override fun MacrobenchmarkScope.profileBlock() {
// Start into the RecyclerViewActivity
startActivityAndWait(Intent("$TARGET_PACKAGE.RECYCLER_VIEW_ACTIVITY"))
@get:Rule
val rule = BaselineProfileRule()

// Scrolling RecyclerView journey
device.findObject(By.res(packageName, "recycler")).also {
it.setGestureMargin(device.displayWidth / 10)
it.fling(Direction.DOWN)
it.fling(Direction.UP)
@Test
fun generate() {
rule.collect(
packageName = TARGET_PACKAGE,
maxIterations = 15,
stableIterations = 3
) {
// Start into the RecyclerViewActivity
startActivityAndWait(Intent("$TARGET_PACKAGE.RECYCLER_VIEW_ACTIVITY"))

// Scrolling RecyclerView journey
device.findObject(By.res(packageName, "recycler")).also {
it.setGestureMargin(device.displayWidth / 10)
it.fling(Direction.DOWN)
it.fling(Direction.UP)
}
}
}
}
Loading