Skip to content

Commit

Permalink
Separate startup profile from baseline profile
Browse files Browse the repository at this point in the history
  • Loading branch information
w2sv committed Jan 5, 2025
1 parent dcef2e7 commit 9f97886
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 4,335 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ format:

baseline-profile:
@echo "Generate baseline profile"
@./gradlew :app:generateReleaseBaselineProfile
@./gradlew :app:generateReleaseBaselineProfile --console verbose

build-aab:
@echo "Build AAB"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
Expand All @@ -31,7 +30,6 @@ import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.annotation.RootGraph
import com.w2sv.composed.CollectFromFlow
import com.w2sv.composed.isLandscapeModeActive
import com.w2sv.wifiwidget.R
import com.w2sv.wifiwidget.ui.designsystem.AppSnackbarHost
import com.w2sv.wifiwidget.ui.designsystem.AppTopBar
import com.w2sv.wifiwidget.ui.designsystem.drawer.NavigationDrawer
Expand Down
52 changes: 34 additions & 18 deletions app/src/release/generated/baselineProfiles/baseline-prof.txt

Large diffs are not rendered by default.

4,305 changes: 6 additions & 4,299 deletions app/src/release/generated/baselineProfiles/startup-prof.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.w2sv.baselineprofile
package com.w2sv.wifiwidget

import androidx.benchmark.macro.BaselineProfileMode
import androidx.benchmark.macro.CompilationMode
Expand Down
42 changes: 42 additions & 0 deletions benchmarking/src/main/kotlin/com/w2sv/wifiwidget/UiDeviceExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.w2sv.wifiwidget

import androidx.test.uiautomator.By
import androidx.test.uiautomator.Direction
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiSelector
import java.io.ByteArrayOutputStream

internal fun UiDevice.criticalUserJourney() {
closeLocationAccessPermissionRationalAndRequestDialogIfOpen()
flingListDown("scrollableWifiPropertyList")

goToWidgetConfigurationScreen()
waitForIdle()

flingListDown("scrollableWidgetConfigurationColumn")

pressBack()
}

private fun UiDevice.closeLocationAccessPermissionRationalAndRequestDialogIfOpen() {
findObject(By.text("Understood"))?.let { // 'Understood' button is part of the location access rational dialog
it.click() // Closes the rational dialog
waitForIdle() // Wait until location access permission request dialog appears
pressBack() // Closes location access permission request dialog
}
}

private fun UiDevice.dumpWindowHierarchy(): String {
val outputStream = ByteArrayOutputStream()
dumpWindowHierarchy(outputStream)
return outputStream.toString("UTF-8")
}

private fun UiDevice.flingListDown(resourceName: String) {
findObject(By.res(resourceName)).fling(Direction.DOWN)
waitForIdle()
}

private fun UiDevice.goToWidgetConfigurationScreen() {
findObject(UiSelector().description("Open the widget configuration screen.")).click()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.w2sv.wifiwidget.baselineprofile

import androidx.benchmark.macro.junit4.BaselineProfileRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import com.w2sv.wifiwidget.criticalUserJourney
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@LargeTest
class CriticalUserJourneyBaselineProfile {

@get:Rule
val rule = BaselineProfileRule()

@Test
fun generate() {
rule.collect(packageName = "com.w2sv.wifiwidget") {
startActivityAndWait()
device.criticalUserJourney()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.w2sv.baselineprofile
package com.w2sv.wifiwidget.baselineprofile

import android.content.Context
import androidx.benchmark.macro.MacrobenchmarkScope
import androidx.benchmark.macro.junit4.BaselineProfileRule
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import com.w2sv.wifiwidget.StartupBenchmarks
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand Down Expand Up @@ -34,7 +34,7 @@ import org.junit.runner.RunWith
**/
@RunWith(AndroidJUnit4::class)
@LargeTest
class BaselineProfileGenerator {
class StartupBaselineProfile {

@get:Rule
val rule = BaselineProfileRule()
Expand All @@ -44,12 +44,8 @@ class BaselineProfileGenerator {
rule.collect(
packageName = "com.w2sv.wifiwidget",
// See: https://d.android.com/topic/performance/baselineprofiles/dex-layout-optimizations
includeInStartupProfile = true
) {
pressHome()
startActivityAndWait()

device.criticalUserJourney()
}
includeInStartupProfile = true,
profileBlock = MacrobenchmarkScope::startActivityAndWait
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ internal object WidgetModule {

@WidgetPinSuccessFlow
@Provides
fun widgetPinSuccessFlow(
@MutableWidgetPinSuccessFlow mutableWidgetPinSuccessFlow: MutableSharedFlow<Unit>
): SharedFlow<Unit> =
fun widgetPinSuccessFlow(@MutableWidgetPinSuccessFlow mutableWidgetPinSuccessFlow: MutableSharedFlow<Unit>): SharedFlow<Unit> =
mutableWidgetPinSuccessFlow.asSharedFlow()
}

0 comments on commit 9f97886

Please sign in to comment.