Change hwui jank detection to use deadline & gpu completion (1/2)

- Use GPU finish time as well as actual deadline to determine jank
rate.
- Use dynamic interval to adjust for 60/90hz switching
- Move frame metrics reporting into JankTracker to adjust the
deadline communicated to the app when in stuffing scenario.
- Adjust double-stuffing detection to be a bit more readable.

Test: GraphicsStatsValidationTest.java
Test: adb shell dumpsys gfxinfo
Test: FrameMetricsListenerTest
Test: Log output of FrameMetricsObserver
Bug: 169858044
Change-Id: I3a6b8ed163e2cf9cf2b67667110340ebe35f98a1
diff --git a/libs/hwui/ProfileData.cpp b/libs/hwui/ProfileData.cpp
index a8e36e3..dd84396 100644
--- a/libs/hwui/ProfileData.cpp
+++ b/libs/hwui/ProfileData.cpp
@@ -24,7 +24,8 @@
 
 static const char* JANK_TYPE_NAMES[] = {
         "Missed Vsync",        "High input latency",       "Slow UI thread",
-        "Slow bitmap uploads", "Slow issue draw commands", "Frame deadline missed"};
+        "Slow bitmap uploads", "Slow issue draw commands", "Frame deadline missed",
+        "Frame deadline missed (legacy)"};
 
 // The bucketing algorithm controls so to speak
 // If a frame is <= to this it goes in bucket 0
@@ -94,6 +95,8 @@
     }
     mJankFrameCount >>= divider;
     mJankFrameCount += other.mJankFrameCount;
+    mJankLegacyFrameCount >>= divider;
+    mJankLegacyFrameCount += other.mJankLegacyFrameCount;
     mTotalFrameCount >>= divider;
     mTotalFrameCount += other.mTotalFrameCount;
     if (mStatStartTime > other.mStatStartTime || mStatStartTime == 0) {
@@ -112,6 +115,9 @@
     dprintf(fd, "\nJanky frames: %u (%.2f%%)", mJankFrameCount,
             mTotalFrameCount == 0 ? 0.0f
                                   : (float)mJankFrameCount / (float)mTotalFrameCount * 100.0f);
+    dprintf(fd, "\nJanky frames (legacy): %u (%.2f%%)", mJankLegacyFrameCount, mTotalFrameCount == 0
+            ? 0.0f
+            : (float)mJankLegacyFrameCount / (float)mTotalFrameCount * 100.0f);
     dprintf(fd, "\n50th percentile: %ums", findPercentile(50));
     dprintf(fd, "\n90th percentile: %ums", findPercentile(90));
     dprintf(fd, "\n95th percentile: %ums", findPercentile(95));
@@ -158,6 +164,7 @@
     mSlowFrameCounts.fill(0);
     mTotalFrameCount = 0;
     mJankFrameCount = 0;
+    mJankLegacyFrameCount = 0;
     mStatStartTime = systemTime(SYSTEM_TIME_MONOTONIC);
     mPipelineType = Properties::getRenderPipelineType();
 }