Skip to content

Commit e176bb7

Browse files
committed
Baseline prof-debugging
1 parent 931cfdd commit e176bb7

6 files changed

Lines changed: 49 additions & 53 deletions

File tree

‎app/build.gradle.kts‎

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ android {
3333
applicationId = "com.android.developers.androidify"
3434
versionCode = libs.versions.appVersionCode.get().toInt()
3535
versionName = libs.versions.appVersionName.get()
36+
37+
testInstrumentationRunnerArguments["androidx.benchmark.suppressErrors"] = "EMULATOR"
3638
}
3739

3840
buildTypes {
@@ -45,29 +47,17 @@ android {
4547
isDebuggable = false
4648
}
4749
release {
48-
isShrinkResources = true
4950
isMinifyEnabled = true
50-
proguardFiles(
51-
getDefaultProguardFile("proguard-android-optimize.txt"),
52-
"proguard-rules.pro",
53-
)
51+
isShrinkResources = true
52+
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
5453
configure<CrashlyticsExtension> {
5554
mappingFileUploadEnabled = true
5655
}
56+
signingConfig = signingConfigs.getByName("debug")
57+
5758
// Conditionally apply signingConfig for release builds
5859
// If the 'CI_BUILD' project property is set to 'true', do not assign a signingConfig.
5960
// Otherwise, (e.g., for local Android Studio builds), sign with the debug key.
60-
if (project.findProperty("CI_BUILD")?.toString()?.toBoolean() == true) {
61-
// For CI builds, we want an unsigned artifact.
62-
// No signingConfig is assigned here.
63-
// The bundleRelease task will produce an unsigned AAB.
64-
println("CI_BUILD property detected. Release build will be unsigned by Gradle.")
65-
} else {
66-
// For local builds (not CI), sign with the debug key to allow easy deployment.
67-
// This ensures you can select the "release" variant in Android Studio and run it.
68-
println("Not a CI_BUILD or CI_BUILD property not set. Signing release build with debug key.")
69-
signingConfig = signingConfigs.getByName("debug")
70-
}
7161
}
7262
}
7363
testOptions {
@@ -83,8 +73,9 @@ android {
8373
}
8474
}
8575

