Skip to content

Commit

Permalink
Merge pull request #19 from yveskalume/macrobenchmark
Browse files Browse the repository at this point in the history
Setup Macrobenchmark
  • Loading branch information
yveskalume authored Dec 29, 2023
2 parents c830b62 + a7a200b commit 6759576
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 112 deletions.
7 changes: 6 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ android {
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
signingConfig = signingConfigs.getByName("release")
signingConfig = signingConfigs.getByName("debug")
}
create("benchmark") {
initWith(buildTypes.getByName("release"))
matchingFallbacks += listOf("release")
isDebuggable = false
}
}
compileOptions {
Expand Down
11 changes: 9 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<application
android:allowBackup="true"
android:name=".EventCademyApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@drawable/eventcademy_app_icon"
Expand All @@ -15,6 +15,10 @@
android:supportsRtl="true"
android:theme="@style/Theme.EventCademy"
tools:targetApi="31">
<profileable
android:shell="true"
tools:targetApi="29" />

<activity
android:name=".MainActivity"
android:exported="true"
Expand All @@ -24,6 +28,7 @@

<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
Expand All @@ -45,6 +50,7 @@
<data android:host="eventcademy.app" />
</intent-filter>
</activity>

<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
Expand All @@ -55,11 +61,12 @@
android:value="androidx.startup"
tools:node="remove" />
</provider>

<service
android:name=".service.FcmService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"></action>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>

Expand Down
37 changes: 0 additions & 37 deletions benchmark/benchmark-proguard-rules.pro

This file was deleted.

54 changes: 27 additions & 27 deletions benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed
plugins {
alias(libs.plugins.com.android.library)
alias(libs.plugins.androidx.benchmark)
alias(libs.plugins.androidTest)
alias(libs.plugins.org.jetbrains.kotlin.android)
}

android {
namespace = "com.yveskalume.eventcademy.benchmark"
compileSdk = 33
compileSdk = 34

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

kotlinOptions {
jvmTarget = "17"
jvmTarget = "1.8"
}

defaultConfig {
minSdk = 24
targetSdk = 34

testInstrumentationRunner = "androidx.benchmark.junit4.AndroidBenchmarkRunner"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

testBuildType = "release"
buildTypes {
debug {
// Since isDebuggable can"t be modified by gradle for library modules,
// it must be done in a manifest - see src/androidTest/AndroidManifest.xml
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"benchmark-proguard-rules.pro"
)
}
release {
isDefault = true
// 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 = ":app"
experimentalProperties["android.experimental.self-instrumenting"] = true
}

dependencies {
androidTestImplementation(libs.runner)
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.junit)
androidTestImplementation(libs.benchmark.junit4)
// Add your dependencies here. Note that you cannot benchmark code
// in an app module this way - you will need to move any code you
// want to benchmark to a library module:
// https://developer.android.com/studio/projects/android-library#Convert
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"
}
}
15 changes: 0 additions & 15 deletions benchmark/src/androidTest/AndroidManifest.xml

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion benchmark/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest />
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.yveskalume.eventcademy.benchmark

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 StartupBenchmark {
@get:Rule
val benchmarkRule = MacrobenchmarkRule()

@Test
fun startup() = benchmarkRule.measureRepeated(
packageName = "com.yveskalume.eventcademy",
metrics = listOf(StartupTimingMetric()),
iterations = 5,
startupMode = StartupMode.COLD
) {
pressHome()
startActivityAndWait()
}
}
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ plugins {
alias(libs.plugins.org.jetbrains.kotlin.serialization) apply false
alias(libs.plugins.com.android.library) apply false
alias(libs.plugins.androidx.benchmark) apply false
alias(libs.plugins.androidTest) apply false

}
true // Needed to make the Suppress annotation work for the plugins block
5 changes: 5 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ com-google-android-material-material = "1.10.0"
androidx-benchmark = "1.1.1"
runner = "1.5.2"
benchmark-junit4 = "1.2.0"
uiautomator = "2.2.0"
benchmark-macro-junit4 = "1.2.0-beta01"

[libraries]
androidx-core-splashscreen = { module = "androidx.core:core-splashscreen", version.ref = "core-splashscreen" }
Expand Down Expand Up @@ -82,6 +84,8 @@ runner = { group = "androidx.test", name = "runner", version.ref = "runner" }
benchmark-junit4 = { group = "androidx.benchmark", name = "benchmark-junit4", version.ref = "benchmark-junit4" }

konfetti-compose = "nl.dionsegijn:konfetti-compose:2.0.3"
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]
Expand All @@ -94,6 +98,7 @@ com-google-firebase-crashlytics = { id = "com.google.firebase.crashlytics", vers
org-jetbrains-kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version = "1.7.10" }
com-android-library = { id = "com.android.library", version.ref = "agp" }
androidx-benchmark = { id = "androidx.benchmark", version.ref = "androidx-benchmark" }
androidTest = { id = "com.android.test", version.ref = "agp" }

[bundles]

0 comments on commit 6759576

Please sign in to comment.