Skip to content

Commit

Permalink
fully automated gmd baseline profile generation
Browse files Browse the repository at this point in the history
  • Loading branch information
nift4 committed Sep 10, 2024
1 parent ec77944 commit dbc813a
Show file tree
Hide file tree
Showing 16 changed files with 67,761 additions and 5,852 deletions.
50 changes: 45 additions & 5 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ android {
"RELEASE_TYPE",
"\"$releaseType\""
)
buildConfigField(
"boolean",
"DISABLE_MEDIA_STORE_FILTER",
"false"
)
setProperty("archivesBaseName", "Gramophone-$versionName${versionNameSuffix ?: ""}")
vectorDrawables {
useSupportLibrary = true
Expand All @@ -125,15 +130,50 @@ android {
"proguard-rules.pro",
)
}
create("benchmarkRelease") {
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro",
)
buildConfigField(
"boolean",
"DISABLE_MEDIA_STORE_FILTER",
"true"
)
matchingFallbacks += "release"
}
create("nonMinifiedRelease") {
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro",
)
buildConfigField(
"boolean",
"DISABLE_MEDIA_STORE_FILTER",
"true"
)
matchingFallbacks += "release"
}
create("profiling") {
isMinifyEnabled = false
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro",
)
isProfileable = true
matchingFallbacks += "release"
}
create("userdebug") {
isMinifyEnabled = false
isProfileable = true
isJniDebuggable = true
isPseudoLocalesEnabled = true
matchingFallbacks += "release"
}
debug {
isPseudoLocalesEnabled = true
Expand Down Expand Up @@ -191,16 +231,16 @@ aboutLibraries {
dependencies {
implementation(project(":libphonograph:libPhonograph"))
val media3Version = "1.4.1"
implementation("androidx.activity:activity-ktx:1.9.1")
implementation("androidx.activity:activity-ktx:1.9.2")
implementation("androidx.appcompat:appcompat:1.7.0")
implementation("androidx.collection:collection-ktx:1.4.3")
implementation("androidx.concurrent:concurrent-futures-ktx:1.2.0")
implementation("androidx.constraintlayout:constraintlayout:2.2.0-alpha14")
implementation("androidx.constraintlayout:constraintlayout:2.2.0-beta01")
implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.core:core-splashscreen:1.0.1")
//implementation("androidx.datastore:datastore-preferences:1.1.0-rc01") TODO don't abuse shared prefs
implementation("androidx.fragment:fragment-ktx:1.8.2")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.4")
implementation("androidx.fragment:fragment-ktx:1.8.3")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.5")
implementation("androidx.media3:media3-exoplayer:$media3Version")
implementation("androidx.media3:media3-exoplayer-midi:$media3Version")
implementation("androidx.media3:media3-session:$media3Version")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.parcelize.Parcelize
import org.akanework.gramophone.BuildConfig
import org.akanework.gramophone.R
import org.akanework.gramophone.ui.LibraryViewModel
import uk.akane.libphonograph.reader.Reader
Expand Down Expand Up @@ -56,7 +57,7 @@ object MediaStoreUtils {
@OptIn(UnstableApi::class)
private fun getAllSongs(context: Context): ReaderResult<MediaItem> {
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
val limitValue = prefs.getInt(
val limitValue = if (BuildConfig.DISABLE_MEDIA_STORE_FILTER) 0 else prefs.getInt(
"mediastore_filter",
context.resources.getInteger(R.integer.filter_default_sec)
)
Expand Down
15,511 changes: 15,511 additions & 0 deletions app/src/profiling/generated/baselineProfiles/baseline-prof.txt

Large diffs are not rendered by default.

15,511 changes: 15,511 additions & 0 deletions app/src/profiling/generated/baselineProfiles/startup-prof.txt

Large diffs are not rendered by default.

5,729 changes: 2,811 additions & 2,918 deletions app/src/release/generated/baselineProfiles/baseline-prof.txt

Large diffs are not rendered by default.

5,729 changes: 2,811 additions & 2,918 deletions app/src/release/generated/baselineProfiles/startup-prof.txt

Large diffs are not rendered by default.

15,511 changes: 15,511 additions & 0 deletions app/src/userdebug/generated/baselineProfiles/baseline-prof.txt

Large diffs are not rendered by default.

15,511 changes: 15,511 additions & 0 deletions app/src/userdebug/generated/baselineProfiles/startup-prof.txt

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions baselineprofile/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {

android {
namespace = "org.nift4.baselineprofile"
compileSdk = 34
compileSdk = 35

java {
toolchain {
Expand All @@ -24,7 +24,7 @@ android {

defaultConfig {
minSdk = 28
targetSdk = 34
targetSdk = 35

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -38,7 +38,7 @@ android {
create<ManagedVirtualDevice>("pixel6Api34") {
device = "Pixel 6"
apiLevel = 34
systemImageSource = "google"
systemImageSource = "aosp"
}
}
}
Expand All @@ -54,7 +54,7 @@ dependencies {
implementation("androidx.test.ext:junit:1.2.1")
implementation("androidx.test.espresso:espresso-core:3.6.1")
implementation("androidx.test.uiautomator:uiautomator:2.3.0")
implementation("androidx.benchmark:benchmark-macro-junit4:1.2.4")
implementation("androidx.benchmark:benchmark-macro-junit4:1.3.0")
}

androidComponents {
Expand Down
Binary file added baselineprofile/src/main/assets/test1.mp3
Binary file not shown.
Binary file added baselineprofile/src/main/assets/test2.flac
Binary file not shown.
Binary file added baselineprofile/src/main/assets/test3.wav
Binary file not shown.
Binary file added baselineprofile/src/main/assets/test4.ogg
Binary file not shown.
Binary file added baselineprofile/src/main/assets/test5.opus
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.nift4.baselineprofile

import android.annotation.SuppressLint
import android.media.MediaScannerConnection
import android.net.Uri
import android.os.Environment
import androidx.benchmark.macro.junit4.BaselineProfileRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
Expand All @@ -10,6 +13,9 @@ import androidx.test.uiautomator.Until
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.io.File
import java.io.FileNotFoundException
import java.io.FileOutputStream

/**
* This test class generates a basic startup baseline profile for the target package.
Expand Down Expand Up @@ -44,6 +50,31 @@ class BaselineProfileGenerator {
@SuppressLint("SdCardPath")
@Test
fun generate() {
val ctx = InstrumentationRegistry.getInstrumentation().context
val musicDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC)
val testDir = File(musicDir, "gp_baseline")
val files = listOf("test1.mp3", "test2.flac", "test3.wav", "test4.ogg", "test5.opus")
if (testDir.exists())
testDir.deleteRecursively()
testDir.mkdir()
for (i in files) {
ctx.assets.open(i).use {
try {
FileOutputStream(File(testDir, i)).use { o ->
it.copyTo(o)
}
} catch (e: FileNotFoundException) {
// scoped storage, files are there, ignore it
}
}
}
MediaScannerConnection.scanFile(
ctx,
files.map { File(testDir, it).absolutePath }.toTypedArray(),
null) { _: String, _: Uri -> }
val ae = InstrumentationRegistry.getInstrumentation().uiAutomation
ae.executeShellCommand("pm clear org.akanework.gramophone")
Thread.sleep(1000) // let device settle a bit
// The application id for the running build variant is read from the instrumentation arguments.
rule.collect(
packageName = InstrumentationRegistry.getArguments().getString("targetAppId")
Expand All @@ -57,21 +88,28 @@ class BaselineProfileGenerator {

// Start default activity for your app
pressHome()
device.executeShellCommand("pm clear org.akanework.gramophone")
device.executeShellCommand("pm grant org.akanework.gramophone android.permission.READ_MEDIA_AUDIO")
ae.executeShellCommand("pm grant org.akanework.gramophone android.permission.READ_MEDIA_AUDIO")
startActivityAndWait()

// More interactions to optimize advanced journeys of your app.
// 1. Wait until the content is asynchronously loaded
device.wait(Until.findObject(By.text("8 Songs")), 30L)
device.wait(Until.findObject(By.text("5 Songs")), 30L)
// 2. Scroll the tabs
device.swipe(800, 1000, 200, 1000, 20)
device.waitForIdle(20L)
device.swipe(200, 1000, 800, 1000, 20)
device.waitForIdle(20L)
// 3. Play a song
device.findObject(By.text("Summit (feat. Ellie Goulding)")).click()
Thread.sleep(5000)
device.findObject(By.text("Ending / Credits")).click()
Thread.sleep(2000)
device.findObject(By.text("test3")).click()
Thread.sleep(2000)
device.findObject(By.text("Level 1")).click()
Thread.sleep(2000)
device.findObject(By.text("Level 2")).click()
Thread.sleep(2000)
device.findObject(By.text("Level 3")).click()
Thread.sleep(2000)


// Check UiAutomator documentation for more information how to interact with the app.
Expand Down

0 comments on commit dbc813a

Please sign in to comment.