From 27421aca2c6ecdd72f32c2513dbb06abf5367add Mon Sep 17 00:00:00 2001 From: Yasin Kilicdere Date: Wed, 9 Nov 2022 17:45:00 +0000 Subject: [PATCH] Add trace logs to UserSwitchObserver callbacks. UserSwitchObservers have a reply mechanism to know when the observers finish doing their job on onUserSwitching event. These callbacks were not shown on perfetto traces. Adding these will be helpful to see when each callback is called while investigating perfetto traces. Note that these traces won't be able to show the duration of the work done by the observers since beginning and end calls can be on different threads. But they will mark the callbacks on the timetable of perfetto ui. Bug: 256604395 Test: N/A Change-Id: Ib1c76554caa472da99e86f6368611d0d251c25db --- .../java/com/android/server/am/UserController.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/services/core/java/com/android/server/am/UserController.java b/services/core/java/com/android/server/am/UserController.java index af559808d880f..a1f7d6e7000be 100644 --- a/services/core/java/com/android/server/am/UserController.java +++ b/services/core/java/com/android/server/am/UserController.java @@ -2075,6 +2075,8 @@ class UserController implements Handler.Callback { } private void timeoutUserSwitch(UserState uss, int oldUserId, int newUserId) { + TimingsTraceAndSlog t = new TimingsTraceAndSlog(TAG); + t.traceBegin("timeoutUserSwitch-" + oldUserId + "-to-" + newUserId); synchronized (mLock) { Slogf.e(TAG, "User switch timeout: from " + oldUserId + " to " + newUserId); mTimeoutUserSwitchCallbacks = mCurWaitingUserSwitchCallbacks; @@ -2084,6 +2086,7 @@ class UserController implements Handler.Callback { mHandler.sendMessageDelayed(mHandler.obtainMessage(USER_SWITCH_CALLBACKS_TIMEOUT_MSG, oldUserId, newUserId), USER_SWITCH_CALLBACKS_TIMEOUT_MS); } + t.traceEnd(); } private void timeoutUserSwitchCallbacks(int oldUserId, int newUserId) { @@ -2141,6 +2144,8 @@ class UserController implements Handler.Callback { + " ms after dispatchUserSwitch."); } + TimingsTraceAndSlog t2 = new TimingsTraceAndSlog(TAG); + t2.traceBegin("onUserSwitchingReply-" + name); curWaitingUserSwitchCallbacks.remove(name); // Continue switching if all callbacks have been notified and // user switching session is still valid @@ -2149,11 +2154,15 @@ class UserController implements Handler.Callback { == mCurWaitingUserSwitchCallbacks)) { sendContinueUserSwitchLU(uss, oldUserId, newUserId); } + t2.traceEnd(); } } }; + t.traceBegin("onUserSwitching-" + name); mUserSwitchObservers.getBroadcastItem(i).onUserSwitching(newUserId, callback); + t.traceEnd(); } catch (RemoteException e) { + // Ignore } } } else { @@ -2167,10 +2176,13 @@ class UserController implements Handler.Callback { @GuardedBy("mLock") private void sendContinueUserSwitchLU(UserState uss, int oldUserId, int newUserId) { + TimingsTraceAndSlog t = new TimingsTraceAndSlog(TAG); + t.traceBegin("sendContinueUserSwitchLU-" + oldUserId + "-to-" + newUserId); mCurWaitingUserSwitchCallbacks = null; mHandler.removeMessages(USER_SWITCH_TIMEOUT_MSG); mHandler.sendMessage(mHandler.obtainMessage(CONTINUE_USER_SWITCH_MSG, oldUserId, newUserId, uss)); + t.traceEnd(); } @VisibleForTesting