Bug 1943145 Comment 3 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

Ok I think it's all figured out now. Rather than running `cmd package compile -m speed-profile`, we should run `profgen extractProfile` on the host, and then run `adb install-multiple` instead of `adb install`.

Backstory:

1. The Baseline profile inside the apk at `assets/dexopt/baseline.prof` is ignored when installing an apk.
2. There are two ways to tell Android to use a Baseline profile: Either by using `install-multiple` with the Baseline profile in a `.dm` file ("Dex Metadata") [1], or by broadcasting `androidx.profileinstaller.action.INSTALL_PROFILE` [2] which is handled by the `profileinstaller` library that we include in fenix. The Play Store does the former [3], the Macrobenchmark framework does the latter [4].
3. Baseline profile versions: The profile at `assets/dexopt/baseline.prof` must always have version v0_1_0_p. The profile in the `.dm` file provided to `adb install-multiple` must be of the version that the targeted Android understands. Starting with Android 12, that's v0_1_5_s [5].
4. Transcoding from v0_1_0_p to v0_1_5_s happens in these places:
    1. When submitting an APK to the Play Store, Google's servers transcode the profile found in the APK into all versions that might be needed. The Play Store fetches the .dm file of the right version when it installs the app. [6]
    2. When using Macrobenchmark / profileinstaller, the ProfileTranscoder class inside profileinstaller [7] probably does the transcoding.
    3. If you want to run `install-multiple` yourself, you can transcode the profile on the host by running `profgen extractProfile` (from the Android SDK). You specify the destination format in the command line invocation. [8]

---

All of this information comes from this page in the documentation: https://developer.android.com/topic/performance/baselineprofiles/manually-create-measure

[1] `adb install-multiple` is mentioned in multiple sections of the document.
[2] mentioned under "Broadcast with androidx.profileinstaller"
[3] mentioned under "Use install-multiple with DexMetadata".
[4] see [androidx/benchmark/macro/ProfileInstallBroadcast.kt](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:benchmark/benchmark-macro/src/main/java/androidx/benchmark/macro/ProfileInstallBroadcast.kt;l=41-43;drc=034c3a030f7c593927f81efb9fe127c74e287c4d)
[5] see section "Profile formats and platform versions"
[6] mentioned under "Use install-multiple with DexMetadata": "Play generates a tuple by transcoding profiles packaged as v0_1_0_p to every known profile version in use to deliver the correct version."
[7] see [androidx/profileinstaller/ProfileTranscoder.java](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:profileinstaller/profileinstaller/src/main/java/androidx/profileinstaller/ProfileTranscoder.java;drc=cf74225ed1cd251639c2db1536e674d3bac64331)
[8] described under "Use install-multiple with profgen or DexMetaData"
Ok I think it's all figured out now. Rather than running `cmd package compile -m speed-profile`, we should run `profgen extractProfile` on the host, and then run `adb install-multiple` instead of `adb install`.

Backstory:

1. The Baseline profile inside the apk at `assets/dexopt/baseline.prof` is ignored when installing an apk.
2. There are two ways to tell Android to use a Baseline profile: Either by using `install-multiple` with the Baseline profile in a `.dm` file ("Dex Metadata") [1], or by broadcasting `androidx.profileinstaller.action.INSTALL_PROFILE` [2] which is handled by the `profileinstaller` library that we include in fenix. The Play Store does the former [3], the Macrobenchmark framework does the latter [4].
3. Baseline profile versions: The profile at `assets/dexopt/baseline.prof` must always have version v0_1_0_p. The profile in the `.dm` file provided to `adb install-multiple` must be of the version that the targeted Android understands. Starting with Android 12, that's v0_1_5_s [5].
4. `.dm` files are just zip files with two files in them: `primary.prof` and `primary.profm`.
5. Transcoding from v0_1_0_p to v0_1_5_s happens in these places:
    1. When submitting an APK to the Play Store, Google's servers transcode the profile found in the APK into all versions that might be needed. The Play Store fetches the .dm file of the right version when it installs the app. [6]
    2. When using Macrobenchmark / profileinstaller, the ProfileTranscoder class inside profileinstaller [7] probably does the transcoding.
    3. If you want to run `install-multiple` yourself, you can transcode the profile on the host by running `profgen extractProfile` (from the Android SDK). You specify the destination format in the command line invocation. [8]
