Update JankTestHelper to track frame percentile metrics.

Change-Id: I0b0808d2fe8f9a74605bd680004ac6457206408f
diff --git a/src/android/support/test/jank/GfxMonitor.java b/src/android/support/test/jank/GfxMonitor.java
index f60c5d1..71ede73 100644
--- a/src/android/support/test/jank/GfxMonitor.java
+++ b/src/android/support/test/jank/GfxMonitor.java
@@ -40,4 +40,10 @@
     public static final String KEY_MAX_SLOW_BITMAP_UPLOADS = "gfx-max-slow-bitmap-uploads";
     public static final String KEY_AVG_SLOW_DRAW = "gfx-avg-slow-draw";
     public static final String KEY_MAX_SLOW_DRAW = "gfx-max-slow-draw";
+    public static final String KEY_AVG_FRAME_TIME_90TH_PERCENTILE = "gfx-avg-frame-time-90";
+    public static final String KEY_MAX_FRAME_TIME_90TH_PERCENTILE = "gfx-max-frame-time-90";
+    public static final String KEY_AVG_FRAME_TIME_95TH_PERCENTILE = "gfx-avg-frame-time-95";
+    public static final String KEY_MAX_FRAME_TIME_95TH_PERCENTILE = "gfx-max-frame-time-95";
+    public static final String KEY_AVG_FRAME_TIME_99TH_PERCENTILE = "gfx-avg-frame-time-99";
+    public static final String KEY_MAX_FRAME_TIME_99TH_PERCENTILE = "gfx-max-frame-time-99";
 }
diff --git a/src/android/support/test/jank/internal/GfxMonitorImpl.java b/src/android/support/test/jank/internal/GfxMonitorImpl.java
index 0878847..bc1abd5 100644
--- a/src/android/support/test/jank/internal/GfxMonitorImpl.java
+++ b/src/android/support/test/jank/internal/GfxMonitorImpl.java
@@ -55,6 +55,12 @@
             Pattern.compile("\\s*Number Slow bitmap uploads: (\\d+)");
     private static final Pattern SLOW_DRAW_PATTERN =
             Pattern.compile("\\s*Number Slow draw: (\\d+)");
+    private static final Pattern FRAME_TIME_90TH_PERCENTILE_PATTERN =
+            Pattern.compile("\\s*90th percentile: (\\d+)ms");
+    private static final Pattern FRAME_TIME_95TH_PERCENTILE_PATTERN =
+            Pattern.compile("\\s*95th percentile: (\\d+)ms");
+    private static final Pattern FRAME_TIME_99TH_PERCENTILE_PATTERN =
+            Pattern.compile("\\s*99th percentile: (\\d+)ms");
 
     // Used to invoke dumpsys gfxinfo
     private UiAutomation mUiAutomation;
@@ -67,6 +73,9 @@
     private List<Integer> slowUiThread = new ArrayList<Integer>();
     private List<Integer> slowBitmapUploads = new ArrayList<Integer>();
     private List<Integer> slowDraw = new ArrayList<Integer>();
+    private List<Integer> frameTime90thPercentile = new ArrayList<Integer>();
+    private List<Integer> frameTime95thPercentile = new ArrayList<Integer>();
+    private List<Integer> frameTime99thPercentile = new ArrayList<Integer>();
 
 
     public GfxMonitorImpl(UiAutomation automation, String process) {
@@ -108,6 +117,9 @@
         // Frame stats:
         //   Total frames rendered: ###
         //   Janky frames: ### (##.##%)
+        //   90th percentile: ##ms
+        //   95th percentile: ##ms
+        //   99th percentile: ##ms
         //    Number Missed Vsync: #
         //    Number High input latency: #
         //    Number Slow UI thread: #
@@ -127,6 +139,24 @@
         }
         jankyFrames.add(Integer.parseInt(part));
 
+        // Get 90th percentile
+        if ((part = getMatchGroup(stream.readLine(), FRAME_TIME_90TH_PERCENTILE_PATTERN, 1)) == null) {
+            Assert.fail("Failed to parse 90th percentile");
+        }
+        frameTime90thPercentile.add(Integer.parseInt(part));
+
+        // Get 95th percentile
+        if ((part = getMatchGroup(stream.readLine(), FRAME_TIME_95TH_PERCENTILE_PATTERN, 1)) == null) {
+            Assert.fail("Failed to parse 95th percentile");
+        }
+        frameTime95thPercentile.add(Integer.parseInt(part));
+
+        // Get 99th percentile
+        if ((part = getMatchGroup(stream.readLine(), FRAME_TIME_99TH_PERCENTILE_PATTERN, 1)) == null) {
+            Assert.fail("Failed to parse 99th percentile");
+        }
+        frameTime99thPercentile.add(Integer.parseInt(part));
+
         // Get Missed Vsync
         if ((part = getMatchGroup(stream.readLine(), MISSED_VSYNC_PATTERN, 1)) == null) {
             Assert.fail("Failed to parse number missed vsync");
@@ -168,6 +198,20 @@
                 MetricsHelper.computeAverageInt(jankyFrames));
         metrics.putInt(GfxMonitor.KEY_MAX_NUM_JANKY, Collections.max(jankyFrames));
 
+        // Store average and max percentile frame times
+        metrics.putDouble(GfxMonitor.KEY_AVG_FRAME_TIME_90TH_PERCENTILE,
+                MetricsHelper.computeAverageInt(frameTime90thPercentile));
+        metrics.putInt(GfxMonitor.KEY_MAX_FRAME_TIME_90TH_PERCENTILE,
+                Collections.max(frameTime90thPercentile));
+        metrics.putDouble(GfxMonitor.KEY_AVG_FRAME_TIME_95TH_PERCENTILE,
+                MetricsHelper.computeAverageInt(frameTime95thPercentile));
+        metrics.putInt(GfxMonitor.KEY_MAX_FRAME_TIME_95TH_PERCENTILE,
+                Collections.max(frameTime95thPercentile));
+        metrics.putDouble(GfxMonitor.KEY_AVG_FRAME_TIME_99TH_PERCENTILE,
+                MetricsHelper.computeAverageInt(frameTime99thPercentile));
+        metrics.putInt(GfxMonitor.KEY_MAX_FRAME_TIME_99TH_PERCENTILE,
+                Collections.max(frameTime99thPercentile));
+
         // Store average and max missed vsync
         metrics.putDouble(GfxMonitor.KEY_AVG_MISSED_VSYNC,
                 MetricsHelper.computeAverageInt(missedVsync));