Multiuser perfetto metric: adb tracepoints

Add tracepoints in adb for user switches and creation, for the
primary purpose of performance metrics in trace_processor.

These need to be done at the level of shell, not
UserController/UserManager because each entrypoint needs an explicit
tracepoint.
We already have some for UI-based entrypoints - and we want to time
from the moment
the user requests the switch, not some internal point that might be
substantially later - so to capture adb-based switching/creation within
the same trace processor mechanism, we must also add tracepoints for
the shell commands.

Bug: 192001071
Test: manual
Change-Id: I2d7d30faf7906eb455f5d2dc05f0d6b2d96518c2
This commit is contained in:
Adam Bookatz
2021-11-08 17:14:22 -08:00
parent 2cb0187713
commit 12d2a30a3e
3 changed files with 21 additions and 11 deletions

View File

@@ -85,6 +85,7 @@ import android.os.ShellCommand;
import android.os.StrictMode;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.Trace;
import android.os.UserHandle;
import android.os.UserManager;
import android.text.TextUtils;
@@ -1880,16 +1881,21 @@ final class ActivityManagerShellCommand extends ShellCommand {
int userId = Integer.parseInt(getNextArgRequired());
boolean switched;
if (wait) {
switched = switchUserAndWaitForComplete(userId);
} else {
switched = mInterface.switchUser(userId);
}
if (switched) {
return 0;
} else {
pw.printf("Error: Failed to switch to user %d\n", userId);
return 1;
Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "shell_runSwitchUser");
try {
if (wait) {
switched = switchUserAndWaitForComplete(userId);
} else {
switched = mInterface.switchUser(userId);
}
if (switched) {
return 0;
} else {
pw.printf("Error: Failed to switch to user %d\n", userId);
return 1;
}
} finally {
Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
}
}

View File

@@ -1373,7 +1373,7 @@ class UserController implements Handler.Callback {
@Nullable IProgressListener unlockListener) {
TimingsTraceAndSlog t = new TimingsTraceAndSlog();
t.traceBegin("startUser-" + userId + "-" + (foreground ? "fg" : "bg"));
t.traceBegin("UserController.startUser-" + userId + "-" + (foreground ? "fg" : "bg"));
try {
return startUserInternal(userId, foreground, unlockListener, t);
} finally {

View File

@@ -81,6 +81,7 @@ import android.os.ServiceSpecificException;
import android.os.ShellCommand;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.Trace;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.incremental.V4Signature;
@@ -2629,6 +2630,7 @@ class PackageManagerShellCommand extends ShellCommand {
if (userType == null) {
userType = UserInfo.getDefaultUserType(flags);
}
Trace.traceBegin(Trace.TRACE_TAG_PACKAGE_MANAGER, "shell_runCreateUser");
try {
if (UserManager.isUserTypeRestricted(userType)) {
// In non-split user mode, userId can only be SYSTEM
@@ -2645,6 +2647,8 @@ class PackageManagerShellCommand extends ShellCommand {
}
} catch (ServiceSpecificException e) {
getErrPrintWriter().println("Error: " + e);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_PACKAGE_MANAGER);
}
if (info != null) {