Skip to content

Commit

Permalink
Merge pull request #149 from WithPeace/feat/#135-벤치마크_적용
Browse files Browse the repository at this point in the history
Feat/#135 벤치마크 적용
  • Loading branch information
rhkrwngud445 authored Jun 26, 2024
2 parents 38d9cf4 + 5f5bd8e commit 4ca98c6
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 12 deletions.
5 changes: 5 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ android {
"proguard-rules.pro",
)
}
create("benchmark") {
initWith(buildTypes.getByName("release"))
matchingFallbacks += listOf("release")
isDebuggable = false
}
}
}

Expand Down
23 changes: 13 additions & 10 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.withpeace.withpeace">

<uses-permission android:name="android.permission.INTERNET" />

<!-- Devices running Android 12L (API level 32) or lower -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />

<!-- Devices running Android 13 (API level 33) or higher -->
<uses-permission android:name="android.permission.INTERNET" /> <!-- Devices running Android 12L (API level 32) or lower -->
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" /> <!-- Devices running Android 13 (API level 33) or higher -->
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />

<application
Expand All @@ -17,22 +15,27 @@
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_app_logo"
android:usesCleartextTraffic="true"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_app_logo_round"
android:supportsRtl="true"
android:theme="@style/Theme.Withpeace"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<profileable
android:shell="true"
tools:targetApi="29" />

<activity
android:name=".MainActivity"
android:exported="true"
android:windowSoftInputMode="adjustResize"
android:theme="@style/Theme.Withpeace.Starting">
android:theme="@style/Theme.Withpeace.Starting"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

</manifest>
8 changes: 7 additions & 1 deletion app/src/main/java/com/withpeace/withpeace/WithpeaceApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.navigation.NavHostController
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.withpeace.withpeace.core.designsystem.theme.WithpeaceTheme
import com.withpeace.withpeace.navigation.WithpeaceNavHost
import kotlinx.coroutines.launch

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun WithpeaceApp(
startDestination: String,
Expand Down Expand Up @@ -47,7 +51,9 @@ fun WithpeaceApp(
)
}
},
modifier = Modifier.fillMaxSize(),
modifier = Modifier.fillMaxSize().semantics {
testTagsAsResourceId = true
},
snackbarHost = { SnackbarHost(snackBarHostState) },
containerColor = WithpeaceTheme.colors.SystemWhite,
) { innerPadding ->
Expand Down
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 @@
plugins {
alias(libs.plugins.android.test)
alias(libs.plugins.kotlin.android)
}

android {
namespace = "com.withpeace.withpeace.benchmark"
compileSdk = 34

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

kotlinOptions {
jvmTarget = "1.8"
}

defaultConfig {
minSdk = 26
targetSdk = 34

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments["androidx.benchmark.suppressErrors"] = "EMULATOR"
}

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 = ":app"
experimentalProperties["android.experimental.self-instrumenting"] = true
}

dependencies {
implementation(libs.junit)
implementation(libs.androidx.test.espresso.core)
implementation(libs.androidx.uiautomator)
implementation(libs.androidx.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.withpeace.withpeace.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.withpeace.withpeace",
metrics = listOf(StartupTimingMetric()),
iterations = 5,
startupMode = StartupMode.COLD
) {
pressHome()
startActivityAndWait()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.withpeace.withpeace.benchmark.home

import androidx.benchmark.macro.MacrobenchmarkScope
import androidx.test.uiautomator.By
import androidx.test.uiautomator.BySelector
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiObject2
import androidx.test.uiautomator.Until

fun MacrobenchmarkScope.policyContent() {
device.wait(Until.gone(By.res("circular_progress_bar")), 5_000)

val obj = device.waitAndFindObject(By.res("forYou:topicSelection"), 10_000)

}

fun UiDevice.waitAndFindObject(selector: BySelector, timeout: Long): UiObject2 {
if (!wait(Until.hasObject(selector), timeout)) {
throw AssertionError("Element not found on screen in ${timeout}ms (selector=$selector)")
}

return findObject(selector)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.withpeace.withpeace.benchmark.home

import androidx.benchmark.macro.FrameTimingMetric
import androidx.benchmark.macro.StartupMode
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Direction
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class HomeBenchMark {
@get:Rule
val benchmarkRule = MacrobenchmarkRule()

@Test
fun scrollPolicy() = benchmarkRule.measureRepeated(
packageName = "com.withpeace.withpeace",
metrics = listOf(FrameTimingMetric()),
iterations = 10,
startupMode = StartupMode.HOT,
setupBlock = {
pressHome()
startActivityAndWait()
}
) {
val contentList = device.waitAndFindObject(By.res("home:policies"), 10000)
contentList.setGestureMargin(device.displayWidth / 5)

contentList.fling(Direction.DOWN)

device.waitForIdle()
}
}
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.kotlin.serialization) apply false
alias(libs.plugins.firebase.services) apply false
alias(libs.plugins.firebase.crashlytics) apply false
alias(libs.plugins.android.test) apply false
}

apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
Expand Down Expand Up @@ -178,7 +179,7 @@ private fun PolicyItems(
) {
Spacer(modifier = modifier.height(8.dp))
LazyColumn(
modifier = modifier.fillMaxSize(),
modifier = modifier.fillMaxSize().testTag("home:policies"),
contentPadding = PaddingValues(bottom = 16.dp),
) {
items(
Expand Down
5 changes: 5 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ firebaseBom = "32.7.4"
firebaseCrashlytics = "2.9.9"

textflow = "1.1.2"
uiautomator = "2.2.0"
benchmarkMacroJunit4 = "1.2.0-beta01"

[libraries]
android-gradlePlugin = { group = "com.android.tools.build", name = "gradle", version.ref = "androidGradlePlugin" }
Expand Down Expand Up @@ -185,6 +187,8 @@ androidx-material3-android = { group = "androidx.compose.material3", name = "mat
firebase-bom = { group = "com.google.firebase", name = "firebase-bom", version.ref = "firebaseBom" }
firebase-analytics = { group = "com.google.firebase", name = "firebase-analytics" }
firebase-crashlytics = { group = "com.google.firebase", name = "firebase-crashlytics" }
androidx-uiautomator = { group = "androidx.test.uiautomator", name = "uiautomator", version.ref = "uiautomator" }
androidx-benchmark-macro-junit4 = { group = "androidx.benchmark", name = "benchmark-macro-junit4", version.ref = "benchmarkMacroJunit4" }

[bundles]

Expand All @@ -200,5 +204,6 @@ verify-detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" }
firebase-services = { id = "com.google.gms.google-services", version.ref = "firebasePlugin" }
firebase-crashlytics = { id = "com.google.firebase.crashlytics", version.ref = "firebaseCrashlytics" }
android-test = { id = "com.android.test", version.ref = "androidGradlePlugin" }


1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ include(":feature:policydetail")
include(":feature:policyconsent")
include(":feature:privacypolicy")
include(":feature:termsofservice")
include(":benchmark")

0 comments on commit 4ca98c6

Please sign in to comment.