-
Notifications
You must be signed in to change notification settings - Fork 0
[feat/#83] baselineprofile 적용 #84
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /build |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| plugins { | ||
| alias(libs.plugins.android.test) | ||
| alias(libs.plugins.jetbrains.kotlin.android) | ||
| alias(libs.plugins.baselineprofile) | ||
| } | ||
|
|
||
| android { | ||
| namespace = "com.kiero.baselineprofile" | ||
| compileSdk { | ||
| version = release(36) | ||
| } | ||
|
|
||
| compileOptions { | ||
| sourceCompatibility = JavaVersion.VERSION_11 | ||
| targetCompatibility = JavaVersion.VERSION_11 | ||
| } | ||
|
|
||
| kotlinOptions { | ||
| jvmTarget = "11" | ||
| } | ||
|
|
||
| defaultConfig { | ||
| minSdk = 28 | ||
| targetSdk = 36 | ||
|
|
||
| testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
| } | ||
|
|
||
| targetProjectPath = ":app" | ||
|
|
||
| flavorDimensions += listOf("version") | ||
| productFlavors { | ||
| create("parent") { dimension = "version" } | ||
| create("child") { dimension = "version" } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| // This is the configuration block for the Baseline Profile plugin. | ||
| // You can specify to run the generators on a managed devices or connected devices. | ||
| baselineProfile { | ||
| useConnectedDevices = true | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation(libs.androidx.junit) | ||
| implementation(libs.androidx.espresso.core) | ||
| implementation(libs.androidx.uiautomator) | ||
| implementation(libs.androidx.benchmark.macro.junit4) | ||
| } | ||
|
|
||
| androidComponents { | ||
| onVariants { v -> | ||
| val artifactsLoader = v.artifacts.getBuiltArtifactsLoader() | ||
| v.instrumentationRunnerArguments.put( | ||
| "targetAppId", | ||
| v.testedApks.map { artifactsLoader.load(it)?.applicationId } | ||
| ) | ||
| } | ||
| } |
| 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,89 @@ | ||
| package com.kiero.baselineprofile.benchmarks | ||
|
|
||
| import androidx.benchmark.macro.BaselineProfileMode | ||
| 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 androidx.test.filters.LargeTest | ||
| import androidx.test.platform.app.InstrumentationRegistry | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
|
|
||
| /** | ||
| * This test class benchmarks the speed of app startup. | ||
| * Run this benchmark to verify how effective a Baseline Profile is. | ||
| * It does this by comparing [androidx.benchmark.macro.CompilationMode.None], which represents the app with no Baseline | ||
| * Profiles optimizations, and [androidx.benchmark.macro.CompilationMode.Partial], which uses Baseline Profiles. | ||
| * | ||
| * Run this benchmark to see startup measurements and captured system traces for verifying | ||
| * the effectiveness of your Baseline Profiles. You can run it directly from Android | ||
| * Studio as an instrumentation test, or run all benchmarks for a variant, for example benchmarkRelease, | ||
| * with this Gradle task: | ||
| * ``` | ||
| * ./gradlew :baselineprofile:connectedBenchmarkReleaseAndroidTest | ||
| * ``` | ||
| * | ||
| * You should run the benchmarks on a physical device, not an Android emulator, because the | ||
| * emulator doesn't represent real world performance and shares system resources with its host. | ||
| * | ||
| * For more information, see the [Macrobenchmark documentation](https://d.android.com/macrobenchmark#create-macrobenchmark) | ||
| * and the [instrumentation arguments documentation](https://d.android.com/topic/performance/benchmarking/macrobenchmark-instrumentation-args). | ||
| **/ | ||
| @RunWith(AndroidJUnit4::class) | ||
| @LargeTest | ||
| class StartupBenchmarks { | ||
|
|
||
| @get:Rule | ||
| val rule = MacrobenchmarkRule() | ||
|
|
||
| private val targetPackageName = InstrumentationRegistry.getArguments().getString("targetAppId") | ||
| ?: "com.kiero.parent" | ||
|
|
||
| @Test | ||
| fun startupCompilationNone() = | ||
| benchmark(CompilationMode.None()) | ||
|
|
||
| @Test | ||
| fun startupCompilationBaselineProfiles() = | ||
| benchmark(CompilationMode.Partial(BaselineProfileMode.Require)) | ||
|
|
||
| @Test | ||
| fun startupWithBaselineProfile() = rule.measureRepeated( | ||
| packageName = targetPackageName, | ||
| metrics = listOf(StartupTimingMetric()), | ||
| iterations = 5, | ||
| startupMode = StartupMode.COLD, | ||
| compilationMode = CompilationMode.Partial() | ||
| ) { | ||
| pressHome() | ||
| startActivityAndWait() | ||
| } | ||
| private fun benchmark(compilationMode: CompilationMode) { | ||
| // The application id for the running build variant is read from the instrumentation arguments. | ||
| rule.measureRepeated( | ||
| packageName = targetPackageName, | ||
| metrics = listOf(StartupTimingMetric()), | ||
| compilationMode = compilationMode, | ||
| startupMode = StartupMode.COLD, | ||
| iterations = 10, | ||
| setupBlock = { | ||
| pressHome() | ||
| }, | ||
| measureBlock = { | ||
| startActivityAndWait() | ||
|
|
||
| // TODO Add interactions to wait for when your app is fully drawn. | ||
| // The app is fully drawn when Activity.reportFullyDrawn is called. | ||
| // For Jetpack Compose, you can use ReportDrawn, ReportDrawnWhen and ReportDrawnAfter | ||
| // from the AndroidX Activity library. | ||
|
|
||
| // Check the UiAutomator documentation for more information on how to | ||
| // interact with the app. | ||
| // https://d.android.com/training/testing/other-components/ui-automator | ||
| } | ||
| ) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package com.kiero.baselineprofile.generator | ||
|
|
||
| import androidx.benchmark.macro.junit4.BaselineProfileRule | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| import androidx.test.filters.LargeTest | ||
| import androidx.test.platform.app.InstrumentationRegistry | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
|
|
||
| /** | ||
| * This test class generates a basic startup baseline profile for the target package. | ||
| * | ||
| * We recommend you start with this but add important user flows to the profile to improve their performance. | ||
| * Refer to the [baseline profile documentation](https://d.android.com/topic/performance/baselineprofiles) | ||
| * for more information. | ||
| * | ||
| * You can run the generator with the "Generate Baseline Profile" run configuration in Android Studio or | ||
| * the equivalent `generateBaselineProfile` gradle task: | ||
| * ``` | ||
| * ./gradlew :app:generateReleaseBaselineProfile | ||
| * ``` | ||
| * The run configuration runs the Gradle task and applies filtering to run only the generators. | ||
| * | ||
| * Check [documentation](https://d.android.com/topic/performance/benchmarking/macrobenchmark-instrumentation-args) | ||
| * for more information about available instrumentation arguments. | ||
| * | ||
| * After you run the generator, you can verify the improvements running the [com.kiero.baselineprofile.benchmarks.StartupBenchmarks] benchmark. | ||
| * | ||
| * When using this class to generate a baseline profile, only API 33+ or rooted API 28+ are supported. | ||
| * | ||
| * The minimum required version of androidx.benchmark to generate a baseline profile is 1.2.0. | ||
| **/ | ||
| @RunWith(AndroidJUnit4::class) | ||
| @LargeTest | ||
| class BaselineProfileGenerator { | ||
|
|
||
| @get:Rule | ||
| val rule = BaselineProfileRule() | ||
|
|
||
| @Test | ||
| fun generate() { | ||
| // The application id for the running build variant is read from the instrumentation arguments. | ||
| rule.collect( | ||
| packageName = InstrumentationRegistry.getArguments().getString("targetAppId") | ||
| ?: throw Exception("targetAppId not passed as instrumentation runner arg"), | ||
|
|
||
| // See: https://d.android.com/topic/performance/baselineprofiles/dex-layout-optimizations | ||
| includeInStartupProfile = true | ||
| ) { | ||
| // This block defines the app's critical user journey. Here we are interested in | ||
| // optimizing for app startup. But you can also navigate and scroll through your most important UI. | ||
|
|
||
| // Start default activity for your app | ||
| pressHome() | ||
| startActivityAndWait() | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p3) 지금은 기본 앱 시작만 적용된거같은데, 어디까지 이거를 적용시키실 생각이신가요 ?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pr 에 올려놨듯이, 로그인 관련해서 좀 더 공부해보고 이 후 화면까지 적용해볼 예정입니다! 말씀대로 GIF나 화면 렌더링시 데이터가 많이 필요한 곳 위주로 테스트해볼 계획입니당 |
||
| // TODO Write more interactions to optimize advanced journeys of your app. | ||
| // For example: | ||
| // 1. Wait until the content is asynchronously loaded | ||
| // 2. Scroll the feed content | ||
| // 3. Navigate to detail screen | ||
|
|
||
| // Check UiAutomator documentation for more information how to interact with the app. | ||
| // https://d.android.com/training/testing/other-components/ui-automator | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,4 +22,4 @@ dependencyResolutionManagement { | |
|
|
||
| rootProject.name = "Kiero" | ||
| include(":app") | ||
| include(":baselineprofile") | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p3: 순수 궁금증인데 추가된 이유가 있을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이게 처음에 테스트를 돌려봤는데, 해당 model 에서만 직렬화 과정에서 오류가 난다고 계속 뜨더라구요 ㅜㅜ 난독화나 최적화 과정에서 누락될 가능성이 있다고해서 어노테이션 추가했습니답
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아주 굿입니다용