Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/workflows/baseline-profile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Generate baseline profile

# Regenerates app/src/main/generated/baselineProfiles/baseline-prof.txt on a managed emulator
# and uploads it as an artifact. Download it and commit it to the repo.
on:
workflow_dispatch:
inputs:
server:
description: Jellyfin server URL to profile against (defaults to the public demo server)
required: false
type: string

defaults:
run:
shell: bash

env:
GRADLE_OPTS: "-Dorg.gradle.jvmargs='-Xmx12g -XX:MaxMetaspaceSize=1024m'"

jobs:
generate:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
fetch-depth: 0 # Need the tags to build
- name: Setup
uses: ./.github/actions/setup
- name: Enable KVM
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Generate baseline profile
env:
ORG_GRADLE_PROJECT_WholphinExtensionsUsername: "${{ secrets.EXTENSIONS_USERNAME }}"
ORG_GRADLE_PROJECT_WholphinExtensionsPassword: "${{ secrets.EXTENSIONS_PASSWORD }}"
SERVER: ${{ inputs.server }}
run: |
args=()
if [[ -n "$SERVER" ]]; then
args+=("-Pandroid.testInstrumentationRunnerArguments.wholphin.server=$SERVER")
fi
./gradlew :app:generateBaselineProfile "${args[@]}" \
-Pandroid.testoptions.manageddevices.emulator.gpu=swiftshader_indirect \
-Pandroid.experimental.androidTest.numManagedDeviceShards=1 \
--no-daemon
- name: Upload baseline profile
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: baseline-profile
path: |
app/src/main/generated/baselineProfiles/*
if-no-files-found: error
25 changes: 25 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,31 @@ You can also build the extensions locally from https://github.com/damontecres/wh

Finally, if no `wholphin-mpv` implementation is found, `wholphin-mpv-stub` will be used. This allows the app to compile, but any runtime usage of MPV will throw an exception.

## Baseline profile

Wholphin ships a [baseline profile](https://developer.android.com/topic/performance/baselineprofiles/overview) so the most used code paths are compiled ahead of time after install. It is generated by the `:baselineprofile` module and committed at `app/src/main/generated/baselineProfiles/baseline-prof.txt`. `androidx.profileinstaller` installs it on first run, including for sideloaded installs.

The generator (`BaselineProfileGenerator`) signs in to a Jellyfin server and walks through the home page, navigation drawer, a library, a details page, and playback using only D-pad keys. By default, it uses the public Jellyfin demo server.

To regenerate it, run:
```bash
./gradlew :app:generateBaselineProfile
```
This uses a Gradle managed Pixel 6/API 34 emulator, so it needs hardware virtualization. To use a connected device/emulator instead, set `useConnectedDevices = true` in `baselineprofile/build.gradle.kts` and remove the managed device.

To profile your own server, pass the credentials as instrumentation arguments (nothing is stored):
```bash
./gradlew :app:generateBaselineProfile -Pandroid.testInstrumentationRunnerArguments.wholphin.server=http://192.168.1.2:8096 -Pandroid.testInstrumentationRunnerArguments.wholphin.username=user -Pandroid.testInstrumentationRunnerArguments.wholphin.password=pass
```

To measure the effect of the profile, run the benchmarks in `WholphinBenchmarks`, which compare cold start and navigation frame timings with and without the profile:
```bash
./gradlew :baselineprofile:pixel6Api34BenchmarkReleaseAndroidTest -Pandroid.testInstrumentationRunnerArguments.androidx.benchmark.enabledRules=macrobenchmark -Pandroid.testInstrumentationRunnerArguments.androidx.benchmark.suppressErrors=EMULATOR,LOW-BATTERY,DEBUGGABLE
```
Emulator results are only indicative. For real numbers, run it on a physical TV device and remove `suppressErrors`.

The `Generate baseline profile` GitHub workflow can be run manually to regenerate the profile in CI. It uploads the result as an artifact to commit. Regenerate the profile before releases and after major UI changes.

## Code organization

Code is split into several packages:
Expand Down
16 changes: 16 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ plugins {
alias(libs.plugins.kotlin.plugin.serialization)
alias(libs.plugins.aboutLibraries)
alias(libs.plugins.openapi.generator)
alias(libs.plugins.androidx.baselineprofile)
}

val isCI = providers.environmentVariable("CI").orElse("false").map { it.toBoolean() }
Expand Down Expand Up @@ -227,6 +228,20 @@ androidComponents {
}
}

baselineProfile {
// Write the generated profile to app/src/main/generated/baselineProfiles so it can be committed
mergeIntoMain = true
saveInSrc = true
// The plugin does not filter startup profiles, which would add all of the AndroidX rules back
dexLayoutOptimization = false

// AndroidX libraries ship their own profiles that AGP merges in, and j$ is desugared code
filter {
exclude("androidx.**")
exclude("j$.**")
}
}

room {
schemaDirectory("$projectDir/schemas")
}
Expand Down Expand Up @@ -306,6 +321,7 @@ dependencies {
implementation(libs.androidx.work.runtime.ktx)
implementation(libs.androidx.hilt.work)
implementation(libs.androidx.profileinstaller)
baselineProfile(project(":baselineprofile"))

implementation(libs.androidx.media3.exoplayer)
implementation(libs.androidx.media3.session)
Expand Down
Loading