Merge pull request #177

Baseline profiles
This commit is contained in:
Nishant Mishra
2025-12-20 19:23:26 +05:30
committed by GitHub
20 changed files with 436 additions and 26 deletions

View File

@@ -25,6 +25,7 @@ plugins {
alias(libs.plugins.kotlin.compose) alias(libs.plugins.kotlin.compose)
alias(libs.plugins.kotlin.serialization) alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.ksp) alias(libs.plugins.ksp)
alias(libs.plugins.baselineprofile)
} }
tasks.withType(Test::class) { tasks.withType(Test::class) {
@@ -101,6 +102,14 @@ android {
includeInApk = false includeInApk = false
includeInBundle = false includeInBundle = false
} }
baselineProfile {
variants {
create("playRelease") {
automaticGenerationDuringBuild = true
}
}
}
} }
dependencies { dependencies {
@@ -124,6 +133,8 @@ dependencies {
implementation(libs.androidx.room.runtime) implementation(libs.androidx.room.runtime)
implementation(libs.androidx.room.ktx) implementation(libs.androidx.room.ktx)
implementation(libs.androidx.profileinstaller)
"baselineProfile"(project(":baselineprofile"))
ksp(libs.androidx.room.compiler) ksp(libs.androidx.room.compiler)
"playImplementation"(libs.revenuecat.purchases) "playImplementation"(libs.revenuecat.purchases)

View File

@@ -219,9 +219,12 @@ fun AppScreen(
Crossfade(selected) { Crossfade(selected) {
if (it) Icon( if (it) Icon(
painterResource(item.selectedIcon), painterResource(item.selectedIcon),
null stringResource(item.label)
)
else Icon(
painterResource(item.unselectedIcon),
stringResource(item.label)
) )
else Icon(painterResource(item.unselectedIcon), null)
} }
AnimatedVisibility( AnimatedVisibility(
visible = selected || wide, visible = selected || wide,

View File

@@ -173,12 +173,11 @@ private fun SettingsScreen(
setShowSheet = { showLocaleSheet = it } setShowSheet = { showLocaleSheet = it }
) )
if(settingsState.isShowingEraseDataDialog){ if (settingsState.isShowingEraseDataDialog) {
ResetDataDialog(resetData = { ResetDataDialog(
onAction(SettingsAction.EraseData) resetData = { onAction(SettingsAction.EraseData) },
}, onDismiss = { onDismiss = { onAction(SettingsAction.CancelEraseData) }
onAction(SettingsAction.CancelEraseData) )
})
} }
NavDisplay( NavDisplay(
@@ -310,11 +309,11 @@ private fun SettingsScreen(
Box( Box(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
contentAlignment = Alignment.Center contentAlignment = Alignment.Center
){ ) {
TextButton( TextButton(
onClick = { onAction(SettingsAction.AskEraseData) }, onClick = { onAction(SettingsAction.AskEraseData) },
) { ) {
Text(stringResource(R.string.reset_data)) Text(stringResource(R.string.reset_data))
} }
} }

View File

@@ -115,7 +115,7 @@ fun AboutScreen(
) { ) {
Icon( Icon(
painterResource(R.drawable.arrow_back), painterResource(R.drawable.arrow_back),
null stringResource(R.string.back)
) )
} }
}, },

View File

@@ -183,7 +183,7 @@ fun AlarmSettings(
) { ) {
Icon( Icon(
painterResource(R.drawable.arrow_back), painterResource(R.drawable.arrow_back),
null stringResource(R.string.back)
) )
} }
}, },

View File

@@ -92,7 +92,7 @@ fun AppearanceSettings(
) { ) {
Icon( Icon(
painterResource(R.drawable.arrow_back), painterResource(R.drawable.arrow_back),
null stringResource(R.string.back)
) )
} }
}, },

View File

@@ -206,7 +206,8 @@ fun TimerSettings(
) { ) {
Icon( Icon(
painterResource(R.drawable.arrow_back), painterResource(R.drawable.arrow_back),
null stringResource(R.string.back)
) )
} }
}, },

View File

@@ -146,7 +146,7 @@ fun SharedTransitionScope.LastMonthScreen(
) { ) {
Icon( Icon(
painterResource(R.drawable.arrow_back), painterResource(R.drawable.arrow_back),
null stringResource(R.string.back)
) )
} }
}, },

