diff options
author | Robert Sloan <varomodt@google.com> | 2016-09-02 18:39:06 -0700 |
---|---|---|
committer | Robert Sloan <varomodt@google.com> | 2016-09-09 13:43:23 -0700 |
commit | 2b4d5bf8ab7f4604dffcc1cdeebcfacb26bf1529 (patch) | |
tree | 798cd6637dac4b30e9b526aaf84b5b4a02ba6498 | |
parent | 7bf9a32b554dd3eaeec7b386a2f283b200dafb39 (diff) | |
download | platform_testing-2b4d5bf8ab7f4604dffcc1cdeebcfacb26bf1529.tar.gz |
Replaced toString of JankStat with JSON
BUG: 31266887
Change-Id: I61b0184d6607537e9343a4d3f329763c64fc17e8
-rw-r--r-- | libraries/aupt-lib/src/android/support/test/aupt/JankStat.java | 149 |
1 files changed, 102 insertions, 47 deletions
diff --git a/libraries/aupt-lib/src/android/support/test/aupt/JankStat.java b/libraries/aupt-lib/src/android/support/test/aupt/JankStat.java index 8c555bed5..dbef882de 100644 --- a/libraries/aupt-lib/src/android/support/test/aupt/JankStat.java +++ b/libraries/aupt-lib/src/android/support/test/aupt/JankStat.java @@ -23,6 +23,9 @@ import java.util.List; import java.util.regex.Pattern; import java.util.regex.Matcher; +import org.json.JSONObject; +import org.json.JSONException; + /** * This class is like a C-style struct that holds individual process information from the * dumpsys graphicsstats command. It also includes an enumeration, originally from the @@ -34,25 +37,64 @@ public class JankStat { // Patterns used for parsing dumpsys graphicsstats public enum StatPattern { - PACKAGE(Pattern.compile("\\s*Package: (.*)"), 1), - STATS_SINCE(Pattern.compile("\\s*Stats since: (\\d+)ns"), 1), - TOTAL_FRAMES(Pattern.compile("\\s*Total frames rendered: (\\d+)"), 1), - NUM_JANKY(Pattern.compile("\\s*Janky frames: (\\d+) (.*)"), 1), - FRAME_TIME_50TH(Pattern.compile("\\s*50th percentile: (\\d+)ms"), 1), - FRAME_TIME_90TH(Pattern.compile("\\s*90th percentile: (\\d+)ms"), 1), - FRAME_TIME_95TH(Pattern.compile("\\s*95th percentile: (\\d+)ms"), 1), - FRAME_TIME_99TH(Pattern.compile("\\s*99th percentile: (\\d+)ms"), 1), - SLOWEST_FRAMES_24H(Pattern.compile("\\s*Slowest frames over last 24h: (.*)"), 1), - NUM_MISSED_VSYNC(Pattern.compile("\\s*Number Missed Vsync: (\\d+)"), 1), - NUM_HIGH_INPUT_LATENCY(Pattern.compile("\\s*Number High input latency: (\\d+)"), 1), - NUM_SLOW_UI_THREAD(Pattern.compile("\\s*Number Slow UI thread: (\\d+)"), 1), - NUM_SLOW_BITMAP_UPLOADS(Pattern.compile("\\s*Number Slow bitmap uploads: (\\d+)"), 1), - NUM_SLOW_DRAW(Pattern.compile("\\s*Number Slow issue draw commands: (\\d+)"), 1); + PACKAGE("package", + Pattern.compile("\\s*Package: (.*)"), 1), + + STATS_SINCE("startTime", + Pattern.compile("\\s*Stats since: (\\d+)ns"), 1), + + TOTAL_FRAMES("frameCount", + Pattern.compile("\\s*Total frames rendered: (\\d+)"), 1), + + NUM_JANKY("jankyCount", + Pattern.compile("\\s*Janky frames: (\\d+) (.*)"), 1), + + FRAME_TIME_50TH("percentile50", + Pattern.compile("\\s*50th percentile: (\\d+)ms"), 1), + + FRAME_TIME_90TH("percentile90", + Pattern.compile("\\s*90th percentile: (\\d+)ms"), 1), + + FRAME_TIME_95TH("percentile95", + Pattern.compile("\\s*95th percentile: (\\d+)ms"), 1), + + FRAME_TIME_99TH("percentile99", + Pattern.compile("\\s*99th percentile: (\\d+)ms"), 1), + + SLOWEST_FRAMES_24H("slowestFramesToday", + Pattern.compile("\\s*Slowest frames over last 24h: (.*)"), 1), + + NUM_MISSED_VSYNC("missedVsyncCount", + Pattern.compile("\\s*Number Missed Vsync: (\\d+)"), 1), + + NUM_HIGH_INPUT_LATENCY("highLatencyCount", + Pattern.compile("\\s*Number High input latency: (\\d+)"), 1), + + NUM_SLOW_UI_THREAD("slowUIThreadCount", + Pattern.compile("\\s*Number Slow UI thread: (\\d+)"), 1), + NUM_SLOW_BITMAP_UPLOADS("slowBitmapUploadCount", + Pattern.compile("\\s*Number Slow bitmap uploads: (\\d+)"), 1), + + NUM_SLOW_DRAW("slowDrawCmdCount", + Pattern.compile("\\s*Number Slow issue draw commands: (\\d+)"), 1), + + AGGREGATE_COUNT("aggregateCount", null, 1); + + private String mName; private Pattern mParsePattern; private int mGroupIdx; - StatPattern(Pattern pattern, int idx) { + /** + * Constructs each pattern for parsing the statistics + * generated by `dumpsys graphicsstats` + * + * "name" is a unique JSON key for the field + * "pattern" is the regex for parsing out the field + * "idx" the match-index for the relevant field in that pattern + */ + StatPattern(String name, Pattern pattern, int idx) { + mName = name; mParsePattern = pattern; mGroupIdx = idx; } @@ -65,24 +107,27 @@ public class JankStat { } return ret; } + + String getName() { + return mName; + } } public String packageName; - public long statsSince; - public int totalFrames; - public int jankyFrames; - public int frameTime50th; - public int frameTime90th; - public int frameTime95th; - public int frameTime99th; + public Long statsSince; + public Integer totalFrames; + public Integer jankyFrames; + public Integer frameTime50th; + public Integer frameTime90th; + public Integer frameTime95th; + public Integer frameTime99th; public String slowestFrames24h; - public int numMissedVsync; - public int numHighLatency; - public int numSlowUiThread; - public int numSlowBitmap; - public int numSlowDraw; - - public int aggregateCount; + public Integer numMissedVsync; + public Integer numHighLatency; + public Integer numSlowUiThread; + public Integer numSlowBitmap; + public Integer numSlowDraw; + public Integer aggregateCount; public JankStat (String pkg, long since, int total, int janky, int ft50, int ft90, int ft95, int ft99, String slow24h, int vsync, int latency, int slowUi, int slowBmp, int slowDraw, @@ -101,7 +146,6 @@ public class JankStat { numSlowUiThread = slowUi; numSlowBitmap = slowBmp; numSlowDraw = slowDraw; - aggregateCount = aggCount; } @@ -123,26 +167,37 @@ public class JankStat { } /** - * Returns the jank stats similar to how they are presented in the shell + * Serialize this object into a JSONObject + */ + public JSONObject toJson () throws JSONException { + return new JSONObject(). + put(StatPattern.PACKAGE.getName(), packageName). + put(StatPattern.STATS_SINCE.getName(), statsSince). + put(StatPattern.TOTAL_FRAMES.getName(), totalFrames). + put(StatPattern.NUM_JANKY.getName(), new Float(getPercentJankyFrames())). + put(StatPattern.FRAME_TIME_50TH.getName(), frameTime50th). + put(StatPattern.FRAME_TIME_90TH.getName(), frameTime90th). + put(StatPattern.FRAME_TIME_95TH.getName(), frameTime95th). + put(StatPattern.FRAME_TIME_99TH.getName(), frameTime99th). + put(StatPattern.SLOWEST_FRAMES_24H.getName(), slowestFrames24h). + put(StatPattern.NUM_MISSED_VSYNC.getName(), numMissedVsync). + put(StatPattern.NUM_HIGH_INPUT_LATENCY.getName(), numHighLatency). + put(StatPattern.NUM_SLOW_UI_THREAD.getName(), numSlowUiThread). + put(StatPattern.NUM_SLOW_BITMAP_UPLOADS.getName(), numSlowBitmap). + put(StatPattern.NUM_SLOW_DRAW.getName(), numSlowDraw). + put(StatPattern.AGGREGATE_COUNT.getName(), aggregateCount); + } + + /** + * @{inheritDoc} */ @Override public String toString () { - String result = packageName + - "\nStats since: " + statsSince + - "\nTotal frames: " + totalFrames + - "\nJanky frames: " + jankyFrames + - "\n50th percentile: " + frameTime50th + - "\n90th percentile: " + frameTime90th + - "\n95th percentile: " + frameTime95th + - "\n99th percentile: " + frameTime99th + - "\nSlowest frames over last 24h: " + slowestFrames24h + - "\nNumber Missed Vsync: " + numMissedVsync + - "\nNumber High input latency: " + numHighLatency + - "\nNumber Slow UI thread: " + numSlowUiThread + - "\nNumber Slow bitmap uploads: " + numSlowBitmap + - "\nNumber Slow draw commands: " + numSlowDraw + - "\nAggregated stats count: " + aggregateCount; - return result; + try { + return toJson().toString(4); + } catch (JSONException e) { + throw new RuntimeException("Error serializing JankStat: " + e.toString()); + } } /** |