Merge "Fix a couple trace issues" into ub-launcher3-master

This commit is contained in:
Winson Chung 2019-10-16 20:54:43 +00:00 committed by Android (Google) Code Review
commit 40f8756793
7 changed files with 80 additions and 47 deletions

View File

@ -417,7 +417,8 @@ public class TouchInteractionService extends Service implements
return; return;
} }
TraceHelper.INSTANCE.beginFlagsOverride(TraceHelper.FLAG_ALLOW_BINDER_TRACKING); Object traceToken = TraceHelper.INSTANCE.beginFlagsOverride(
TraceHelper.FLAG_ALLOW_BINDER_TRACKING);
MotionEvent event = (MotionEvent) ev; MotionEvent event = (MotionEvent) ev;
if (event.getAction() == ACTION_DOWN) { if (event.getAction() == ACTION_DOWN) {
GestureState newGestureState = new GestureState( GestureState newGestureState = new GestureState(
@ -446,7 +447,7 @@ public class TouchInteractionService extends Service implements
ActiveGestureLog.INSTANCE.addLog("onMotionEvent", event.getActionMasked()); ActiveGestureLog.INSTANCE.addLog("onMotionEvent", event.getActionMasked());
mUncheckedConsumer.onMotionEvent(event); mUncheckedConsumer.onMotionEvent(event);
TraceHelper.INSTANCE.endFlagsOverride(); TraceHelper.INSTANCE.endFlagsOverride(traceToken);
} }
private InputConsumer newConsumer(GestureState gestureState, boolean useSharedState, private InputConsumer newConsumer(GestureState gestureState, boolean useSharedState,

View File

@ -367,13 +367,19 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity>
if (mWasLauncherAlreadyVisible) { if (mWasLauncherAlreadyVisible) {
mStateCallback.setState(STATE_LAUNCHER_DRAWN); mStateCallback.setState(STATE_LAUNCHER_DRAWN);
} else { } else {
TraceHelper.INSTANCE.beginSection("WTS-init"); Object traceToken = TraceHelper.INSTANCE.beginSection("WTS-init");
View dragLayer = activity.getDragLayer(); View dragLayer = activity.getDragLayer();
dragLayer.getViewTreeObserver().addOnDrawListener(new OnDrawListener() { dragLayer.getViewTreeObserver().addOnDrawListener(new OnDrawListener() {
boolean mHandled = false;
@Override @Override
public void onDraw() { public void onDraw() {
TraceHelper.INSTANCE.endSection(); if (mHandled) {
return;
}
mHandled = true;
TraceHelper.INSTANCE.endSection(traceToken);
dragLayer.post(() -> dragLayer.post(() ->
dragLayer.getViewTreeObserver().removeOnDrawListener(this)); dragLayer.getViewTreeObserver().removeOnDrawListener(this));
if (activity != mActivity) { if (activity != mActivity) {
@ -416,13 +422,14 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity>
private void initializeLauncherAnimationController() { private void initializeLauncherAnimationController() {
buildAnimationController(); buildAnimationController();
TraceHelper.INSTANCE.beginSection("logToggleRecents", TraceHelper.FLAG_IGNORE_BINDERS); Object traceToken = TraceHelper.INSTANCE.beginSection("logToggleRecents",
TraceHelper.FLAG_IGNORE_BINDERS);
// Only used in debug builds // Only used in debug builds
if (LatencyTrackerCompat.isEnabled(mContext)) { if (LatencyTrackerCompat.isEnabled(mContext)) {
LatencyTrackerCompat.logToggleRecents( LatencyTrackerCompat.logToggleRecents(
(int) (mLauncherFrameDrawnTime - mTouchTimeMs)); (int) (mLauncherFrameDrawnTime - mTouchTimeMs));
} }
TraceHelper.INSTANCE.endSection(); TraceHelper.INSTANCE.endSection(traceToken);
// This method is only called when STATE_GESTURE_STARTED is set, so we can enable the // This method is only called when STATE_GESTURE_STARTED is set, so we can enable the
// high-res thumbnail loader here once we are sure that we will end up in an overview state // high-res thumbnail loader here once we are sure that we will end up in an overview state
@ -1144,10 +1151,10 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity>
} }
if (!finishTransitionPosted) { if (!finishTransitionPosted) {
// If we haven't posted a draw callback, set the state immediately. // If we haven't posted a draw callback, set the state immediately.
TraceHelper.INSTANCE.beginSection(SCREENSHOT_CAPTURED_EVT, Object traceToken = TraceHelper.INSTANCE.beginSection(SCREENSHOT_CAPTURED_EVT,
TraceHelper.FLAG_CHECK_FOR_RACE_CONDITIONS); TraceHelper.FLAG_CHECK_FOR_RACE_CONDITIONS);
setStateOnUiThread(STATE_SCREENSHOT_CAPTURED); setStateOnUiThread(STATE_SCREENSHOT_CAPTURED);
TraceHelper.INSTANCE.endSection(); TraceHelper.INSTANCE.endSection(traceToken);
} }
} }
} }

View File

@ -198,7 +198,8 @@ public class OtherActivityInputConsumer extends ContextWrapper implements InputC
switch (ev.getActionMasked()) { switch (ev.getActionMasked()) {
case ACTION_DOWN: { case ACTION_DOWN: {
TraceHelper.INSTANCE.beginSection(DOWN_EVT, FLAG_CHECK_FOR_RACE_CONDITIONS); Object traceToken = TraceHelper.INSTANCE.beginSection(DOWN_EVT,
FLAG_CHECK_FOR_RACE_CONDITIONS);
mActivePointerId = ev.getPointerId(0); mActivePointerId = ev.getPointerId(0);
mDownPos.set(ev.getX(), ev.getY()); mDownPos.set(ev.getX(), ev.getY());
mLastPos.set(mDownPos); mLastPos.set(mDownPos);
@ -209,7 +210,7 @@ public class OtherActivityInputConsumer extends ContextWrapper implements InputC
startTouchTrackingForWindowAnimation(ev.getEventTime(), false); startTouchTrackingForWindowAnimation(ev.getEventTime(), false);
} }
TraceHelper.INSTANCE.endSection(); TraceHelper.INSTANCE.endSection(traceToken);
break; break;
} }
case ACTION_POINTER_DOWN: { case ACTION_POINTER_DOWN: {
@ -355,7 +356,8 @@ public class OtherActivityInputConsumer extends ContextWrapper implements InputC
* the animation can still be running. * the animation can still be running.
*/ */
private void finishTouchTracking(MotionEvent ev) { private void finishTouchTracking(MotionEvent ev) {
TraceHelper.INSTANCE.beginSection(UP_EVT, FLAG_CHECK_FOR_RACE_CONDITIONS); Object traceToken = TraceHelper.INSTANCE.beginSection(UP_EVT,
FLAG_CHECK_FOR_RACE_CONDITIONS);
if (mPassedWindowMoveSlop && mInteractionHandler != null) { if (mPassedWindowMoveSlop && mInteractionHandler != null) {
if (ev.getActionMasked() == ACTION_CANCEL) { if (ev.getActionMasked() == ACTION_CANCEL) {
@ -389,7 +391,7 @@ public class OtherActivityInputConsumer extends ContextWrapper implements InputC
mVelocityTracker.recycle(); mVelocityTracker.recycle();
mVelocityTracker = null; mVelocityTracker = null;
mMotionPauseDetector.clear(); mMotionPauseDetector.clear();
TraceHelper.INSTANCE.endSection(); TraceHelper.INSTANCE.endSection(traceToken);
} }
@Override @Override

View File

@ -313,7 +313,8 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
TraceHelper.INSTANCE.beginSection(ON_CREATE_EVT, TraceHelper.FLAG_UI_EVENT); Object traceToken = TraceHelper.INSTANCE.beginSection(ON_CREATE_EVT,
TraceHelper.FLAG_UI_EVENT);
if (DEBUG_STRICT_MODE) { if (DEBUG_STRICT_MODE) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads() .detectDiskReads()
@ -431,7 +432,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
} }
}); });
TraceHelper.INSTANCE.endSection(); TraceHelper.INSTANCE.endSection(traceToken);
} }
protected LauncherOverlayManager getDefaultOverlay() { protected LauncherOverlayManager getDefaultOverlay() {
@ -936,14 +937,15 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
@Override @Override
protected void onStart() { protected void onStart() {
TraceHelper.INSTANCE.beginSection(ON_START_EVT, TraceHelper.FLAG_UI_EVENT); Object traceToken = TraceHelper.INSTANCE.beginSection(ON_START_EVT,
TraceHelper.FLAG_UI_EVENT);
super.onStart(); super.onStart();
if (!mDeferOverlayCallbacks) { if (!mDeferOverlayCallbacks) {
mOverlayManager.onActivityStarted(this); mOverlayManager.onActivityStarted(this);
} }
mAppWidgetHost.setListenIfResumed(true); mAppWidgetHost.setListenIfResumed(true);
TraceHelper.INSTANCE.endSection(); TraceHelper.INSTANCE.endSection(traceToken);
} }
private void handleDeferredResume() { private void handleDeferredResume() {
@ -1038,7 +1040,8 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
@Override @Override
protected void onResume() { protected void onResume() {
TraceHelper.INSTANCE.beginSection(ON_RESUME_EVT, TraceHelper.FLAG_UI_EVENT); Object traceToken = TraceHelper.INSTANCE.beginSection(ON_RESUME_EVT,
TraceHelper.FLAG_UI_EVENT);
super.onResume(); super.onResume();
mHandler.removeCallbacks(mHandleDeferredResume); mHandler.removeCallbacks(mHandleDeferredResume);
@ -1059,7 +1062,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
mOverlayManager.onActivityResumed(this); mOverlayManager.onActivityResumed(this);
} }
TraceHelper.INSTANCE.endSection(); TraceHelper.INSTANCE.endSection(traceToken);
} }
@Override @Override
@ -1423,7 +1426,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
@Override @Override
protected void onNewIntent(Intent intent) { protected void onNewIntent(Intent intent) {
TraceHelper.INSTANCE.beginSection(ON_NEW_INTENT_EVT); Object traceToken = TraceHelper.INSTANCE.beginSection(ON_NEW_INTENT_EVT);
super.onNewIntent(intent); super.onNewIntent(intent);
boolean alreadyOnHome = hasWindowFocus() && ((intent.getFlags() & boolean alreadyOnHome = hasWindowFocus() && ((intent.getFlags() &
@ -1475,7 +1478,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
mOverlayManager.hideOverlay(isStarted() && !isForceInvisible()); mOverlayManager.hideOverlay(isStarted() && !isForceInvisible());
} }
TraceHelper.INSTANCE.endSection(); TraceHelper.INSTANCE.endSection(traceToken);
} }
@Override @Override
@ -1978,7 +1981,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
* Implementation of the method from LauncherModel.Callbacks. * Implementation of the method from LauncherModel.Callbacks.
*/ */
public void startBinding() { public void startBinding() {
TraceHelper.INSTANCE.beginSection("startBinding"); Object traceToken = TraceHelper.INSTANCE.beginSection("startBinding");
// Floating panels (except the full widget sheet) are associated with individual icons. If // Floating panels (except the full widget sheet) are associated with individual icons. If
// we are starting a fresh bind, close all such panels as all the icons are about // we are starting a fresh bind, close all such panels as all the icons are about
// to go away. // to go away.
@ -1996,7 +1999,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
if (mHotseat != null) { if (mHotseat != null) {
mHotseat.resetLayout(getWallpaperDeviceProfile().isVerticalBarLayout()); mHotseat.resetLayout(getWallpaperDeviceProfile().isVerticalBarLayout());
} }
TraceHelper.INSTANCE.endSection(); TraceHelper.INSTANCE.endSection(traceToken);
} }
@Override @Override
@ -2196,7 +2199,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
return view; return view;
} }
TraceHelper.INSTANCE.beginSection("BIND_WIDGET_id=" + item.appWidgetId); Object traceToken = TraceHelper.INSTANCE.beginSection("BIND_WIDGET_id=" + item.appWidgetId);
try { try {
final LauncherAppWidgetProviderInfo appWidgetInfo; final LauncherAppWidgetProviderInfo appWidgetInfo;
@ -2293,7 +2296,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
} }
prepareAppWidget(view, item); prepareAppWidget(view, item);
} finally { } finally {
TraceHelper.INSTANCE.endSection(); TraceHelper.INSTANCE.endSection(traceToken);
} }
return view; return view;
@ -2373,7 +2376,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
* Implementation of the method from LauncherModel.Callbacks. * Implementation of the method from LauncherModel.Callbacks.
*/ */
public void finishBindingItems(int pageBoundFirst) { public void finishBindingItems(int pageBoundFirst) {
TraceHelper.INSTANCE.beginSection("finishBindingItems"); Object traceToken = TraceHelper.INSTANCE.beginSection("finishBindingItems");
mWorkspace.restoreInstanceStateForRemainingPages(); mWorkspace.restoreInstanceStateForRemainingPages();
setWorkspaceLoading(false); setWorkspaceLoading(false);
@ -2397,7 +2400,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
mDeviceProfile.inv.numFolderColumns * mDeviceProfile.inv.numFolderRows); mDeviceProfile.inv.numFolderColumns * mDeviceProfile.inv.numFolderRows);
getViewCache().setCacheSize(R.layout.folder_page, 2); getViewCache().setCacheSize(R.layout.folder_page, 2);
TraceHelper.INSTANCE.endSection(); TraceHelper.INSTANCE.endSection(traceToken);
} }
private boolean canRunNewAppsAnimation() { private boolean canRunNewAppsAnimation() {

View File

@ -180,7 +180,7 @@ public class LoaderTask implements Runnable {
"LoaderTask2 " + this); "LoaderTask2 " + this);
} }
TraceHelper.INSTANCE.beginSection(TAG); Object traceToken = TraceHelper.INSTANCE.beginSection(TAG);
TimingLogger logger = TestProtocol.sDebugTracing ? TimingLogger logger = TestProtocol.sDebugTracing ?
new TimingLogger(TAG, "run") { new TimingLogger(TAG, "run") {
@Override @Override
@ -281,7 +281,7 @@ public class LoaderTask implements Runnable {
} finally { } finally {
logger.dumpToLog(); logger.dumpToLog();
} }
TraceHelper.INSTANCE.endSection(); TraceHelper.INSTANCE.endSection(traceToken);
} }
public synchronized void stopLocked() { public synchronized void stopLocked() {

View File

@ -46,35 +46,44 @@ public class TraceHelper {
*/ */
public static TraceHelper INSTANCE = new TraceHelper(); public static TraceHelper INSTANCE = new TraceHelper();
public void beginSection(String sectionName) { /**
beginSection(sectionName, 0); * @return a token to pass into {@link #endSection(Object)}.
*/
public Object beginSection(String sectionName) {
return beginSection(sectionName, 0);
} }
public void beginSection(String sectionName, int flags) { public Object beginSection(String sectionName, int flags) {
Trace.beginSection(sectionName); Trace.beginSection(sectionName);
return null;
} }
public void endSection() { /**
* @param token the token returned from {@link #beginSection(String, int)}
*/
public void endSection(Object token) {
Trace.endSection(); Trace.endSection();
} }
/** /**
* Similar to {@link #beginSection} but doesn't add a trace section. * Similar to {@link #beginSection} but doesn't add a trace section.
*/ */
public void beginFlagsOverride(int flags) { } public Object beginFlagsOverride(int flags) {
return null;
}
public void endFlagsOverride() { } public void endFlagsOverride(Object token) { }
/** /**
* Temporarily ignore blocking binder calls for the duration of this {@link Supplier}. * Temporarily ignore blocking binder calls for the duration of this {@link Supplier}.
*/ */
@MainThread @MainThread
public static <T> T whitelistIpcs(String rpcName, Supplier<T> supplier) { public static <T> T whitelistIpcs(String rpcName, Supplier<T> supplier) {
INSTANCE.beginSection(rpcName, FLAG_IGNORE_BINDERS); Object traceToken = INSTANCE.beginSection(rpcName, FLAG_IGNORE_BINDERS);
try { try {
return supplier.get(); return supplier.get();
} finally { } finally {
INSTANCE.endSection(); INSTANCE.endSection(traceToken);
} }
} }
} }

View File

@ -46,9 +46,10 @@ public class TraceHelperForTest extends TraceHelper {
private TraceHelperForTest() { } private TraceHelperForTest() { }
@Override @Override
public void beginSection(String sectionName, int flags) { public Object beginSection(String sectionName, int flags) {
LinkedList<TraceInfo> stack = mStack.get(); LinkedList<TraceInfo> stack = mStack.get();
stack.add(new TraceInfo(sectionName, flags)); TraceInfo info = new TraceInfo(sectionName, flags);
stack.add(info);
if ((flags & TraceHelper.FLAG_CHECK_FOR_RACE_CONDITIONS) != 0 if ((flags & TraceHelper.FLAG_CHECK_FOR_RACE_CONDITIONS) != 0
&& mRaceConditionReproducer != null) { && mRaceConditionReproducer != null) {
@ -57,39 +58,49 @@ public class TraceHelperForTest extends TraceHelper {
updateBinderTracking(stack); updateBinderTracking(stack);
super.beginSection(sectionName, flags); super.beginSection(sectionName, flags);
return info;
} }
@Override @Override
public void endSection() { public void endSection(Object token) {
LinkedList<TraceInfo> stack = mStack.get(); LinkedList<TraceInfo> stack = mStack.get();
TraceInfo info = stack.pollLast(); if (stack.size() == 0) {
new Throwable().printStackTrace();
}
TraceInfo info = (TraceInfo) token;
stack.remove(info);
if ((info.flags & TraceHelper.FLAG_CHECK_FOR_RACE_CONDITIONS) != 0 if ((info.flags & TraceHelper.FLAG_CHECK_FOR_RACE_CONDITIONS) != 0
&& mRaceConditionReproducer != null) { && mRaceConditionReproducer != null) {
mRaceConditionReproducer.onEvent(RaceConditionReproducer.exitEvt(info.sectionName)); mRaceConditionReproducer.onEvent(RaceConditionReproducer.exitEvt(info.sectionName));
} }
updateBinderTracking(stack); updateBinderTracking(stack);
super.endSection(); super.endSection(token);
} }
@Override @Override
public void beginFlagsOverride(int flags) { public Object beginFlagsOverride(int flags) {
LinkedList<TraceInfo> stack = mStack.get(); LinkedList<TraceInfo> stack = mStack.get();
stack.push(new TraceInfo(null, flags)); TraceInfo info = new TraceInfo(null, flags);
stack.add(info);
updateBinderTracking(stack); updateBinderTracking(stack);
super.beginFlagsOverride(flags); super.beginFlagsOverride(flags);
return info;
} }
@Override @Override
public void endFlagsOverride() { public void endFlagsOverride(Object token) {
super.endFlagsOverride(); super.endFlagsOverride(token);
updateBinderTracking(mStack.get()); LinkedList<TraceInfo> stack = mStack.get();
TraceInfo info = (TraceInfo) token;
stack.remove(info);
updateBinderTracking(stack);
} }
private void updateBinderTracking(LinkedList<TraceInfo> stack) { private void updateBinderTracking(LinkedList<TraceInfo> stack) {
if (mFlagsChangeListener != null) { if (mFlagsChangeListener != null) {
mFlagsChangeListener.accept(stack.stream() mFlagsChangeListener.accept(stack.stream()
.mapToInt(s -> s.flags).reduce(0, (a, b) -> a | b)); .mapToInt(info -> info.flags).reduce(0, (a, b) -> a | b));
} }
} }