TP-35161 | benchmark setup in uitron (#122)

This commit is contained in:
Maila Rajanikanth
2023-07-13 19:43:22 +05:30
committed by GitHub
parent a44d39932e
commit 748b0f17ee
9 changed files with 130 additions and 0 deletions

30
.github/workflows/benchmark.yml vendored Normal file
View File

@@ -0,0 +1,30 @@
name: Cron Job
on:
schedule:
- cron: '15 14 * * *'
jobs:
benchmark:
runs-on: [ macOS ]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Log Build Metadata
run: |
echo "Commit SHA: ${{ github.sha }}"
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Connected Devices
run: adb devices
- name: Benchmark
run: ./gradlew :benchmark:connectedCheck || true
- name: Connected Devices
run: adb devices
- name: Benchmark Report
run: |
for folder in benchmark/build/outputs/androidTest-results/connected/*/; do
echo "Device: $folder"
cat "$folder/testlog/test-results.log" || true
grep "android.studio.display.benchmark=UiTronBenchmark_startup" "$folder/testlog/test-results.log" -A 2 || true
done

View File

@@ -27,6 +27,11 @@ android {
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
benchmark {
initWith release
signingConfig signingConfigs.debug
matchingFallbacks = ['release']
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
@@ -68,4 +73,6 @@ dependencies {
androidTestImplementation "androidx.test.ext:junit:1.1.4"
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation "androidx.navigation:navigation-compose:$nav_version"
implementation 'androidx.profileinstaller:profileinstaller:1.3.1'
}

View File

@@ -16,6 +16,7 @@
android:supportsRtl="true"
android:theme="@style/Theme.UiTron"
tools:targetApi="31">
<profileable android:shell="true"/>
<activity
android:name="com.uitron.demo.MainActivity"
android:exported="true"

1
benchmark/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build

55
benchmark/build.gradle Normal file
View File

@@ -0,0 +1,55 @@
plugins {
id 'com.android.test'
id 'org.jetbrains.kotlin.android'
}
android {
namespace 'com.navi.uitron.benchmark'
compileSdk 33
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
defaultConfig {
minSdk 24
targetSdk 33
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
// This benchmark buildType is used for benchmarking, and should function like your
// release build (for example, with minification on). It's signed with a debug key
// for easy local/CI testing.
benchmark {
debuggable = true
minifyEnabled true
shrinkResources true
signingConfig = signingConfigs.getByName("debug")
matchingFallbacks.add("release")
}
}
targetProjectPath = ":app"
experimentalProperties["android.experimental.self-instrumenting"] = true
}
dependencies {
implementation 'androidx.test.ext:junit:1.1.5'
implementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation 'androidx.test.uiautomator:uiautomator:2.2.0'
implementation 'androidx.benchmark:benchmark-macro-junit4:1.1.1'
implementation "androidx.benchmark:benchmark-junit4:1.1.1"
}
androidComponents {
beforeVariants(selector().all()) {
enable = buildType == "benchmark"
}
}

View File

@@ -0,0 +1 @@
<manifest />

View File

@@ -0,0 +1,33 @@
package com.navi.uitron.benchmark
import androidx.benchmark.macro.FrameTimingMetric
import androidx.benchmark.macro.StartupMode
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
import java.util.concurrent.TimeUnit
@RunWith(AndroidJUnit4::class)
class UiTronBenchmark {
@get:Rule
val benchmarkRule = MacrobenchmarkRule()
@Test
fun startup() = benchmarkRule.measureRepeated(
packageName = "com.uitron.demo",
metrics = listOf(FrameTimingMetric()),
iterations = 3,
startupMode = StartupMode.COLD,
) {
pressHome()
startActivityAndWait()
device.wait(
Until.hasObject(By.clazz("$packageName.MockActivity")),
TimeUnit.SECONDS.toMillis(1)
)
}
}

View File

@@ -8,4 +8,5 @@ plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
id 'org.jetbrains.kotlin.android' version '1.8.10' apply false
id 'com.android.test' version '7.3.1' apply false
}

View File

@@ -31,3 +31,4 @@ dependencyResolutionManagement {
rootProject.name = "UiTron"
include ':app'
include ':navi-uitron'
include ':benchmark'