[android] Add macrobenchmark module
Signed-off-by: Arnaud Vergnet <arnaud.vergnet@mailo.com>
This commit is contained in:
parent
ee42929139
commit
469de4d036
8 changed files with 121 additions and 1 deletions
|
@ -320,6 +320,15 @@ android {
|
|||
}
|
||||
|
||||
buildTypes {
|
||||
|
||||
benchmark {
|
||||
initWith release
|
||||
signingConfig signingConfigs.debug
|
||||
matchingFallbacks = ['release']
|
||||
debuggable false
|
||||
resValue 'string', 'app_id', android.defaultConfig.applicationId
|
||||
resValue 'string', 'app_name', project.ext.appName
|
||||
}
|
||||
debug {
|
||||
applicationIdSuffix '.debug' // Allows to install debug and release builds together
|
||||
versionNameSuffix '-debug'
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
android:supportsRtl="true"
|
||||
android:networkSecurityConfig="@xml/network_security_config"
|
||||
tools:targetApi="t">
|
||||
|
||||
<profileable android:shell="true" />
|
||||
<activity
|
||||
android:name="app.organicmaps.SplashActivity"
|
||||
android:exported="true">
|
||||
|
|
|
@ -2,4 +2,6 @@
|
|||
plugins {
|
||||
id 'com.android.application' version '8.1.0' apply false
|
||||
id 'com.android.library' version '8.1.0' apply false
|
||||
id 'com.android.test' version '8.1.0' apply false
|
||||
id 'org.jetbrains.kotlin.android' version '1.9.0' apply false
|
||||
}
|
1
android/macrobenchmark/.gitignore
vendored
Normal file
1
android/macrobenchmark/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/build
|
67
android/macrobenchmark/build.gradle
Normal file
67
android/macrobenchmark/build.gradle
Normal file
|
@ -0,0 +1,67 @@
|
|||
plugins {
|
||||
id 'com.android.test'
|
||||
id 'org.jetbrains.kotlin.android'
|
||||
}
|
||||
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
maven { url 'https://www.jitpack.io' } // MPAndroidChart
|
||||
}
|
||||
|
||||
android {
|
||||
namespace 'com.example.macrobenchmark'
|
||||
compileSdk 33
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
minSdk 23
|
||||
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
|
||||
signingConfig = debug.signingConfig
|
||||
matchingFallbacks = ["release"]
|
||||
}
|
||||
}
|
||||
|
||||
flavorDimensions += ["default"]
|
||||
productFlavors {
|
||||
google { dimension = "default" }
|
||||
web { dimension = "default" }
|
||||
fdroid { dimension = "default" }
|
||||
huawei { dimension = "default" }
|
||||
}
|
||||
|
||||
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.core:core-ktx:1.10.1'
|
||||
}
|
||||
|
||||
androidComponents {
|
||||
beforeVariants(selector().all()) {
|
||||
enable = buildType == "benchmark"
|
||||
}
|
||||
}
|
1
android/macrobenchmark/src/main/AndroidManifest.xml
Normal file
1
android/macrobenchmark/src/main/AndroidManifest.xml
Normal file
|
@ -0,0 +1 @@
|
|||
<manifest />
|
|
@ -0,0 +1,39 @@
|
|||
package com.example.macrobenchmark
|
||||
|
||||
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 = "app.organicmaps",
|
||||
metrics = listOf(StartupTimingMetric()),
|
||||
iterations = 5,
|
||||
startupMode = StartupMode.COLD
|
||||
) {
|
||||
pressHome()
|
||||
startActivityAndWait()
|
||||
}
|
||||
}
|
|
@ -15,3 +15,4 @@ pluginManagement {
|
|||
//}
|
||||
rootProject.name = "Organic Maps"
|
||||
include ':app'
|
||||
include ':macrobenchmark'
|
||||
|
|
Reference in a new issue