View File

@@ -145,7 +145,7 @@ fun SharedTransitionScope.LastWeekScreen(
) { ) {
Icon( Icon(
painterResource(R.drawable.arrow_back), painterResource(R.drawable.arrow_back),
null stringResource(R.string.back)
) )
} }
}, },

View File

@@ -153,7 +153,7 @@ fun SharedTransitionScope.LastYearScreen(
) { ) {
Icon( Icon(
painterResource(R.drawable.arrow_back), painterResource(R.drawable.arrow_back),
null stringResource(R.string.back)
) )
} }
}, },

View File

@@ -122,4 +122,5 @@
<string name="focus_history_calendar_desc">Focus history of the past month. Days of the previous month are marked with a different color. Tap on a date for more info.</string> <string name="focus_history_calendar_desc">Focus history of the past month. Days of the previous month are marked with a different color. Tap on a date for more info.</string>
<string name="reset_data">Reset stats</string> <string name="reset_data">Reset stats</string>
<string name="reset_data_dialog_text">Are you sure you want to reset all your stats?</string> <string name="reset_data_dialog_text">Are you sure you want to reset all your stats?</string>
<string name="back">Back</string>
</resources> </resources>

1
baselineprofile/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build

View File

@@ -0,0 +1,81 @@
/*
* Copyright (c) 2025 Nishant Mishra
*
* This file is part of Tomato - a minimalist pomodoro timer for Android.
*
* Tomato is free software: you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Tomato is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Tomato.
* If not, see <https://www.gnu.org/licenses/>.
*/
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins {
alias(libs.plugins.android.test)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.baselineprofile)
}
android {
namespace = "org.nsh07.baselineprofile"
compileSdk {
version = release(36)
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlin {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17) // Use the enum for target JVM version
}
}
defaultConfig {
minSdk = 28
targetSdk = 36
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
targetProjectPath = ":app"
flavorDimensions += listOf("version")
productFlavors {
create("foss") { dimension = "version" }
create("play") { 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 }
)
}
}

View File

@@ -0,0 +1,18 @@
<!--
~ Copyright (c) 2025 Nishant Mishra
~
~ This file is part of Tomato - a minimalist pomodoro timer for Android.
~
~ Tomato is free software: you can redistribute it and/or modify it under the terms of the GNU
~ General Public License as published by the Free Software Foundation, either version 3 of the
~ License, or (at your option) any later version.
~
~ Tomato is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
~ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
~ Public License for more details.
~
~ You should have received a copy of the GNU General Public License along with Tomato.
~ If not, see <https://www.gnu.org/licenses/>.
-->
<manifest />

View File

