init
This commit is contained in:
1
benchmark/.gitignore
vendored
Normal file
1
benchmark/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build
|
||||
54
benchmark/build.gradle.kts
Normal file
54
benchmark/build.gradle.kts
Normal file
@@ -0,0 +1,54 @@
|
||||
import com.android.build.api.dsl.ManagedVirtualDevice
|
||||
|
||||
kotlin {
|
||||
jvmToolchain(21)
|
||||
}
|
||||
plugins {
|
||||
alias(libs.plugins.android.test)
|
||||
alias(libs.plugins.kotlin.android)
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "cc.n0th1ng.benchmark"
|
||||
compileSdk = 36
|
||||
|
||||
defaultConfig {
|
||||
minSdk = 24
|
||||
targetSdk = 36
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
testInstrumentationRunnerArguments["androidx.compose.ui.test.tagsAsResourceId"] = "true"
|
||||
}
|
||||
|
||||
testOptions.managedDevices.devices {
|
||||
create<ManagedVirtualDevice>("pixel6Api31") {
|
||||
device = "Pixel 6"
|
||||
apiLevel = 31
|
||||
systemImageSource = "aosp"
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
create("benchmark") {
|
||||
isDebuggable = true
|
||||
signingConfig = getByName("debug").signingConfig
|
||||
matchingFallbacks += listOf("release")
|
||||
}
|
||||
}
|
||||
|
||||
targetProjectPath = ":app"
|
||||
experimentalProperties["android.experimental.self-instrumenting"] = true
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(libs.androidx.junit)
|
||||
implementation(libs.androidx.espresso.core)
|
||||
implementation(libs.androidx.uiautomator)
|
||||
implementation(libs.androidx.benchmark.macro.junit4)
|
||||
}
|
||||
|
||||
androidComponents {
|
||||
beforeVariants(selector().all()) {
|
||||
it.enable = it.buildType == "benchmark"
|
||||
}
|
||||
}
|
||||
1
benchmark/src/main/AndroidManifest.xml
Normal file
1
benchmark/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1 @@
|
||||
<manifest />
|
||||
@@ -0,0 +1,46 @@
|
||||
package cc.n0th1ng.benchmark
|
||||
|
||||
import android.os.Build
|
||||
import androidx.annotation.RequiresApi
|
||||
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 androidx.test.uiautomator.Direction
|
||||
import androidx.test.uiautomator.Until
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4ClassRunner::class)
|
||||
class BaselineProfileGenerator {
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
@get:Rule
|
||||
val rule = BaselineProfileRule()
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
@Test
|
||||
fun startup() = rule.collect(
|
||||
maxIterations = 1,
|
||||
packageName = "cc.n0th1ng.tripmoney",
|
||||
profileBlock = {
|
||||
device.executeShellCommand(
|
||||
"rm -rf /data/data/cc.n0th1ng.tripmoney/files/datastore/"
|
||||
)
|
||||
startActivityAndWait()
|
||||
device.wait(Until.hasObject(By.text("Włochy")), 10_000)
|
||||
device.findObject(By.text("Włochy")).click()
|
||||
val isVisible = device.wait(Until.hasObject(By.desc("expensesList")), 10_000)
|
||||
assert(isVisible)
|
||||
val expensesList = device.findObject(By.desc("expensesList"))
|
||||
expensesList.setGestureMargin(device.displayWidth / 5)
|
||||
expensesList.fling(Direction.DOWN)
|
||||
expensesList.fling(Direction.UP)
|
||||
expensesList.fling(Direction.DOWN)
|
||||
expensesList.fling(Direction.UP)
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package cc.n0th1ng.benchmark
|
||||
|
||||
import androidx.benchmark.macro.CompilationMode
|
||||
import androidx.benchmark.macro.StartupMode
|
||||
import androidx.benchmark.macro.StartupTimingMetric
|
||||
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.uiautomator.By
|
||||
import androidx.test.uiautomator.Until
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
/**
|
||||
* This is an example startup benchmark.
|
||||
*
|
||||
* It navigates to the device's home screen, and launches the default activity.
|
||||
*
|
||||
* Before running this benchmark:
|
||||
* 1) switch your app's active build variant in the Studio (affedaggcts Studio runs only)
|
||||
* 2) add `<profileable android:shell="true" />` to your app's manifest, within the `<application>` tag
|
||||
*
|
||||
* Run this benchmark from Studio to see startup measurements, and captured system traces
|
||||
* for investigating your app's performance.
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ExampleStartupBenchmark {
|
||||
@get:Rule
|
||||
val benchmarkRule = MacrobenchmarkRule()
|
||||
|
||||
@Test
|
||||
fun startup() = benchmarkRule.measureRepeated(
|
||||
packageName = "cc.n0th1ng.tripmoney",
|
||||
metrics = listOf(StartupTimingMetric()),
|
||||
iterations = 5,
|
||||
startupMode = StartupMode.COLD
|
||||
) {
|
||||
pressHome()
|
||||
startActivityAndWait()
|
||||
device.wait(Until.hasObject(By.pkg("cc.n0th1ng.tripmoney")), 10_000)
|
||||
device.waitForIdle()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user