Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#38 benchmark #40

Merged
merged 8 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11,219 changes: 11,219 additions & 0 deletions app/src/main/baseline-prof.txt

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions benchmarks/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ android {
defaultConfig {
minSdk = 28
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments["androidx.benchmark.suppressErrors"] = "LOW-BATTERY"

buildConfigField("String", "APP_BUILD_TYPE_SUFFIX", "\"\"")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package com.najudoryeong.mineme

import androidx.benchmark.macro.MacrobenchmarkScope


fun MacrobenchmarkScope.setTestJwtAndStartApp(jwt: String) {
val command = "am start -n $PACKAGE_NAME/MainActivity -e TEST_JWT $jwt"
device.executeShellCommand(command)
}




2 changes: 1 addition & 1 deletion benchmarks/src/main/java/com/najudoryeong/mineme/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fun UiDevice.flingElementDownUp(element: UiObject2) {
waitForIdle()
// 위 슬라이드
element.fling(Direction.UP)

}


Expand All @@ -34,7 +35,6 @@ 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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,41 @@ package com.najudoryeong.mineme.baselineprofile
import androidx.benchmark.macro.junit4.BaselineProfileRule
import com.najudoryeong.mineme.PACKAGE_NAME
import com.najudoryeong.mineme.home.homeYouWaitForContent
import com.najudoryeong.mineme.settings.goToSettingsScreen
import com.najudoryeong.mineme.story.goToDetailStory
import com.najudoryeong.mineme.story.goToStory
import com.najudoryeong.mineme.story.selectRegionFromDropdown
import com.najudoryeong.mineme.story.storyScrollPostDownUp
import com.najudoryeong.mineme.story.storyWaitForPost
import org.junit.Rule
import org.junit.Test

class BaselineProfileGenerator {
@get:Rule
val baselineProfileRule = BaselineProfileRule()


@Test
fun generate() = baselineProfileRule.collect(PACKAGE_NAME) {
fun generate() =
baselineProfileRule.collect(PACKAGE_NAME) {

pressHome()
startActivityAndWait()

homeYouWaitForContent()

//goToStory
goToStory()
storyWaitForPost()

// scroll Region and select Region
storyScrollPostDownUp("story:posts")
selectRegionFromDropdown("경남")

// goToDetail and Scroll
goToDetailStory()
storyScrollPostDownUp("detail:posts")
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.najudoryeong.mineme.settings

import androidx.benchmark.macro.MacrobenchmarkScope
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Until


fun MacrobenchmarkScope.goToSettingsScreen() {
device.findObject(By.res("Settings")).click()
device.waitForIdle()
device.wait(Until.hasObject(By.res("DoTopAppBar")), 2_000)
val topAppBar = device.findObject(By.res("DoTopAppBar"))
topAppBar.wait(Until.hasObject(By.text("Settings")), 2_000)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.najudoryeong.mineme.settings

import androidx.benchmark.macro.CompilationMode
import androidx.benchmark.macro.FrameTimingMetric
import androidx.benchmark.macro.StartupMode
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.najudoryeong.mineme.PACKAGE_NAME
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class SettingsBenchmark {

@get:Rule
val benchmarkRule = MacrobenchmarkRule()


@Test
fun benchmarkStateChangeCompilationBaselineProfile() =
benchmarkStateChange(CompilationMode.Partial())


private fun benchmarkStateChange(compilationMode: CompilationMode) =
benchmarkRule.measureRepeated(
packageName = PACKAGE_NAME,
metrics = listOf(FrameTimingMetric()),
compilationMode = compilationMode,
iterations = 10,
startupMode = StartupMode.WARM,
setupBlock = {
pressHome()
startActivityAndWait()
device.waitForIdle()
},
) {
goToSettingsScreen()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@ class StartupBenchmark {
@get:Rule
val benchmarkRule = MacrobenchmarkRule()




@Test
fun startupNoCompilation() = startup(CompilationMode.None())
fun startUpNoCompilation() = startup(CompilationMode.None())


@Test
fun startupBaselineProfile() =
startup(CompilationMode.Partial(baselineProfileMode = BaselineProfileMode.Require))



@Test
fun startupBaselineProfileDisabled() = startup(
Expand All @@ -29,13 +39,11 @@ class StartupBenchmark {
),
)

@Test
fun startupBaselineProfile() =
startup(CompilationMode.Partial(baselineProfileMode = BaselineProfileMode.Require))

@Test
fun startupFullCompilation() = startup(CompilationMode.Full())


private fun startup(compilationMode: CompilationMode) = benchmarkRule.measureRepeated(
packageName = PACKAGE_NAME,
metrics = listOf(StartupTimingMetric()),
Expand All @@ -51,3 +59,10 @@ class StartupBenchmark {
}
}








Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.najudoryeong.mineme.story

import androidx.benchmark.macro.CompilationMode
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 com.najudoryeong.mineme.PACKAGE_NAME
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

private val dropdownRegion = listOf("경남","서울","부산")

@RunWith(AndroidJUnit4::class)
class RegionStoryRecompositionBenchmark {

@get:Rule
val benchmarkRule = MacrobenchmarkRule()


@Test
fun benchmarkStateChangeNoCompilation() =
benchmarkStateChange(CompilationMode.None())

@Test
fun benchmarkStateChangeCompilationBaselineProfile() =
benchmarkStateChange(CompilationMode.Partial())


private fun benchmarkStateChange(compilationMode: CompilationMode) =
benchmarkRule.measureRepeated(
packageName = PACKAGE_NAME,
metrics = listOf(FrameTimingMetric()),
compilationMode = compilationMode,
iterations = 10,
startupMode = StartupMode.WARM,
setupBlock = {
pressHome()
startActivityAndWait()
goToStory()
},
) {
storyWaitForPost()
repeat(3) {
selectRegionFromDropdown(dropdownRegion[it])
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@ import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith


@RunWith(AndroidJUnit4::class)
class ScrollStoryListBenchmark {
class ScrollDetailStoryListBenchmark {

@get:Rule
val benchmarkRule = MacrobenchmarkRule()

@Test
fun benchmarkStateChangeNoCompilation() =
benchmarkStateChange(CompilationMode.None())

@Test
fun benchmarkStateChangeCompilationBaselineProfile() = benchmarkStateChange(CompilationMode.Partial())


private fun benchmarkStateChange(compilationMode: CompilationMode) =
benchmarkRule.measureRepeated(
packageName = PACKAGE_NAME,
Expand All @@ -30,15 +37,13 @@ class ScrollStoryListBenchmark {
setupBlock = {
pressHome()
startActivityAndWait()
device.waitForIdle()
device.findObject(By.res("Story")).click()
goToStory()
},
) {
storyWaitForPost()
goToDetailStory()
repeat(3) {
storyScrollPostDownUp()
storyScrollPostDownUp("detail:posts")
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.najudoryeong.mineme.story

import androidx.benchmark.macro.CompilationMode
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 com.najudoryeong.mineme.PACKAGE_NAME
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

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


@Test
fun benchmarkStateChangeNoCompilation() =
benchmarkStateChange(CompilationMode.None())

@Test
fun benchmarkStateChangeCompilationBaselineProfile() =
benchmarkStateChange(CompilationMode.Partial())

private fun benchmarkStateChange(compilationMode: CompilationMode) =
benchmarkRule.measureRepeated(
packageName = PACKAGE_NAME,
// FrameTimingMetric을 사용하여 프레임 타이밍을 측정
metrics = listOf(FrameTimingMetric()),
compilationMode = compilationMode,
iterations = 10,
startupMode = StartupMode.WARM,
setupBlock = {
pressHome()
startActivityAndWait()
goToStory()
},
) {
storyWaitForPost()
repeat(3) {
storyScrollPostDownUp("story:posts")
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,58 @@ package com.najudoryeong.mineme.story

import androidx.benchmark.macro.MacrobenchmarkScope
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Direction
import androidx.test.uiautomator.StaleObjectException
import androidx.test.uiautomator.UiObject2
import androidx.test.uiautomator.Until
import com.najudoryeong.mineme.flingElementDownUp
import com.najudoryeong.mineme.waitAndFindObject


fun MacrobenchmarkScope.goToStory() {
device.waitAndFindObject(By.res("Story"), 3_000).click()
device.waitForIdle()
}


fun MacrobenchmarkScope.storyWaitForPost() {
device.wait(Until.hasObject(By.text("전체")),30_000)
device.wait(Until.hasObject(By.text("경남 창원시")), 3_000)
}

fun MacrobenchmarkScope.goToDetailStory() {
device.waitAndFindObject(By.text("경남 창원시"), 3_000).click()
device.waitForIdle()
}

fun MacrobenchmarkScope.changeToCalenderView() {
device.waitAndFindObject(By.res("Story:ChangeView"), 3_000).click()
device.waitForIdle()
device.hasObject(By.text("Story:CalendarView"))
}

fun MacrobenchmarkScope.storyScrollPostDownUp() {
val postList = device.wait(Until.findObject(By.res("story:posts")), 2_000)

fun MacrobenchmarkScope.storyScrollPostDownUp(listTag: String) {
val postList = device.waitAndFindObject(By.res(listTag), 3_000)
device.flingElementDownUp(postList)
}


fun MacrobenchmarkScope.selectRegionFromDropdown(regionName: String) {
device.waitAndFindObject(By.res("RegionDropDown"), 3_000).click()
device.waitForIdle()

device.waitAndFindObject(By.text(regionName), 3_000).click()
device.waitForIdle()
}

fun MacrobenchmarkScope.changeDateUsingPicker() {
device.waitAndFindObject(By.res("Story:DatePicker"), 3_000).click()
val pickText = device.waitAndFindObject(By.desc("MonthPicker"), 3_000)

pickText.parent.scroll(Direction.UP, 0.25f)
device.waitForIdle()

device.waitAndFindObject(By.text("확인"), 3_000).click()
device.waitForIdle()
}

Loading