Skip to content

Commit

Permalink
refactor: baseline profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
f-arslan committed Feb 21, 2024
1 parent 4f41f40 commit 22e5967
Show file tree
Hide file tree
Showing 18 changed files with 97 additions and 46 deletions.
8 changes: 6 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ android {
}

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

}

val keystorePropertiesFile = rootProject.file("keystore.properties")
Expand All @@ -40,7 +39,12 @@ android {


buildTypes {
release {
getByName("debug") {
signingConfig = signingConfigs.getByName("config")
}


getByName("release") {
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28"
tools:ignore="ScopedStorage" />

<application
android:name=".GmHiltApp"
android:allowBackup="true"
Expand Down
28 changes: 22 additions & 6 deletions benchmarks/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
import com.android.build.api.dsl.ManagedVirtualDevice

plugins {
alias(libs.plugins.android.test)
alias(libs.plugins.jetbrains.kotlin.android)
alias(libs.plugins.baselineprofile)
alias(libs.plugins.gptmap.android.test)
}

android {
namespace = "com.espressodev.benchmarks"
compileSdk = 34

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = "1.8"
}

defaultConfig {
minSdk = 28
targetSdk = 34

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

targetProjectPath = ":app"

// This code creates the gradle managed device used to generate baseline profiles.
// To use GMD please invoke generation through the command line:
// ./gradlew :app:generateBaselineProfile
testOptions.managedDevices.devices {
create<ManagedVirtualDevice>("pixel6Api34") {
device = "Pixel 6"
Expand All @@ -32,8 +48,8 @@ baselineProfile {
}

dependencies {
implementation(libs.androidx.test.ext)
implementation(libs.androidx.espresso.core)
implementation(libs.androidx.uiautomator)
implementation(libs.androidx.benchmark.macro.junit4)
}
implementation(libs.androidx.junit)
implementation(libs.androidx.test.espresso.core)
implementation(libs.androidx.test.uiautomator)
implementation(libs.androidx.benchmark.macro)
}
2 changes: 1 addition & 1 deletion benchmarks/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<manifest />
<manifest />
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.espressodev.benchmarks.baselineprofile
package com.espressodev.benchmarks

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

/**
* This test class generates a basic startup baseline profile for the target package.
Expand All @@ -28,6 +31,8 @@ import org.junit.Test
*
* The minimum required version of androidx.benchmark to generate a baseline profile is 1.2.0.
**/
@RunWith(AndroidJUnit4::class)
@LargeTest
class BaselineProfileGenerator {

@get:Rule
Expand All @@ -38,6 +43,7 @@ class BaselineProfileGenerator {
// This example works only with the variant with application id `com.espressodev.gptmap`."
rule.collect(
packageName = "com.espressodev.gptmap",
maxIterations = 3,

// See: https://d.android.com/topic/performance/baselineprofiles/dex-layout-optimizations
includeInStartupProfile = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.espressodev.benchmarks.baselineprofile
package com.espressodev.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.rule.GrantPermissionRule
import com.espressodev.benchmarks.allowWriteToExternal
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

/**
* This test class benchmarks the speed of app startup.
Expand All @@ -31,6 +32,8 @@ import org.junit.Test
* 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
Expand All @@ -51,10 +54,9 @@ class StartupBenchmarks {
metrics = listOf(StartupTimingMetric()),
compilationMode = compilationMode,
startupMode = StartupMode.COLD,
iterations = 10,
iterations = 3,
setupBlock = {
pressHome()
allowWriteToExternal()
},
measureBlock = {
startActivityAndWait()
Expand All @@ -70,4 +72,4 @@ class StartupBenchmarks {
}
)
}
}
}

This file was deleted.

11 changes: 10 additions & 1 deletion build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@ tasks.withType<KotlinCompile>().configureEach {
}

dependencies {
compileOnly(libs.android.gradlePlugin)
compileOnly(libs.android.tools.common)
compileOnly(libs.firebase.crashlytics.gradlePlugin)
compileOnly(libs.kotlin.gradlePlugin)
compileOnly(libs.ksp.gradlePlugin)
compileOnly(libs.android.gradlePlugin)
compileOnly(libs.detekt.gradlePlugin)
}

tasks {
validatePlugins {
enableStricterValidation = true
failOnWarning = true
}
}

gradlePlugin {
plugins {
register("androidApplicationCompose") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import com.android.build.api.dsl.ApplicationExtension
import com.espressodev.gptmap.ext.implementation
import com.espressodev.gptmap.libs
import com.google.firebase.crashlytics.buildtools.gradle.CrashlyticsExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies

class AndroidApplicationFirebaseConventionPlugin : Plugin<Project> {
Expand All @@ -13,6 +16,8 @@ class AndroidApplicationFirebaseConventionPlugin : Plugin<Project> {
}

dependencies {
val bom = libs.findLibrary("firebase-bom").get()
add("implementation", platform(bom))
implementation(libs.findLibrary("firebase-auth").get())
implementation(libs.findLibrary("firebase-firestore").get())
implementation(libs.findLibrary("firebase-crashlytics").get())
Expand All @@ -21,6 +26,17 @@ class AndroidApplicationFirebaseConventionPlugin : Plugin<Project> {
implementation(libs.findLibrary("play-services-location").get())
implementation(libs.findLibrary("play-services-maps").get())
}

// extensions.configure<ApplicationExtension> {
// buildTypes.configureEach {
// // Disable the Crashlytics mapping file upload. This feature should only be
// // enabled if a Firebase backend is available and configured in
// // google-services.json.
// configure<CrashlyticsExtension> {
// mappingFileUploadEnabled = false
// }
// }
// }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

internal fun Project.configureAndroidCompose(
commonExtension: CommonExtension<*, *, *, *, *>,
commonExtension: CommonExtension<*, *, *, *, *, *>,
) {
commonExtension.apply {
buildFeatures {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.gradle.api.Project
internal fun LibraryAndroidComponentsExtension.disableUnnecessaryAndroidTests(
project: Project,
) = beforeVariants {
it.enableAndroidTest = it.enableAndroidTest
it.androidTest.enable = it.androidTest.enable
&& project.projectDir.resolve("src/androidTest").exists()
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.gradle.kotlin.dsl.invoke
* Configure project for Gradle managed devices
*/
internal fun configureGradleManagedDevices(
commonExtension: CommonExtension<*, *, *, *, *>,
commonExtension: CommonExtension<*, *, *, *, *, *>,
) {
val pixel4 = DeviceConfig("Pixel 4", 30, "aosp-atd")
val pixel6 = DeviceConfig("Pixel 6", 31, "aosp")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.espressodev.gptmap

import com.android.build.api.dsl.CommonExtension
import com.espressodev.gptmap.ext.androidTestImplementation
import com.espressodev.gptmap.ext.implementation
import org.gradle.api.JavaVersion
import org.gradle.api.Project
Expand All @@ -13,7 +12,7 @@ import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

internal fun Project.configureKotlinAndroid(
commonExtension: CommonExtension<*, *, *, *, *>,
commonExtension: CommonExtension<*, *, *, *, *, *>,
) {
commonExtension.apply {
compileSdk = 34
Expand Down Expand Up @@ -80,4 +79,3 @@ private fun Project.configureKotlin() {
}
}
}

5 changes: 2 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ buildscript {
}
dependencies {
classpath(libs.google.services)
classpath(libs.firebase.crashlytics.gradlePlugin)
classpath(libs.google.oss.licenses.plugin) {
exclude(group = "com.google.protobuf")
}
Expand Down Expand Up @@ -33,6 +32,7 @@ subprojects {
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.android.test) apply false
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.kotlin.serialization) apply false
alias(libs.plugins.firebase.crashlytics) apply false
Expand All @@ -41,7 +41,6 @@ plugins {
alias(libs.plugins.secrets) apply false
alias(libs.plugins.detekt) apply false
alias(libs.plugins.gms) apply false
alias(libs.plugins.androidTest) apply false
alias(libs.plugins.jetbrainsKotlinAndroid) apply false
alias(libs.plugins.baselineprofile) apply false
alias(libs.plugins.jetbrains.kotlin.android) apply false
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import java.io.InputStream
import java.io.OutputStream
import javax.inject.Inject


class UserPreferencesSerializer @Inject constructor() : Serializer<UserPreferences> {
override val defaultValue: UserPreferences = UserPreferences.getDefaultInstance()

Expand All @@ -24,4 +23,3 @@ class UserPreferencesSerializer @Inject constructor() : Serializer<UserPreferenc
t.writeTo(output)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import com.espressodev.gptmap.core.designsystem.TextType
import com.espressodev.gptmap.core.designsystem.component.GmAlertDialog
import com.espressodev.gptmap.core.designsystem.component.GmProgressIndicator
import com.espressodev.gptmap.core.designsystem.component.GmTopAppBar
import java.util.PriorityQueue
import com.espressodev.gptmap.core.designsystem.R.drawable as AppDrawable
import com.espressodev.gptmap.core.designsystem.R.string as AppText

Expand Down Expand Up @@ -65,6 +66,10 @@ fun DeleteProfileRoute(
)
}


val queue =
PriorityQueue<Map<Int, Int>> { a, b -> a.keys.first().compareTo(b.keys.first()) }

if (isDialogOpened) {
GmAlertDialog(
title = AppText.delete_confirm,
Expand Down
Loading

0 comments on commit 22e5967

Please sign in to comment.