86-
baselineProfile() {
76+
baselineProfile {
8777
dexLayoutOptimization = true
78+
automaticGenerationDuringBuild = true
8879
}
8980

9081
spdxSbom {

‎app/proguard-rules.pro‎

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,7 @@
1919
# If you keep the line number information, uncomment this to
2020
# hide the original source file name.
2121
#-renamesourcefileattribute SourceFile
22-
-keep class com.firebase.** { *; }
23-
-keep interface com.firebase.** { *; }
24-
-keep class org.apache.** { *; }
25-
-keepnames class com.fasterxml.jackson.** { *; }
26-
-keepnames class javax.servlet.** { *; }
27-
-keepnames class org.ietf.jgss.** { *; }
22+
2823
-dontwarn org.w3c.dom.**
2924
-dontwarn org.joda.time.**
3025
-dontwarn org.shaded.apache.**
@@ -43,25 +38,16 @@
4338

4439
# Ignore missing Java SE annotation processing classes, often from libraries like AutoValue
4540
-dontwarn javax.lang.model.**
46-
41+
-dontoptimize
42+
-dontobfuscate
4743
# OkHttp
48-
-keep class okhttp3.** { *; }
49-
-keep interface okhttp3.** { *; }
50-
-dontwarn okhttp3.**
44+
-dontwarn okhttp3.internal.Util
45+
5146

5247
# Ignore SAX parser warning
5348
-dontwarn org.xml.sax.**
5449

5550
# WorkManager / Room R8 Full Mode keep rules
5651
-keep class androidx.work.impl.WorkDatabase_Impl { *; }
57-
-keep class androidx.work.impl.** { *; }
5852
-dontwarn androidx.work.impl.**
5953

60-
# Keep list of constructors used by reflection (Workers)
61-
-keep class * extends androidx.work.ListenableWorker {
62-
<init>(android.content.Context, androidx.work.WorkerParameters);
63-
}
64-
-keep class * extends androidx.work.Worker {
65-
<init>(android.content.Context, androidx.work.WorkerParameters);
66-
}
67-

‎app/src/main/AndroidManifest.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
tools:targetApi="31">
4545
<profileable
4646
android:shell="true"
47-
tools:targetApi="29" />
47+
/>
4848

4949
<provider
5050
android:name="androidx.core.content.FileProvider"

‎benchmark/build.gradle.kts‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ android {
4747

4848
defaultConfig {
4949
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
50+
testInstrumentationRunnerArguments["androidx.benchmark.suppressErrors"] = "EMULATOR"
5051
}
5152

5253
buildTypes {
@@ -62,14 +63,6 @@ android {
6263

6364
targetProjectPath = ":app"
6465
experimentalProperties["android.experimental.self-instrumenting"] = true
65-
66-
testOptions.managedDevices.allDevices {
67-
create("pixel6Api34", ManagedVirtualDevice::class.java) {
68-
device = "Pixel 6"
69-
apiLevel = 34
70-
systemImageSource = "google"
71-
}
72-
}
7366
}
7467

7568
kotlin {
@@ -81,8 +74,6 @@ kotlin {
8174
// This is the configuration block for the Baseline Profile plugin.
8275
// You can specify to run the generators on a managed devices or connected devices.
8376
baselineProfile {
84-
managedDevices += "pixel6Api34"
85-
skipBenchmarksOnEmulator = true
8677
useConnectedDevices = true
8778
}
8879

‎benchmark/src/main/kotlin/com/android/developers/androidify/benchmark/PromptBenchmark.kt‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ package com.android.developers.androidify.benchmark
1717

1818
import android.os.Build
1919
import androidx.annotation.RequiresApi
20+
import androidx.benchmark.macro.ArtMetric
21+
import androidx.benchmark.macro.BaselineProfileMode
2022
import androidx.benchmark.macro.CompilationMode
2123
import androidx.benchmark.macro.ExperimentalMetricApi
2224
import androidx.benchmark.macro.FrameTimingMetric
@@ -50,12 +52,26 @@ class PromptBenchmark {
5052
@Test
5153
fun promptBenchmarkFullCompilation() = promptBenchmark(CompilationMode.Full())
5254

55+
@Test
56+
fun speedProfileBaselineProfile() = promptBenchmark(
57+
CompilationMode.Partial(BaselineProfileMode.Require)
58+
)
59+
60+
@Test
61+
fun speedProfileWarmup() = promptBenchmark(
62+
CompilationMode.Partial(BaselineProfileMode.Disable, warmupIterations = 3)
63+
)
64+
65+
66+
67+
5368
@OptIn(ExperimentalMetricApi::class)
5469
private fun promptBenchmark(compilationMode: CompilationMode) {
5570
benchmarkRule.measureRepeated(
5671
packageName = "com.android.developers.androidify",
5772
compilationMode = compilationMode,
5873
metrics = listOf(
74+
ArtMetric(),
5975
StartupTimingMetric(),
6076
FrameTimingMetric(),
6177
MemoryUsageMetric(MemoryUsageMetric.Mode.Max),

‎benchmark/src/main/kotlin/com/android/developers/androidify/benchmark/StartupBenchmark.kt‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ package com.android.developers.androidify.benchmark
1717

1818
import android.os.Build
1919
import androidx.annotation.RequiresApi
20+
import androidx.benchmark.macro.ArtMetric
21+
import androidx.benchmark.macro.BaselineProfileMode
2022
import androidx.benchmark.macro.CompilationMode
2123
import androidx.benchmark.macro.ExperimentalMetricApi
2224
import androidx.benchmark.macro.FrameTimingMetric
@@ -41,23 +43,33 @@ class StartupBenchmark {
4143
fun startupNoPrecompilation() = startup(CompilationMode.None())
4244

4345
@Test
44-
fun startupBaselineProfile() = startup(CompilationMode.DEFAULT)
46+
fun startUpProfileBaselineProfileUseIfAvailable() = startup(
47+
CompilationMode.Partial(BaselineProfileMode.UseIfAvailable, warmupIterations = 3)
48+
)
4549

4650
@Test
47-
fun startupFullCompilation() = startup(CompilationMode.Full())
51+
fun startUpProfileBaselineProfileRequired() = startup(
52+
CompilationMode.Partial(BaselineProfileMode.Require, warmupIterations = 3)
53+
)
54+
55+
@Test
56+
fun startProfileBaselineProfile() = startup(
57+
CompilationMode.Partial(BaselineProfileMode.Disable, warmupIterations = 3)
58+
)
4859

4960
@OptIn(ExperimentalMetricApi::class)
5061
private fun startup(compilationMode: CompilationMode) = benchmarkRule.measureRepeated(
5162
packageName = "com.android.developers.androidify",
5263
metrics = listOf(
5364
StartupTimingMetric(),
54-
FrameTimingMetric(),
55-
MemoryUsageMetric(MemoryUsageMetric.Mode.Max),
56-
PowerMetric(PowerMetric.Type.Power()),
65+
ArtMetric(),
5766
),
58-
iterations = 10,
67+
iterations = 5,
5968
compilationMode = compilationMode,
6069
startupMode = StartupMode.COLD,
70+
setupBlock = {
71+
killProcess()
72+
}
6173
) {
6274
uiAutomator {
6375
startApp(packageName = packageName)

0 commit comments

Comments
 (0)