BaseLine Profile 이란?
Android 런타임(ART) 이 설치 중에 중요한 경로를 기계어 코드로 사전 컴파일하는 데 사용하는 APK에 포함된 클래스 및 메서드 목록입니다. BaseLine Profile은 앱의 시작을 최적화하고, 버벅거림을 줄이고, 최종 사용자가 경험하는 성능을 개선할 수 있도록 합니다.
Macrobenchmark ??
Android M(API 23) 이상을 실행하는 기기의 앱과 관련된 시작 및 런타임 성능 테스트를 직접 작성할 수 있습니다.
@RunWith(AndroidJUnit4::class)
class ExampleStartupBenchmark{
@get:Rule
val benchmarkRule = MacrobenchmarkRule()
@Test
fun startup()= benchmarkRule.measureRepeated(
packageName = "co.mk.app", //패키지 네임
metrics =listOf(StartupTimingMetric()), // 앱 부팅 완료 옵션
iterations = 3, // 반복 횟수
startupMode = StartupMode.COLD // 부팅 종류 cold, warm, hot
){
pressHome()
startActivityAndWait() // 앱이 로드되는 순간
device.wait(Until.hasObject(By.text("What are you interested in?")), 30_000) // 앱이 완전히 로드 된 후
// val recycler = device.findObject(By.res("mypackage.myapp", "recycler_id"))
// recycler.setGestureMargin(device.displayWidth / 5)
//
// // Scroll down several times
// for (i in 1..10) {
// recycler.scroll(Direction.DOWN, 2f)
// device.waitForIdle()
// }
}
}
💡 Test 실행 시 Json 파일로 확인도 가능하다.
**<--build.gradle.kts-->**
create("benchmark"){
signingConfig = signingConfigs.getByName("debug")
matchingFallbacks +=listOf("release")
isDebuggable = false
proguardFiles("baseline-profiles-rules.pro")
}
@OptIn(ExperimentalBaselineProfilesApi::class)
@RunWith(AndroidJUnit4ClassRunner::class)
class BaselineProfileGenerator{
@get:Rule
val rule = BaselineProfileRule()
@Test
fun generate()= rule.collectBaselineProfile(
"co.mk.app",
){
startActivityAndWait() // 앱이 로드되는 순간
device.wait(Until.hasObject(By.text("What are you interested in?")), 30_000) // 앱이 완전히 로드 된 후
}
}
**<--benchmark/build.gradle.kts-->**
testOptions{
managedDevices{
devices{
create("pixel2Api31", ManagedVirtualDevice::class){
device = "Pixel 2"
apiLevel = 31
systemImageSource = "aosp"
}
}
}
}
파일 이름을 baseline-prof로 변경
static.com/859cd9dd-bfc7-4b49-bf76-e37a3f91491f/Untitled.png)
@RunWith(AndroidJUnit4::class)
class ExampleStartupBenchmark{
@get:Rule
val benchmarkRule = MacrobenchmarkRule()
@Test
fun startupCompilationNone()= startup(CompilationMode.None())
// 완전한 AOT
@Test
fun startupCompilationPartial()= startup(CompilationMode.Partial())
// 부분적인 AOT
fun startup(compilationMode: CompilationMode)= benchmarkRule.measureRepeated(
packageName = "co.mk.app",
metrics =listOf(StartupTimingMetric()),
iterations = 3,
compilationMode = compilationMode,
startupMode = StartupMode.COLD
){
pressHome()
startActivityAndWait()
device.wait(Until.hasObject(By.text("What are you interested in?")), 30_000)
}
}
1. Run 결과 창을 통한 내용 확인
좋은 글 감사합니다!