Skip to content

Commit

Permalink
Merge pull request #115 from cortinico/nc/p01-macrobenchmark
Browse files Browse the repository at this point in the history
Optional challange - P01 – Measure the performance of the app
  • Loading branch information
mike-n-jordan authored Oct 26, 2023
2 parents f38c5e2 + b4a306e commit ed20ddd
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 1 deletion.
5 changes: 5 additions & 0 deletions androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ android {
isMinifyEnabled = true
signingConfig = signingConfigs.getByName("debug")
}
create("benchmark") {
initWith(buildTypes.getByName("release"))
matchingFallbacks += listOf("release")
isDebuggable = false
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
Expand Down
6 changes: 5 additions & 1 deletion androidApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="DataExtractionRules">
<profileable android:shell="true" />

<activity
android:name="com.bumble.livemosaic.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

</manifest>
1 change: 1 addition & 0 deletions benchmark/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
53 changes: 53 additions & 0 deletions benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed
plugins {
id("com.android.test")
kotlin("android")
}

android {
namespace = "com.bumble.appyx.livemosaic.android.benchmark"
compileSdk = 34

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = "1.8"
}

defaultConfig {
minSdk = 23
targetSdk = 34

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.
create("benchmark") {
isDebuggable = true
signingConfig = getByName("debug").signingConfig
matchingFallbacks += listOf("release")
}
}

targetProjectPath = ":androidApp"
experimentalProperties["android.experimental.self-instrumenting"] = true
}

dependencies {
implementation(libs.androidx.test.ext.junit)
implementation(libs.espresso.core)
implementation(libs.uiautomator)
implementation(libs.benchmark.macro.junit4)
}

androidComponents {
beforeVariants(selector().all()) {
it.enable = it.buildType == "benchmark"
}
}
1 change: 1 addition & 0 deletions benchmark/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<manifest />
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.bumble.appyx.livemosaic.android.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 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 (affects 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 = "com.bumble.appyx.livemosaic.android",
metrics = listOf(StartupTimingMetric()),
iterations = 5,
startupMode = StartupMode.COLD
) {
pressHome()
startActivityAndWait()
}
}
8 changes: 8 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ resources = "0.22.3"
serialization-json = "1.5.0"
ktor = "2.3.4"
uuid = "9.0.0"
androidxtestext = "1.1.5"
espresso-core = "3.5.1"
uiautomator = "2.2.0"
benchmark-macro-junit4 = "1.2.0-beta01"

[libraries]
androidx-activity-compose = "androidx.activity:activity-compose:1.7.2"
Expand Down Expand Up @@ -92,6 +96,10 @@ detekt-compose-rules = "io.nlopez.compose.rules:detekt:0.3.0"
toolargetool = "com.gu.android:toolargetool:0.3.0"

symbol-processing-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" }
androidx-test-ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidxtestext" }
espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espresso-core" }
uiautomator = { group = "androidx.test.uiautomator", name = "uiautomator", version.ref = "uiautomator" }
benchmark-macro-junit4 = { group = "androidx.benchmark", name = "benchmark-macro-junit4", version.ref = "benchmark-macro-junit4" }

[plugins]
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pluginManagement {
plugins {
kotlin("multiplatform")
id("org.jetbrains.compose")
id("com.android.test")
}
}

Expand All @@ -27,3 +28,4 @@ include(":androidApp")
include(":desktopApp")
include(":webApp")
include(":shared")
include(":benchmark")

0 comments on commit ed20ddd

Please sign in to comment.