Merge "Added more systrace points to window manager" into oc-dev

This commit is contained in:
TreeHugger Robot
2017-06-22 19:30:40 +00:00
committed by Android (Google) Code Review
3 changed files with 78 additions and 24 deletions

View File

@@ -18,6 +18,7 @@ package com.android.server.wm;
import static android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; import static android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
import static android.content.pm.PackageManager.PERMISSION_GRANTED; import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType; import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DRAG; import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DRAG;
@@ -37,6 +38,7 @@ import android.os.Parcel;
import android.os.Process; import android.os.Process;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.ServiceManager; import android.os.ServiceManager;
import android.os.Trace;
import android.os.UserHandle; import android.os.UserHandle;
import android.util.MergedConfiguration; import android.util.MergedConfiguration;
import android.util.Slog; import android.util.Slog;
@@ -85,6 +87,7 @@ public class Session extends IWindowSession.Stub
private boolean mClientDead = false; private boolean mClientDead = false;
private float mLastReportedAnimatorScale; private float mLastReportedAnimatorScale;
private String mPackageName; private String mPackageName;
private String mRelayoutTag;
public Session(WindowManagerService service, IWindowSessionCallback callback, public Session(WindowManagerService service, IWindowSessionCallback callback,
IInputMethodClient client, IInputContext inputContext) { IInputMethodClient client, IInputContext inputContext) {
@@ -221,10 +224,12 @@ public class Session extends IWindowSession.Stub
MergedConfiguration mergedConfiguration, Surface outSurface) { MergedConfiguration mergedConfiguration, Surface outSurface) {
if (false) Slog.d(TAG_WM, ">>>>>> ENTERED relayout from " if (false) Slog.d(TAG_WM, ">>>>>> ENTERED relayout from "
+ Binder.getCallingPid()); + Binder.getCallingPid());
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, mRelayoutTag);
int res = mService.relayoutWindow(this, window, seq, attrs, int res = mService.relayoutWindow(this, window, seq, attrs,
requestedWidth, requestedHeight, viewFlags, flags, requestedWidth, requestedHeight, viewFlags, flags,
outFrame, outOverscanInsets, outContentInsets, outVisibleInsets, outFrame, outOverscanInsets, outContentInsets, outVisibleInsets,
outStableInsets, outsets, outBackdropFrame, mergedConfiguration, outSurface); outStableInsets, outsets, outBackdropFrame, mergedConfiguration, outSurface);
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
if (false) Slog.d(TAG_WM, "<<<<<< EXITING relayout to " if (false) Slog.d(TAG_WM, "<<<<<< EXITING relayout to "
+ Binder.getCallingPid()); + Binder.getCallingPid());
return res; return res;
@@ -550,6 +555,7 @@ public class Session extends IWindowSession.Stub
void windowAddedLocked(String packageName) { void windowAddedLocked(String packageName) {
mPackageName = packageName; mPackageName = packageName;
mRelayoutTag = "relayoutWindow: " + mPackageName;
if (mSurfaceSession == null) { if (mSurfaceSession == null) {
if (WindowManagerService.localLOGV) Slog.v( if (WindowManagerService.localLOGV) Slog.v(
TAG_WM, "First window added to " + this + ", creating SurfaceSession"); TAG_WM, "First window added to " + this + ", creating SurfaceSession");
@@ -673,6 +679,7 @@ public class Session extends IWindowSession.Stub
pw.print(" mAlertWindowSurfaces="); pw.print(mAlertWindowSurfaces); pw.print(" mAlertWindowSurfaces="); pw.print(mAlertWindowSurfaces);
pw.print(" mClientDead="); pw.print(mClientDead); pw.print(" mClientDead="); pw.print(mClientDead);
pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
pw.print(prefix); pw.print("mPackageName="); pw.println(mPackageName);
} }
@Override @Override

View File

@@ -30,6 +30,7 @@ import static android.os.Process.SHELL_UID;
import static android.os.Process.SYSTEM_UID; import static android.os.Process.SYSTEM_UID;
import static android.os.Process.THREAD_PRIORITY_DISPLAY; import static android.os.Process.THREAD_PRIORITY_DISPLAY;
import static android.os.Process.myPid; import static android.os.Process.myPid;
import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
import static android.os.UserHandle.USER_NULL; import static android.os.UserHandle.USER_NULL;
import static android.view.Display.DEFAULT_DISPLAY; import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.INVALID_DISPLAY; import static android.view.Display.INVALID_DISPLAY;
@@ -884,12 +885,17 @@ public class WindowManagerService extends IWindowManager.Stub
} }
void openSurfaceTransaction() { void openSurfaceTransaction() {
try {
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "openSurfaceTransaction");
synchronized (mWindowMap) { synchronized (mWindowMap) {
if (mRoot.mSurfaceTraceEnabled) { if (mRoot.mSurfaceTraceEnabled) {
mRoot.mRemoteEventTrace.openSurfaceTransaction(); mRoot.mRemoteEventTrace.openSurfaceTransaction();
} }
SurfaceControl.openTransaction(); SurfaceControl.openTransaction();
} }
} finally {
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
}
} }
void closeSurfaceTransaction() { void closeSurfaceTransaction() {
@@ -904,6 +910,8 @@ public class WindowManagerService extends IWindowManager.Stub
* blocks and we call it repeatedly, like we do for animations. * blocks and we call it repeatedly, like we do for animations.
*/ */
void closeSurfaceTransaction(boolean withLockHeld) { void closeSurfaceTransaction(boolean withLockHeld) {
try {
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "closeSurfaceTransaction");
synchronized (mWindowMap) { synchronized (mWindowMap) {
if (mRoot.mSurfaceTraceEnabled) { if (mRoot.mSurfaceTraceEnabled) {
mRoot.mRemoteEventTrace.closeSurfaceTransaction(); mRoot.mRemoteEventTrace.closeSurfaceTransaction();
@@ -915,6 +923,9 @@ public class WindowManagerService extends IWindowManager.Stub
if (!withLockHeld) { if (!withLockHeld) {
SurfaceControl.closeTransaction(); SurfaceControl.closeTransaction();
} }
} finally {
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
}
} }
/** Listener to notify activity manager about app transitions. */ /** Listener to notify activity manager about app transitions. */
@@ -1988,6 +1999,8 @@ public class WindowManagerService extends IWindowManager.Stub
(win.mAppToken == null || win.mAttrs.type == TYPE_APPLICATION_STARTING (win.mAppToken == null || win.mAttrs.type == TYPE_APPLICATION_STARTING
|| !win.mAppToken.isClientHidden())) { || !win.mAppToken.isClientHidden())) {
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "relayoutWindow: viewVisibility_1");
// We are about to create a surface, but we didn't run a layout yet. So better run // We are about to create a surface, but we didn't run a layout yet. So better run
// a layout now that we already know the right size, as a resize call will make the // a layout now that we already know the right size, as a resize call will make the
// surface transaction blocking until next vsync and slow us down. // surface transaction blocking until next vsync and slow us down.
@@ -1999,6 +2012,7 @@ public class WindowManagerService extends IWindowManager.Stub
} }
result = win.relayoutVisibleWindow(mergedConfiguration, result, attrChanges, result = win.relayoutVisibleWindow(mergedConfiguration, result, attrChanges,
oldVisibility); oldVisibility);
try { try {
result = createSurfaceControl(outSurface, result, win, winAnimator); result = createSurfaceControl(outSurface, result, win, winAnimator);
} catch (Exception e) { } catch (Exception e) {
@@ -2018,7 +2032,10 @@ public class WindowManagerService extends IWindowManager.Stub
imMayMove = true; imMayMove = true;
} }
win.adjustStartingWindowFlags(); win.adjustStartingWindowFlags();
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
} else { } else {
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "relayoutWindow: viewVisibility_2");
winAnimator.mEnterAnimationPending = false; winAnimator.mEnterAnimationPending = false;
winAnimator.mEnteringAnimation = false; winAnimator.mEnteringAnimation = false;
final boolean usingSavedSurfaceBeforeVisible = final boolean usingSavedSurfaceBeforeVisible =
@@ -2053,18 +2070,22 @@ public class WindowManagerService extends IWindowManager.Stub
// We already told the client to go invisible, but the message may not be // We already told the client to go invisible, but the message may not be
// handled yet, or it might want to draw a last frame. If we already have a // handled yet, or it might want to draw a last frame. If we already have a
// surface, let the client use that, but don't create new surface at this point. // surface, let the client use that, but don't create new surface at this point.
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "relayoutWindow: getSurface");
winAnimator.mSurfaceController.getSurface(outSurface); winAnimator.mSurfaceController.getSurface(outSurface);
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
} else { } else {
if (DEBUG_VISIBILITY) Slog.i(TAG_WM, "Releasing surface in: " + win); if (DEBUG_VISIBILITY) Slog.i(TAG_WM, "Releasing surface in: " + win);
try { try {
Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "wmReleaseOutSurface_" Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wmReleaseOutSurface_"
+ win.mAttrs.getTitle()); + win.mAttrs.getTitle());
outSurface.release(); outSurface.release();
} finally { } finally {
Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
} }
} }
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
} }
if (focusMayChange) { if (focusMayChange) {
@@ -2101,8 +2122,11 @@ public class WindowManagerService extends IWindowManager.Stub
} }
win.setDisplayLayoutNeeded(); win.setDisplayLayoutNeeded();
win.mGivenInsetsPending = (flags&WindowManagerGlobal.RELAYOUT_INSETS_PENDING) != 0; win.mGivenInsetsPending = (flags & WindowManagerGlobal.RELAYOUT_INSETS_PENDING) != 0;
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER,
"relayoutWindow: updateOrientationFromAppTokens");
configChanged = updateOrientationFromAppTokensLocked(false, displayId); configChanged = updateOrientationFromAppTokensLocked(false, displayId);
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
// We may be deferring layout passes at the moment, but since the client is interested // We may be deferring layout passes at the moment, but since the client is interested
// in the new out values right now we need to force a layout. // in the new out values right now we need to force a layout.
@@ -2155,7 +2179,9 @@ public class WindowManagerService extends IWindowManager.Stub
} }
if (configChanged) { if (configChanged) {
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "relayoutWindow: sendNewConfiguration");
sendNewConfiguration(displayId); sendNewConfiguration(displayId);
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
} }
Binder.restoreCallingIdentity(origId); Binder.restoreCallingIdentity(origId);
return result; return result;
@@ -2216,8 +2242,14 @@ public class WindowManagerService extends IWindowManager.Stub
if (!win.mHasSurface) { if (!win.mHasSurface) {
result |= RELAYOUT_RES_SURFACE_CHANGED; result |= RELAYOUT_RES_SURFACE_CHANGED;
} }
WindowSurfaceController surfaceController = winAnimator.createSurfaceLocked(
win.mAttrs.type, win.mOwnerUid); WindowSurfaceController surfaceController;
try {
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "createSurfaceControl");
surfaceController = winAnimator.createSurfaceLocked(win.mAttrs.type, win.mOwnerUid);
} finally {
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
}
if (surfaceController != null) { if (surfaceController != null) {
surfaceController.getSurface(outSurface); surfaceController.getSurface(outSurface);
if (SHOW_TRANSACTIONS) Slog.i(TAG_WM, " OUT SURFACE " + outSurface + ": copied"); if (SHOW_TRANSACTIONS) Slog.i(TAG_WM, " OUT SURFACE " + outSurface + ": copied");
@@ -2227,6 +2259,7 @@ public class WindowManagerService extends IWindowManager.Stub
Slog.w(TAG_WM, "Failed to create surface control for " + win); Slog.w(TAG_WM, "Failed to create surface control for " + win);
outSurface.release(); outSurface.release();
} }
return result; return result;
} }
@@ -2273,7 +2306,7 @@ public class WindowManagerService extends IWindowManager.Stub
// frozen, there is no reason to animate and it can cause strange // frozen, there is no reason to animate and it can cause strange
// artifacts when we unfreeze the display if some different animation // artifacts when we unfreeze the display if some different animation
// is running. // is running.
Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "WM#applyAnimationLocked"); Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "WM#applyAnimationLocked");
if (okToDisplay()) { if (okToDisplay()) {
final DisplayContent displayContent = atoken.getTask().getDisplayContent(); final DisplayContent displayContent = atoken.getTask().getDisplayContent();
final DisplayInfo displayInfo = displayContent.getDisplayInfo(); final DisplayInfo displayInfo = displayContent.getDisplayInfo();
@@ -2329,7 +2362,7 @@ public class WindowManagerService extends IWindowManager.Stub
} else { } else {
atoken.mAppAnimator.clearAnimation(); atoken.mAppAnimator.clearAnimation();
} }
Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
return atoken.mAppAnimator.animation != null; return atoken.mAppAnimator.animation != null;
} }
@@ -3412,7 +3445,7 @@ public class WindowManagerService extends IWindowManager.Stub
if (!mBootAnimationStopped) { if (!mBootAnimationStopped) {
// Do this one time. // Do this one time.
Trace.asyncTraceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "Stop bootanim", 0); Trace.asyncTraceBegin(TRACE_TAG_WINDOW_MANAGER, "Stop bootanim", 0);
try { try {
IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
if (surfaceFlinger != null) { if (surfaceFlinger != null) {
@@ -3435,7 +3468,7 @@ public class WindowManagerService extends IWindowManager.Stub
} }
EventLog.writeEvent(EventLogTags.WM_BOOT_ANIMATION_DONE, SystemClock.uptimeMillis()); EventLog.writeEvent(EventLogTags.WM_BOOT_ANIMATION_DONE, SystemClock.uptimeMillis());
Trace.asyncTraceEnd(Trace.TRACE_TAG_WINDOW_MANAGER, "Stop bootanim", 0); Trace.asyncTraceEnd(TRACE_TAG_WINDOW_MANAGER, "Stop bootanim", 0);
mDisplayEnabled = true; mDisplayEnabled = true;
if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM, "******************** ENABLING SCREEN!"); if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM, "******************** ENABLING SCREEN!");
@@ -3666,12 +3699,12 @@ public class WindowManagerService extends IWindowManager.Stub
throw new SecurityException("Requires READ_FRAME_BUFFER permission"); throw new SecurityException("Requires READ_FRAME_BUFFER permission");
} }
try { try {
Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "screenshotWallpaper"); Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "screenshotWallpaper");
return screenshotApplications(null /* appToken */, DEFAULT_DISPLAY, -1 /* width */, return screenshotApplications(null /* appToken */, DEFAULT_DISPLAY, -1 /* width */,
-1 /* height */, true /* includeFullDisplay */, 1f /* frameScale */, -1 /* height */, true /* includeFullDisplay */, 1f /* frameScale */,
Bitmap.Config.ARGB_8888, true /* wallpaperOnly */, false /* includeDecor */); Bitmap.Config.ARGB_8888, true /* wallpaperOnly */, false /* includeDecor */);
} finally { } finally {
Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
} }
} }
@@ -3857,6 +3890,8 @@ public class WindowManagerService extends IWindowManager.Stub
+ " alwaysSendConfiguration=" + alwaysSendConfiguration + " alwaysSendConfiguration=" + alwaysSendConfiguration
+ " forceRelayout=" + forceRelayout); + " forceRelayout=" + forceRelayout);
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "updateRotation");
long origId = Binder.clearCallingIdentity(); long origId = Binder.clearCallingIdentity();
try { try {
@@ -3865,20 +3900,28 @@ public class WindowManagerService extends IWindowManager.Stub
final int displayId; final int displayId;
synchronized (mWindowMap) { synchronized (mWindowMap) {
final DisplayContent displayContent = getDefaultDisplayContentLocked(); final DisplayContent displayContent = getDefaultDisplayContentLocked();
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "updateRotation: display");
rotationChanged = displayContent.updateRotationUnchecked( rotationChanged = displayContent.updateRotationUnchecked(
false /* inTransaction */); false /* inTransaction */);
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
if (!rotationChanged || forceRelayout) { if (!rotationChanged || forceRelayout) {
displayContent.setLayoutNeeded(); displayContent.setLayoutNeeded();
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER,
"updateRotation: performSurfacePlacement");
mWindowPlacerLocked.performSurfacePlacement(); mWindowPlacerLocked.performSurfacePlacement();
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
} }
displayId = displayContent.getDisplayId(); displayId = displayContent.getDisplayId();
} }
if (rotationChanged || alwaysSendConfiguration) { if (rotationChanged || alwaysSendConfiguration) {
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "updateRotation: sendNewConfiguration");
sendNewConfiguration(displayId); sendNewConfiguration(displayId);
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
} }
} finally { } finally {
Binder.restoreCallingIdentity(origId); Binder.restoreCallingIdentity(origId);
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
} }
} }
@@ -5806,7 +5849,7 @@ public class WindowManagerService extends IWindowManager.Stub
boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) { boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) {
WindowState newFocus = mRoot.computeFocusedWindow(); WindowState newFocus = mRoot.computeFocusedWindow();
if (mCurrentFocus != newFocus) { if (mCurrentFocus != newFocus) {
Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "wmUpdateFocus"); Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wmUpdateFocus");
// This check makes sure that we don't already have the focus // This check makes sure that we don't already have the focus
// change message pending. // change message pending.
mH.removeMessages(H.REPORT_FOCUS_CHANGE); mH.removeMessages(H.REPORT_FOCUS_CHANGE);
@@ -5882,7 +5925,7 @@ public class WindowManagerService extends IWindowManager.Stub
// other apps' UI. // other apps' UI.
displayContent.scheduleToastWindowsTimeoutIfNeededLocked(oldFocus, newFocus); displayContent.scheduleToastWindowsTimeoutIfNeededLocked(oldFocus, newFocus);
Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
return true; return true;
} }
return false; return false;

View File

@@ -16,6 +16,7 @@
package com.android.server.wm; package com.android.server.wm;
import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC; import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC;
import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS; import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS; import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
@@ -33,6 +34,7 @@ import android.graphics.Rect;
import android.graphics.Region; import android.graphics.Region;
import android.os.IBinder; import android.os.IBinder;
import android.os.Debug; import android.os.Debug;
import android.os.Trace;
import android.view.Surface; import android.view.Surface;
import android.view.SurfaceControl; import android.view.SurfaceControl;
import android.view.SurfaceSession; import android.view.SurfaceSession;
@@ -101,8 +103,10 @@ class WindowSurfaceController {
mSurfaceControl = new SurfaceTrace( mSurfaceControl = new SurfaceTrace(
s, name, w, h, format, flags, windowType, ownerUid); s, name, w, h, format, flags, windowType, ownerUid);
} else { } else {
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "new SurfaceControl");
mSurfaceControl = new SurfaceControl( mSurfaceControl = new SurfaceControl(
s, name, w, h, format, flags, windowType, ownerUid); s, name, w, h, format, flags, windowType, ownerUid);
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
} }
if (mService.mRoot.mSurfaceTraceEnabled) { if (mService.mRoot.mSurfaceTraceEnabled) {