-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(baselineprofile): Add BaseLineProfile && Benchmark
feat(baselineprofile): Add Warm Hot BenchMark feat(baselineprofile): Remove Test Device
- Loading branch information
Showing
10 changed files
with
179 additions
and
4 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
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 @@ | ||
import com.android.build.api.dsl.ManagedVirtualDevice | ||
|
||
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed | ||
plugins { | ||
alias(libs.plugins.androidTest) | ||
alias(libs.plugins.kotlin.android) | ||
alias(libs.plugins.androidx.baselineprofile) | ||
} | ||
|
||
android { | ||
namespace = "org.sopt.official.benchmark" | ||
compileSdk = 34 | ||
|
||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
targetCompatibility = JavaVersion.VERSION_17 | ||
} | ||
|
||
kotlinOptions { | ||
jvmTarget = "17" | ||
} | ||
|
||
defaultConfig { | ||
minSdk = 28 | ||
targetSdk = 34 | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
val benchmark by creating { | ||
isDebuggable = false | ||
signingConfig = signingConfigs.getByName("debug") | ||
matchingFallbacks.add("release") | ||
} | ||
} | ||
|
||
targetProjectPath = ":app" | ||
experimentalProperties["android.experimental.self-instrumenting"] = true | ||
} | ||
|
||
dependencies { | ||
implementation(libs.androidx.test.junit) | ||
implementation(libs.androidx.test.espresso) | ||
implementation(libs.androidx.uiautomator) | ||
implementation(libs.benchmark.macro.junit4) | ||
} | ||
|
||
androidComponents { | ||
beforeVariants { | ||
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 /> |
24 changes: 24 additions & 0 deletions
24
benchmark/src/main/java/org/sopt/official/benchmark/BaselineProfileGenerator.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,24 @@ | ||
package org.sopt.official.benchmark | ||
|
||
import androidx.benchmark.macro.junit4.BaselineProfileRule | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.filters.LargeTest | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
@LargeTest | ||
class BaselineProfileGenerator { | ||
|
||
@get:Rule | ||
val rule = BaselineProfileRule() | ||
|
||
@Test | ||
fun generate() { | ||
rule.collect(PACKAGE_NAME) { | ||
pressHome() | ||
startActivityAndWait() | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
benchmark/src/main/java/org/sopt/official/benchmark/Constant.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,3 @@ | ||
package org.sopt.official.benchmark | ||
|
||
internal const val PACKAGE_NAME: String = "org.sopt.official" |
69 changes: 69 additions & 0 deletions
69
benchmark/src/main/java/org/sopt/official/benchmark/StartupBenchmarks.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,69 @@ | ||
package org.sopt.official.benchmark | ||
|
||
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.internal.runner.junit4.AndroidJUnit4ClassRunner | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4ClassRunner::class) | ||
class ColdStartupBenchmark : AbstractStartupBenchmark(StartupMode.COLD) | ||
|
||
/** | ||
* Run this benchmark from Studio to see startup measurements, and captured system traces | ||
* for investigating your app's performance from a warm state. | ||
*/ | ||
@RunWith(AndroidJUnit4ClassRunner::class) | ||
class WarmStartupBenchmark : AbstractStartupBenchmark(StartupMode.WARM) | ||
|
||
/** | ||
* Run this benchmark from Studio to see startup measurements, and captured system traces | ||
* for investigating your app's performance from a hot state. | ||
*/ | ||
@RunWith(AndroidJUnit4ClassRunner::class) | ||
class HotStartupBenchmark : AbstractStartupBenchmark(StartupMode.HOT) | ||
|
||
/** | ||
* Base class for benchmarks with different startup modes. | ||
* Enables app startups from various states of baseline profile or [CompilationMode]s. | ||
*/ | ||
abstract class AbstractStartupBenchmark(private val startupMode: StartupMode) { | ||
@get:Rule | ||
val benchmarkRule = MacrobenchmarkRule() | ||
|
||
@Test | ||
fun startupNoCompilation() = startup(CompilationMode.None()) | ||
|
||
@Test | ||
fun startupBaselineProfileDisabled() = startup( | ||
CompilationMode.Partial( | ||
baselineProfileMode = BaselineProfileMode.Disable, | ||
warmupIterations = 3, | ||
), | ||
) | ||
|
||
@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()), | ||
compilationMode = compilationMode, | ||
iterations = 5, | ||
startupMode = startupMode, | ||
setupBlock = { | ||
pressHome() | ||
}, | ||
measureBlock = { | ||
startActivityAndWait() | ||
} | ||
) | ||
} |
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 |
---|---|---|
|
@@ -35,4 +35,5 @@ include( | |
":feature:mypage", | ||
":feature:soptamp", | ||
":feature:poke", | ||
":benchmark" | ||
) |