6. When running `adb install-multiple myfenix.apk myfenix.dm`, the filenames before the `.apk` and the `.dm` must match exactly.

---

All of this information comes from this page in the documentation: https://developer.android.com/topic/performance/baselineprofiles/manually-create-measure

[1] `adb install-multiple` is mentioned in multiple sections of the document.
[2] mentioned under "Broadcast with androidx.profileinstaller"
[3] mentioned under "Use install-multiple with DexMetadata".
[4] see [androidx/benchmark/macro/ProfileInstallBroadcast.kt](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:benchmark/benchmark-macro/src/main/java/androidx/benchmark/macro/ProfileInstallBroadcast.kt;l=41-43;drc=034c3a030f7c593927f81efb9fe127c74e287c4d)
[5] see section "Profile formats and platform versions"
[6] mentioned under "Use install-multiple with DexMetadata": "Play generates a tuple by transcoding profiles packaged as v0_1_0_p to every known profile version in use to deliver the correct version."
[7] see [androidx/profileinstaller/ProfileTranscoder.java](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:profileinstaller/profileinstaller/src/main/java/androidx/profileinstaller/ProfileTranscoder.java;drc=cf74225ed1cd251639c2db1536e674d3bac64331)
[8] described under "Use install-multiple with profgen or DexMetaData"
Ok I think it's all figured out now. Rather than running `cmd package compile -m speed-profile`, we should run `profgen extractProfile` on the host, and then run `adb install-multiple` instead of `adb install`.

Backstory:

1. The Baseline profile inside the apk at `assets/dexopt/baseline.prof` is ignored when installing an apk.
2. There are two ways to tell Android to use a Baseline profile: Either by using `install-multiple` with the Baseline profile in a `.dm` file ("Dex Metadata") [1], or by broadcasting `androidx.profileinstaller.action.INSTALL_PROFILE` [2] which is handled by the `profileinstaller` library that we include in fenix. The Play Store does the former [3], the Macrobenchmark framework does the latter [4].
3. Baseline profile versions: The profile at `assets/dexopt/baseline.prof` must always have version v0_1_0_p. The profile in the `.dm` file provided to `adb install-multiple` must be of the version that the targeted Android understands. Starting with Android 12, that's v0_1_5_s [5].
4. `.dm` files are just zip files with two files in them: `primary.prof` and `primary.profm`.
5. Transcoding from v0_1_0_p to v0_1_5_s happens in these places:
    1. When submitting an APK to the Play Store, Google's servers transcode the profile found in the APK into all versions that might be needed. The Play Store fetches the .dm file of the right version when it installs the app. [6]
    2. When using Macrobenchmark / profileinstaller, the ProfileTranscoder class inside profileinstaller [7] probably does the transcoding.
    3. If you want to run `install-multiple` yourself, you can transcode the profile on the host by running `profgen extractProfile` (from the Android SDK). You specify the destination format in the command line invocation. [8]
6. `profgen` is in the Android SDK. `profgen extractProfile` takes an apk as the input and creates a dm file as the output.
7. When running `adb install-multiple myfenix.apk myfenix.dm`, the filenames before the `.apk` and the `.dm` must match exactly.

---

All of this information comes from this page in the documentation: https://developer.android.com/topic/performance/baselineprofiles/manually-create-measure

[1] `adb install-multiple` is mentioned in multiple sections of the document.
[2] mentioned under "Broadcast with androidx.profileinstaller"
[3] mentioned under "Use install-multiple with DexMetadata".
[4] see [androidx/benchmark/macro/ProfileInstallBroadcast.kt](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:benchmark/benchmark-macro/src/main/java/androidx/benchmark/macro/ProfileInstallBroadcast.kt;l=41-43;drc=034c3a030f7c593927f81efb9fe127c74e287c4d)
[5] see section "Profile formats and platform versions"
[6] mentioned under "Use install-multiple with DexMetadata": "Play generates a tuple by transcoding profiles packaged as v0_1_0_p to every known profile version in use to deliver the correct version."
[7] see [androidx/profileinstaller/ProfileTranscoder.java](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:profileinstaller/profileinstaller/src/main/java/androidx/profileinstaller/ProfileTranscoder.java;drc=cf74225ed1cd251639c2db1536e674d3bac64331)
[8] described under "Use install-multiple with profgen or DexMetaData"

Back to Bug 1943145 Comment 3