Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Add]
- Support macro benchmark.
  • Loading branch information
rosuH committed Dec 18, 2022
1 parent 9ace65a commit 3c67af5
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 72 deletions.
7 changes: 7 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,15 @@ android {
)
}
create("benchmark") {
isMinifyEnabled = true
isShrinkResources = true
signingConfig = signingConfigs.getByName("debug")
isDebuggable = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"coroutines.pro", "proguard-rules.pro"
)
matchingFallbacks += listOf("release")
}
}

Expand Down
25 changes: 15 additions & 10 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32"
/>

<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />

<application
Expand All @@ -19,12 +18,16 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApp">
<profileable
android:shell="true"
tools:targetApi="29" />

<activity
android:name=".ui.MainActivity"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait"
android:launchMode="singleTask"
android:exported="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -33,7 +36,9 @@
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />

<category android:name="android.intent.category.DEFAULT" />

<data android:mimeType="image/*" />
</intent-filter>
</activity>
Expand All @@ -44,8 +49,8 @@
<activity
android:name=".ui.about.OpenSourceActivity"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait"
android:parentActivityName=".ui.about.AboutActivity">
android:parentActivityName=".ui.about.AboutActivity"
android:screenOrientation="portrait">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.about.AboutActivity" />
Expand Down
1 change: 1 addition & 0 deletions benchmark/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
18 changes: 9 additions & 9 deletions benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ plugins {
}

android {
compileSdk = 32
namespace = "me.rosuh.benchmark"
compileSdk = 33

compileOptions {
sourceCompatibility(JavaVersion.VERSION_11)
targetCompatibility(JavaVersion.VERSION_11)
}

kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "11"
}

defaultConfig {
minSdk = 21
targetSdk = 32
minSdk = 24
targetSdk = 33

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments["androidx.benchmark.suppressErrors"] = "DEBUGGABLE,NOT-PROFILEABLE"
}

buildTypes {
Expand All @@ -30,19 +30,19 @@ android {
create("benchmark") {
isDebuggable = true
signingConfig = getByName("debug").signingConfig
matchingFallbacks += listOf("release")
}
}

targetProjectPath = ":app"
namespace = "me.rosuh.benchmark"
experimentalProperties["android.experimental.self-instrumenting"] = true
}

dependencies {
implementation("androidx.test.ext:junit:1.1.3")
implementation("androidx.test.espresso:espresso-core:3.4.0")
implementation("androidx.test.ext:junit:1.1.4")
implementation("androidx.test.espresso:espresso-core:3.5.0")
implementation("androidx.test.uiautomator:uiautomator:2.2.0")
implementation("androidx.benchmark:benchmark-macro-junit4:1.1.0-alpha03")
implementation("androidx.benchmark:benchmark-macro-junit4:1.1.1")
}

androidComponents {
Expand Down
8 changes: 2 additions & 6 deletions benchmark/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<queries>
<package android:name="me.rosuh.easywatermark.debug" />
<package android:name="me.rosuh.easywatermark" />
</queries>
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
</manifest>
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
package me.rosuh.benchmark

import android.app.Application
import android.content.Context
import android.content.Intent
import android.graphics.Point
import android.provider.ContactsContract.Intents.Insert.ACTION
import androidx.benchmark.macro.CompilationMode
import androidx.benchmark.macro.FrameTimingMetric
import androidx.benchmark.macro.StartupMode
import androidx.benchmark.macro.StartupTimingMetric
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
import androidx.test.core.app.ApplicationProvider
import androidx.test.core.app.ApplicationProvider.getApplicationContext
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Direction
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.Until
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -31,7 +15,7 @@ import org.junit.runner.RunWith
*
* Before running this benchmark:
* 1) switch your app's active build variant in the Studio (affects Studio runs only)
* 2) add `<profileable shell=true>` to your app's manifest, within the `<application>` tag
* 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.
Expand All @@ -41,39 +25,14 @@ class ExampleStartupBenchmark {
@get:Rule
val benchmarkRule = MacrobenchmarkRule()

private lateinit var device: UiDevice

private val PACKAGE_NAME = "me.rosuh.easywatermark.debug"

@Before
fun setUp() {
val instrumentation = InstrumentationRegistry.getInstrumentation()
device = UiDevice.getInstance(instrumentation)
}

@Test
fun startup() = benchmarkRule.measureRepeated(
packageName = PACKAGE_NAME,
metrics = listOf(FrameTimingMetric()),
packageName = "me.rosuh.easywatermark",
metrics = listOf(StartupTimingMetric()),
iterations = 10,
setupBlock = {
val intent = ApplicationProvider.getApplicationContext<Application>().packageManager.getLaunchIntentForPackage(
PACKAGE_NAME
)
intent?.let { startActivityAndWait(it) }
}
startupMode = StartupMode.COLD
) {
device.findObject(By.text("选择图片")).click()
// Set gesture margin to avoid triggering gesture nav
// with input events from automation.

// Scroll down several times
device.wait(Until.hasObject(By.res("me.rosuh.easywatermark.debug:id/rv_content")), 5000)
val recycler = device.findObject(By.res("me.rosuh.easywatermark.debug:id/rv_content"))
recycler.longClick()
for (i in 1..10) {
recycler.scroll(Direction.DOWN, 2f)
device.waitForIdle()
}
pressHome()
startActivityAndWait()
}
}
8 changes: 8 additions & 0 deletions cmonet/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ android {
"proguard-rules.pro"
)
}
create("benchmark") {
isMinifyEnabled = true
signingConfig = signingConfigs.getByName("debug")
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility(JavaVersion.VERSION_11)
Expand Down

0 comments on commit 3c67af5

Please sign in to comment.