@@ -0,0 +1,148 @@
/*
* Copyright (c) 2025 Nishant Mishra
*
* This file is part of Tomato - a minimalist pomodoro timer for Android.
*
* Tomato is free software: you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Tomato is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Tomato.
* If not, see <https://www.gnu.org/licenses/>.
*/
package org.nsh07.baselineprofile
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 androidx.test.uiautomator.UiAutomatorTestScope
import androidx.test.uiautomator.textAsString
import androidx.test.uiautomator.uiAutomator
import androidx.test.uiautomator.watcher.PermissionDialog
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.util.Locale
@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.
val packageName = InstrumentationRegistry.getArguments().getString("targetAppId")
?: throw Exception("targetAppId not passed as instrumentation runner arg")
rule.collect(
packageName = packageName,
// See: https://d.android.com/topic/performance/baselineprofiles/dex-layout-optimizations
includeInStartupProfile = true
) {
pressHome()
startActivityAndWait()
uiAutomator {
onElement { contentDescription == "Play" }.click()
watchFor(PermissionDialog) {
clickAllow() // Allow notification permission
}
waitForAppToBeVisible(packageName)
onElement { contentDescription == "Restart" }.click()
onElement { contentDescription == "Stats" }.click()
waitForStableInActiveWindow()
scrollThroughContent()
onElement { textAsString() == "Last week" }.click()
waitForStableInActiveWindow()
scrollThroughContent()
onElement { contentDescription == "Back" }.click()
waitForStableInActiveWindow()
onElement { textAsString() == "Last month" }.click()
waitForStableInActiveWindow()
scrollThroughContent()
onElement { contentDescription == "Back" }.click()
waitForStableInActiveWindow()
fling(500, 1500, "UP")
waitForStableInActiveWindow()
onElement { textAsString() == "Last year" }.click()
waitForStableInActiveWindow()
scrollThroughContent()
onElement { contentDescription == "Back" }.click()
waitForStableInActiveWindow()
onElement { contentDescription == "Settings" }.click()
waitForStableInActiveWindow()
onElement { textAsString() == "Timer" }.click()
waitForStableInActiveWindow()
scrollThroughContent()
onElement { contentDescription == "Back" }.click()
waitForStableInActiveWindow()
onElement { textAsString() == "Appearance" }.click()
waitForStableInActiveWindow()
scrollThroughContent()
onElement { contentDescription == "Back" }.click()
waitForStableInActiveWindow()
onElement { textAsString() == "Alarm" }.click()
waitForStableInActiveWindow()
scrollThroughContent()
onElement { contentDescription == "Back" }.click()
waitForStableInActiveWindow()
onElement { textAsString() == "About" }.click()
waitForStableInActiveWindow()
scrollThroughContent()
onElement { contentDescription == "Back" }.click()
}
}
}
private fun UiAutomatorTestScope.fling(startX: Int, startY: Int, direction: String) {
val screenHeight = device.displayHeight
val screenWidth = device.displayWidth
val steps = 5 // Fast speed for fling
var endX = startX
var endY = startY
when (direction.uppercase(Locale.getDefault())) {
"UP" -> endY = startY - (screenHeight * 0.3).toInt()
"DOWN" -> endY = startY + (screenHeight * 0.3).toInt()
"LEFT" -> endX = startX - (screenWidth * 0.3).toInt()
"RIGHT" -> endX = startX + (screenWidth * 0.3).toInt()
}
device.swipe(startX, startY, endX, endY, steps)
}
private fun UiAutomatorTestScope.scrollThroughContent() {
fling(500, 1500, "UP")
waitForStableInActiveWindow()
fling(500, 1500, "DOWN")
waitForStableInActiveWindow()
}
}

View File

@@ -0,0 +1,92 @@
/*
* Copyright (c) 2025 Nishant Mishra
*
* This file is part of Tomato - a minimalist pomodoro timer for Android.
*
* Tomato is free software: you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Tomato is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Tomato.
* If not, see <https://www.gnu.org/licenses/>.
*/
package org.nsh07.baselineprofile
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 androidx.test.uiautomator.By
import androidx.test.uiautomator.Until
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 [CompilationMode.None], which represents the app with no Baseline
* Profiles optimizations, and [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()
@Test
fun startupCompilationNone() =
benchmark(CompilationMode.None())
@Test
fun startupCompilationBaselineProfiles() =
benchmark(CompilationMode.Partial(BaselineProfileMode.Require))
private fun benchmark(compilationMode: CompilationMode) {
// The application id for the running build variant is read from the instrumentation arguments.
rule.measureRepeated(
packageName = InstrumentationRegistry.getArguments().getString("targetAppId")
?: throw Exception("targetAppId not passed as instrumentation runner arg"),
metrics = listOf(StartupTimingMetric()),
compilationMode = compilationMode,
startupMode = StartupMode.COLD,
iterations = 10,
setupBlock = {
pressHome()
},
measureBlock = {
startActivityAndWait()
// This ensures the full UI rendering is included in the measurement.
device.wait(
Until.hasObject(By.text("25:00")),
5_000 // Wait for a maximum of 5 seconds for the content to appear
)
}
)
}
}

View File

