build: baseline-prof for tv.

This commit is contained in:
oxy-macmini
2025-03-30 15:39:31 +08:00
parent 6cd182bf06
commit 8173ea7930
27 changed files with 208514 additions and 21 deletions

View File

@ -0,0 +1,52 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="BaselineProfile Smartphone" type="AndroidBaselineProfileRunConfigurationType" factoryName="Android Baseline Profile Configuration Factory">
<module name="M3U.app.smartphone" />
<option name="generateAllVariants" value="true" />
<option name="CLEAR_LOGCAT" value="false" />
<option name="SHOW_LOGCAT_AUTOMATICALLY" value="false" />
<option name="TARGET_SELECTION_MODE" value="DEVICE_AND_SNAPSHOT_COMBO_BOX" />
<option name="SELECTED_CLOUD_MATRIX_CONFIGURATION_ID" value="-1" />
<option name="SELECTED_CLOUD_MATRIX_PROJECT_ID" value="" />
<option name="DEBUGGER_TYPE" value="Auto" />
<Auto>
<option name="USE_JAVA_AWARE_DEBUGGER" value="false" />
<option name="SHOW_STATIC_VARS" value="true" />
<option name="WORKING_DIR" value="" />
<option name="TARGET_LOGGING_CHANNELS" value="lldb process:gdb-remote packets" />
<option name="SHOW_OPTIMIZED_WARNING" value="true" />
<option name="ATTACH_ON_WAIT_FOR_DEBUGGER" value="false" />
<option name="DEBUG_SANDBOX_SDK" value="false" />
</Auto>
<Hybrid>
<option name="USE_JAVA_AWARE_DEBUGGER" value="false" />
<option name="SHOW_STATIC_VARS" value="true" />
<option name="WORKING_DIR" value="" />
<option name="TARGET_LOGGING_CHANNELS" value="lldb process:gdb-remote packets" />
<option name="SHOW_OPTIMIZED_WARNING" value="true" />
<option name="ATTACH_ON_WAIT_FOR_DEBUGGER" value="false" />
<option name="DEBUG_SANDBOX_SDK" value="false" />
</Hybrid>
<Java>
<option name="ATTACH_ON_WAIT_FOR_DEBUGGER" value="false" />
<option name="DEBUG_SANDBOX_SDK" value="false" />
</Java>
<Native>
<option name="USE_JAVA_AWARE_DEBUGGER" value="false" />
<option name="SHOW_STATIC_VARS" value="true" />
<option name="WORKING_DIR" value="" />
<option name="TARGET_LOGGING_CHANNELS" value="lldb process:gdb-remote packets" />
<option name="SHOW_OPTIMIZED_WARNING" value="true" />
<option name="ATTACH_ON_WAIT_FOR_DEBUGGER" value="false" />
<option name="DEBUG_SANDBOX_SDK" value="false" />
</Native>
<Profilers>
<option name="ADVANCED_PROFILING_ENABLED" value="false" />
<option name="STARTUP_PROFILING_ENABLED" value="false" />
<option name="STARTUP_CPU_PROFILING_ENABLED" value="false" />
<option name="STARTUP_CPU_PROFILING_CONFIGURATION_NAME" value="Java/Kotlin Method Sample (legacy)" />
<option name="STARTUP_NATIVE_MEMORY_PROFILING_ENABLED" value="false" />
<option name="NATIVE_MEMORY_SAMPLE_RATE_BYTES" value="2048" />
</Profilers>
<method v="2" />
</configuration>
</component>

View File

