-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from yveskalume/macrobenchmark
Setup Macrobenchmark
- Loading branch information
Showing
10 changed files
with
86 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
benchmark/src/androidTest/java/com/yveskalume/eventcademy/benchmark/ExampleBenchmark.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest /> |
38 changes: 38 additions & 0 deletions
38
benchmark/src/main/java/com/yveskalume/eventcademy/benchmark/StartupBenchmark.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters