Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a57a0fb7 authored by Tony Huang's avatar Tony Huang
Browse files

Metirc largest view percentage each inflate frame

Bug: 301343249
Test: record_android_trace view -a*
Flag: ACONFIG android.view.flags.Flags.toolkitMetrics DEVELOPMENT
Change-Id: Icd80c9e8790a49d8efa7a4596cc2858222385618
parent 6300e048
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import static android.view.displayhash.DisplayHashResultCallback.EXTRA_DISPLAY_H
import static android.view.displayhash.DisplayHashResultCallback.EXTRA_DISPLAY_HASH_ERROR_CODE;
import static android.view.flags.Flags.FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY;
import static android.view.flags.Flags.FLAG_VIEW_VELOCITY_API;
import static android.view.flags.Flags.toolkitMetricsForFrameRateDecision;
import static android.view.flags.Flags.toolkitSetFrameRateReadOnly;
import static android.view.flags.Flags.viewVelocityApi;
import static android.view.inputmethod.Flags.FLAG_HOME_SCREEN_HANDWRITING_DELEGATOR;
@@ -2309,6 +2310,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET;
    private static boolean sToolkitSetFrameRateReadOnlyFlagValue;
    private static boolean sToolkitMetricsForFrameRateDecisionFlagValue;
    static {
        EMPTY_STATE_SET = StateSet.get(0);
@@ -2393,6 +2395,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                        | StateSet.VIEW_STATE_PRESSED);
        sToolkitSetFrameRateReadOnlyFlagValue = toolkitSetFrameRateReadOnly();
        sToolkitMetricsForFrameRateDecisionFlagValue = toolkitMetricsForFrameRateDecision();
    }
    /**
@@ -33084,11 +33087,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    private void votePreferredFrameRate() {
        // use toolkitSetFrameRate flag to gate the change
        if (sToolkitSetFrameRateReadOnlyFlagValue) {
        ViewRootImpl viewRootImpl = getViewRootImpl();
        float sizePercentage = getSizePercentage();
        int frameRateCateogry = calculateFrameRateCategory(sizePercentage);
        if (viewRootImpl != null && sizePercentage > 0) {
            if (sToolkitSetFrameRateReadOnlyFlagValue) {
                if (mPreferredFrameRate < 0) {
                    if (mPreferredFrameRate == REQUESTED_FRAME_RATE_CATEGORY_NO_PREFERENCE) {
                        frameRateCateogry = FRAME_RATE_CATEGORY_NO_PREFERENCE;
@@ -33104,6 +33107,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                }
                viewRootImpl.votePreferredFrameRateCategory(frameRateCateogry);
            }
            if (sToolkitMetricsForFrameRateDecisionFlagValue) {
                viewRootImpl.recordViewPercentage(sizePercentage);
            }
        }
    }
+15 −0
Original line number Diff line number Diff line
@@ -827,6 +827,8 @@ public final class ViewRootImpl implements ViewParent,
    private boolean mInsetsAnimationRunning;

    private long mPreviousFrameDrawnTime = -1;
    // The largest view size percentage to the display size. Used on trace to collect metric.
    private float mLargestChildPercentage = 0.0f;

    /**
     * The resolved pointer icon type requested by this window.
@@ -1066,6 +1068,7 @@ public final class ViewRootImpl implements ViewParent,

    private String mTag = TAG;
    private String mFpsTraceName;
    private String mLargestViewTraceName;

    private static boolean sToolkitSetFrameRateReadOnlyFlagValue;
    private static boolean sToolkitMetricsForFrameRateDecisionFlagValue;
@@ -1317,6 +1320,7 @@ public final class ViewRootImpl implements ViewParent,
                attrs = mWindowAttributes;
                setTag();
                mFpsTraceName = "FPS of " + getTitle();
                mLargestViewTraceName = "Largest view percentage(per hundred) of " + getTitle();

                if (DEBUG_KEEP_SCREEN_ON && (mClientWindowLayoutFlags
                        & WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) != 0
@@ -4738,6 +4742,10 @@ public final class ViewRootImpl implements ViewParent,
        long fps = NANOS_PER_SEC / timeDiff;
        Trace.setCounter(mFpsTraceName, fps);
        mPreviousFrameDrawnTime = expectedDrawnTime;

        long percentage = (long) (mLargestChildPercentage * 100);
        Trace.setCounter(mLargestViewTraceName, percentage);
        mLargestChildPercentage = 0.0f;
    }

    private void reportDrawFinished(@Nullable Transaction t, int seqId) {
@@ -5058,6 +5066,7 @@ public final class ViewRootImpl implements ViewParent,
        if (DEBUG_FPS) {
            trackFPS();
        }

        if (sToolkitMetricsForFrameRateDecisionFlagValue) {
            collectFrameRateDecisionMetrics();
        }
@@ -12261,4 +12270,10 @@ public final class ViewRootImpl implements ViewParent,
    void setBackKeyCallbackForWindowlessWindow(@NonNull Predicate<KeyEvent> callback) {
        mWindowlessBackKeyCallback = callback;
    }

    void recordViewPercentage(float percentage) {
        if (!Trace.isEnabled()) return;
        // Record the largest view of percentage to the display size.
        mLargestChildPercentage = Math.max(percentage, mLargestChildPercentage);
    }
}