-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feat/#135 벤치마크 적용
- Loading branch information
Showing
13 changed files
with
187 additions
and
12 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
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,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" | ||
} | ||
} |
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 @@ | ||
<manifest /> |
39 changes: 39 additions & 0 deletions
39
benchmark/src/main/java/com/withpeace/withpeace/benchmark/ExampleStartupBenchmark.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,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() | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
benchmark/src/main/java/com/withpeace/withpeace/benchmark/home/HomeActions.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,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) | ||
} |
36 changes: 36 additions & 0 deletions
36
benchmark/src/main/java/com/withpeace/withpeace/benchmark/home/HomeBenchMark.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,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() | ||
} | ||
} |
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 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