@@ -1,3 +1,20 @@
/*
* Copyright (c) 2025 Nishant Mishra
*
* This file is part of Tomato - a minimalist pomodoro timer for Android.
*
* Tomato is free software: you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Tomato is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Tomato.
* If not, see <https://www.gnu.org/licenses/>.
*/
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins { plugins {
alias(libs.plugins.android.application) apply false alias(libs.plugins.android.application) apply false
@@ -5,4 +22,6 @@ plugins {
alias(libs.plugins.kotlin.compose) apply false alias(libs.plugins.kotlin.compose) apply false
alias(libs.plugins.kotlin.serialization) apply false alias(libs.plugins.kotlin.serialization) apply false
alias(libs.plugins.ksp) apply false alias(libs.plugins.ksp) apply false
alias(libs.plugins.android.test) apply false
alias(libs.plugins.baselineprofile) apply false
} }

View File

@@ -1,11 +1,19 @@
# Project-wide Gradle settings. #
# IDE (e.g. Android Studio) users: # Copyright (c) 2025 Nishant Mishra
# Gradle settings configured through the IDE *will override* #
# any settings specified in this file. # This file is part of Tomato - a minimalist pomodoro timer for Android.
# For more details on how to configure your build environment visit #
# http://www.gradle.org/docs/current/userguide/build_environment.html # Tomato is free software: you can redistribute it and/or modify it under the terms of the GNU
# Specifies the JVM arguments used for the daemon process. # General Public License as published by the Free Software Foundation, either version 3 of the
# The setting is particularly useful for tweaking memory settings. # License, or (at your option) any later version.
#
# Tomato is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along with Tomato.
# If not, see <https://www.gnu.org/licenses/>.
#
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode. # When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. For more details, visit # This option should only be used with decoupled projects. For more details, visit
@@ -20,4 +28,5 @@ kotlin.code.style=official
# Enables namespacing of each library's R class so that its R class includes only the # Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies, # resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library # thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true android.nonTransitiveRClass=true
org.gradle.configuration-cache=true

View File

@@ -15,6 +15,10 @@ navigation3 = "1.0.0"
revenuecat = "9.15.2" revenuecat = "9.15.2"
room = "2.8.4" room = "2.8.4"
vico = "2.3.6" vico = "2.3.6"
uiautomator = "2.4.0-alpha07"
benchmarkMacroJunit4 = "1.4.1"
baselineprofile = "1.4.1"
profileinstaller = "1.4.1"
[libraries] [libraries]
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" } androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
@@ -43,6 +47,9 @@ material-kolor = { module = "com.materialkolor:material-kolor", version.ref = "m
revenuecat-purchases = { module = "com.revenuecat.purchases:purchases", version.ref = "revenuecat" } revenuecat-purchases = { module = "com.revenuecat.purchases:purchases", version.ref = "revenuecat" }
revenuecat-purchases-ui = { module = "com.revenuecat.purchases:purchases-ui", version.ref = "revenuecat" } revenuecat-purchases-ui = { module = "com.revenuecat.purchases:purchases-ui", version.ref = "revenuecat" }
vico-compose-m3 = { group = "com.patrykandpatrick.vico", name = "compose-m3", version.ref = "vico" } vico-compose-m3 = { group = "com.patrykandpatrick.vico", name = "compose-m3", version.ref = "vico" }
androidx-uiautomator = { group = "androidx.test.uiautomator", name = "uiautomator", version.ref = "uiautomator" }
androidx-benchmark-macro-junit4 = { group = "androidx.benchmark", name = "benchmark-macro-junit4", version.ref = "benchmarkMacroJunit4" }
androidx-profileinstaller = { group = "androidx.profileinstaller", name = "profileinstaller", version.ref = "profileinstaller" }
[plugins] [plugins]
android-application = { id = "com.android.application", version.ref = "agp" } android-application = { id = "com.android.application", version.ref = "agp" }
@@ -50,3 +57,5 @@ kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
android-test = { id = "com.android.test", version.ref = "agp" }
baselineprofile = { id = "androidx.baselineprofile", version.ref = "baselineprofile" }

View File

@@ -1,3 +1,20 @@
/*
* Copyright (c) 2025 Nishant Mishra
*
* This file is part of Tomato - a minimalist pomodoro timer for Android.
*
* Tomato is free software: you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Tomato is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Tomato.
* If not, see <https://www.gnu.org/licenses/>.
*/
pluginManagement { pluginManagement {
repositories { repositories {
google { google {
@@ -21,3 +38,4 @@ dependencyResolutionManagement {
rootProject.name = "Tomato" rootProject.name = "Tomato"
include(":app") include(":app")
include(":baselineprofile")