When dumping the `cur` profile use the right kernel `uid` that was assigned to the application.
* This is especially useful in the context of Android Auto, Wear like environments where there is more than one user all the time.
Test: Existing unit tests pass. Also tested manual generation.
Change-Id: I6a1e211df3941e5e236ffb0d390d44d7e985c056
diff --git a/benchmark/benchmark-common/src/main/java/androidx/benchmark/UserInfo.kt b/benchmark/benchmark-common/src/main/java/androidx/benchmark/UserInfo.kt
index ec4a1a8..2b2f7fb 100644
--- a/benchmark/benchmark-common/src/main/java/androidx/benchmark/UserInfo.kt
+++ b/benchmark/benchmark-common/src/main/java/androidx/benchmark/UserInfo.kt
@@ -18,9 +18,10 @@
import android.os.Parcel
import android.os.Process
+import androidx.annotation.RestrictTo
-internal object UserInfo {
-
+@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
+object UserInfo {
val currentUserId: Int
get() {
Overrides.currentUserId?.let {
diff --git a/benchmark/benchmark-macro/src/main/java/androidx/benchmark/macro/BaselineProfiles.kt b/benchmark/benchmark-macro/src/main/java/androidx/benchmark/macro/BaselineProfiles.kt
index dfdc145..c2b30c0 100644
--- a/benchmark/benchmark-macro/src/main/java/androidx/benchmark/macro/BaselineProfiles.kt
+++ b/benchmark/benchmark-macro/src/main/java/androidx/benchmark/macro/BaselineProfiles.kt
@@ -26,6 +26,7 @@
import androidx.benchmark.InstrumentationResults
import androidx.benchmark.Outputs
import androidx.benchmark.Shell
+import androidx.benchmark.UserInfo
import androidx.tracing.trace
import java.io.File
@@ -46,6 +47,7 @@
profileBlock: MacrobenchmarkScope.() -> Unit
) {
val scope = buildMacrobenchmarkScope(packageName)
+ val uid = UserInfo.currentUserId
val startTime = System.nanoTime()
// Ensure the device is awake
scope.device.wakeUp()
@@ -89,7 +91,7 @@
if (Build.VERSION.SDK_INT >= 33) {
extractProfile(packageName)
} else {
- extractProfileRooted(packageName)
+ extractProfileRooted(uid, packageName)
}
// Check stability
@@ -209,7 +211,6 @@
*/
@RequiresApi(33)
private fun extractProfile(packageName: String): String {
-
val dumpCommand = "pm dump-profiles --dump-classes-and-methods $packageName"
val stdout = Shell.executeScriptCaptureStdout(dumpCommand).trim()
val expected = "Profile saved to '/data/misc/profman/$packageName-primary.prof.txt'"
@@ -235,11 +236,11 @@
*
* Requires root.
*/
-private fun extractProfileRooted(packageName: String): String {
+private fun extractProfileRooted(uid: Int, packageName: String): String {
// The path of the reference profile
val referenceProfile = "/data/misc/profiles/ref/$packageName/primary.prof"
// The path to the primary profile
- val currentProfile = "/data/misc/profiles/cur/0/$packageName/primary.prof"
+ val currentProfile = "/data/misc/profiles/cur/$uid/$packageName/primary.prof"
Log.d(TAG, "Reference profile location: $referenceProfile")
@Suppress("SimplifiableCallChain") // join+block makes ordering unclear