@ -0,0 +1,52 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="BaselineProfile TV" type="AndroidBaselineProfileRunConfigurationType" factoryName="Android Baseline Profile Configuration Factory">
<module name="M3U.app.tv" />
<option name="generateAllVariants" value="true" />
<option name="CLEAR_LOGCAT" value="false" />
<option name="SHOW_LOGCAT_AUTOMATICALLY" value="false" />
<option name="TARGET_SELECTION_MODE" value="DEVICE_AND_SNAPSHOT_COMBO_BOX" />
<option name="SELECTED_CLOUD_MATRIX_CONFIGURATION_ID" value="-1" />
<option name="SELECTED_CLOUD_MATRIX_PROJECT_ID" value="" />
<option name="DEBUGGER_TYPE" value="Auto" />
<Auto>
<option name="USE_JAVA_AWARE_DEBUGGER" value="false" />
<option name="SHOW_STATIC_VARS" value="true" />
<option name="WORKING_DIR" value="" />
<option name="TARGET_LOGGING_CHANNELS" value="lldb process:gdb-remote packets" />
<option name="SHOW_OPTIMIZED_WARNING" value="true" />
<option name="ATTACH_ON_WAIT_FOR_DEBUGGER" value="false" />
<option name="DEBUG_SANDBOX_SDK" value="false" />
</Auto>
<Hybrid>
<option name="USE_JAVA_AWARE_DEBUGGER" value="false" />
<option name="SHOW_STATIC_VARS" value="true" />
<option name="WORKING_DIR" value="" />
<option name="TARGET_LOGGING_CHANNELS" value="lldb process:gdb-remote packets" />
<option name="SHOW_OPTIMIZED_WARNING" value="true" />
<option name="ATTACH_ON_WAIT_FOR_DEBUGGER" value="false" />
<option name="DEBUG_SANDBOX_SDK" value="false" />
</Hybrid>
<Java>
<option name="ATTACH_ON_WAIT_FOR_DEBUGGER" value="false" />
<option name="DEBUG_SANDBOX_SDK" value="false" />
</Java>
<Native>
<option name="USE_JAVA_AWARE_DEBUGGER" value="false" />
<option name="SHOW_STATIC_VARS" value="true" />
<option name="WORKING_DIR" value="" />
<option name="TARGET_LOGGING_CHANNELS" value="lldb process:gdb-remote packets" />
<option name="SHOW_OPTIMIZED_WARNING" value="true" />
<option name="ATTACH_ON_WAIT_FOR_DEBUGGER" value="false" />
<option name="DEBUG_SANDBOX_SDK" value="false" />
</Native>
<Profilers>
<option name="ADVANCED_PROFILING_ENABLED" value="false" />
<option name="STARTUP_PROFILING_ENABLED" value="false" />
<option name="STARTUP_CPU_PROFILING_ENABLED" value="false" />
<option name="STARTUP_CPU_PROFILING_CONFIGURATION_NAME" value="Java/Kotlin Method Sample (legacy)" />
<option name="STARTUP_NATIVE_MEMORY_PROFILING_ENABLED" value="false" />
<option name="NATIVE_MEMORY_SAMPLE_RATE_BYTES" value="2048" />
</Profilers>
<method v="2" />
</configuration>
</component>

View File

@ -133,7 +133,7 @@ dependencies {
implementation(project(":business:playlist-configuration"))
// baselineprofile
implementation(libs.androidx.profileinstaller)
"baselineProfile"(project(":baselineprofile"))
"baselineProfile"(project(":baselineprofile:smartphone"))
// base
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)

View File

@ -79,7 +79,7 @@ dependencies {
implementation(project(":business:playlist-configuration"))
// baselineprofile
implementation(libs.androidx.profileinstaller)
// "baselineProfile"(project(":baselineprofile"))
"baselineProfile"(project(":baselineprofile:tv"))
// base
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,7 @@ plugins {
}
android {
namespace = "com.m3u.baselineprofile"
namespace = "com.m3u.baselineprofile.smartphone"
compileSdk = 35
compileOptions {
@ -36,21 +36,15 @@ android {
create("liteCodec") { dimension = "codec" }
}
testOptions {
managedDevices {
allDevices {
create("Pixel5Api31", ManagedVirtualDevice::class) {
device = "Pixel 5"
apiLevel = 31
systemImageSource = "aosp"
}
}
testOptions.managedDevices.devices {
create<ManagedVirtualDevice>("Pixel5Api31") {
device = "Pixel 5"
apiLevel = 34
systemImageSource = "aosp"
}
}
// Note that your module name may have different name
targetProjectPath = ":app:smartphone"
// Enable the benchmark to run separately from the app process
experimentalProperties["android.experimental.self-instrumenting"] = true
}
// This is the configuration block for the Baseline Profile plugin.

1
baselineprofile/tv/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/build

View File

@ -0,0 +1,64 @@
@file:Suppress("UnstableApiUsage")
import com.android.build.api.dsl.ManagedVirtualDevice
plugins {
alias(libs.plugins.org.jetbrains.kotlin.android)
alias(libs.plugins.androidx.baselineprofile)
alias(libs.plugins.com.android.test)
}
android {
namespace = "com.m3u.baselineprofile.tv"
compileSdk = 35
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
}
defaultConfig {
minSdk = 28
targetSdk = 34
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
testOptions.managedDevices.devices {
create<ManagedVirtualDevice>("tvApi34") {
device = "Television (1080p)"
apiLevel = 34
systemImageSource = "aosp"
}
}
// Note that your module name may have different name
targetProjectPath = ":app:tv"
}
// 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 {
managedDevices += "Pixel5Api31"
useConnectedDevices = false
enableEmulatorDisplay = true
}
androidComponents {
onVariants { v ->
v.instrumentationRunnerArguments.put(
"targetAppId",
"com.m3u.tv"
)
}
}
dependencies {
implementation(libs.androidx.test.ext.junit)
implementation(libs.androidx.test.espresso.espresso.core)
implementation(libs.androidx.test.uiautomator.uiautomator)
implementation(libs.androidx.benchmark.benchmark.macro.junit4)
}

View File

@ -0,0 +1 @@
<manifest />

View File

@ -0,0 +1,30 @@
package com.m3u.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 org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
@LargeTest
class BaselineProfileGenerator {
@get:Rule
val rule = BaselineProfileRule()
@Test
fun generate() {
rule.collect(
packageName = InstrumentationRegistry.getArguments().getString("targetAppId")
?: throw Exception("targetAppId not passed as instrumentation runner arg"),
includeInStartupProfile = true
) {
pressHome()
startActivityAndWait()
}
}
}

View File

@ -0,0 +1,48 @@
package com.m3u.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 org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@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) {
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()
}
)
}
}

View File

@ -30,15 +30,23 @@ dependencies {
implementation(project(":lint:annotation"))
ksp(project(":lint:processor"))
val richCodec = gradle
implementation(project(":data:codec"))
val isTvBuild = gradle
.startParameter
.taskNames
.find { it.contains("richCodec", ignoreCase = true) } != null
implementation(project(":data:codec"))
if (richCodec) {
.any { ":app:tv" in it }
if (isTvBuild) {
implementation(project(":data:codec:rich"))
} else {
implementation(project(":data:codec:lite"))
val richCodec = gradle
.startParameter
.taskNames
.find { it.contains("richCodec", ignoreCase = true) } != null
if (richCodec) {
implementation(project(":data:codec:rich"))
} else {
implementation(project(":data:codec:lite"))
}
}
implementation(libs.androidx.core.ktx)

View File

@ -76,7 +76,6 @@ import com.m3u.data.repository.channel.ChannelRepository
import com.m3u.data.repository.playlist.PlaylistRepository
import com.m3u.data.service.MediaCommand
import com.m3u.data.service.PlayerManager
import com.m3u.data.service.currentTracks
import dagger.hilt.android.qualifiers.ApplicationContext
import io.ktor.http.Url
import kotlinx.coroutines.CoroutineDispatcher

View File

@ -27,7 +27,7 @@ include(
":business:playlist-configuration",
":business:channel"
)
include(":baselineprofile")
include(":baselineprofile:smartphone", ":baselineprofile:tv")
include(":i18n")
include(
":lint:annotation",