From 7fcf9d0df3d851e583e1ece3fd0d9336dd9631aa Mon Sep 17 00:00:00 2001 From: Gopinath Date: Wed, 21 Sep 2016 15:55:29 -0700 Subject: Add parser to track the latency info printed from sysui Bug 31629439 Change-Id: I86627a8da8ae95acfb1bcf0d1369330dc5cb7a5c --- src/com/android/loganalysis/item/LatencyItem.java | 43 +++++++++++++++ .../loganalysis/parser/EventsLogParser.java | 64 ++++++++++++++++------ 2 files changed, 90 insertions(+), 17 deletions(-) create mode 100644 src/com/android/loganalysis/item/LatencyItem.java (limited to 'src') diff --git a/src/com/android/loganalysis/item/LatencyItem.java b/src/com/android/loganalysis/item/LatencyItem.java new file mode 100644 index 0000000..66b6b33 --- /dev/null +++ b/src/com/android/loganalysis/item/LatencyItem.java @@ -0,0 +1,43 @@ +package com.android.loganalysis.item; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +/** + * An {@link IItem} used to LatencyInfo. + */ +public class LatencyItem extends GenericItem { + + /** Constant for JSON output */ + public static final String ACTION_ID = "ACTION_ID"; + /** Constant for JSON output */ + public static final String DELAY = "DELAY"; + /** Constant for JSON output */ + + private static final Set ATTRIBUTES = new HashSet(Arrays.asList( + ACTION_ID, DELAY)); + + /** + * The constructor for {@link LatencyItem}. + */ + public LatencyItem() { + super(ATTRIBUTES); + } + + public int getActionId() { + return (int) getAttribute(ACTION_ID); + } + + public void setActionId(int actionId) { + setAttribute(ACTION_ID, actionId); + } + + public long getDelay() { + return (long) getAttribute(DELAY); + } + + public void setDelay(long delay) { + setAttribute(DELAY, delay); + } +} diff --git a/src/com/android/loganalysis/parser/EventsLogParser.java b/src/com/android/loganalysis/parser/EventsLogParser.java index 068feeb..a15abf8 100644 --- a/src/com/android/loganalysis/parser/EventsLogParser.java +++ b/src/com/android/loganalysis/parser/EventsLogParser.java @@ -17,10 +17,11 @@ package com.android.loganalysis.parser; import com.android.loganalysis.item.IItem; +import com.android.loganalysis.item.LatencyItem; import com.android.loganalysis.item.TransitionDelayItem; -import java.io.IOException; import java.io.BufferedReader; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; @@ -31,24 +32,31 @@ import java.util.regex.Pattern; */ public class EventsLogParser implements IParser { + // 08-21 17:53:53.876 1053 2135 + private static final String EVENTS_PREFIX = "^\\d{2}-\\d{2} \\d{2}:\\d{2}" + + ":\\d{2}.\\d{3}\\s+\\d+\\s+\\d+ "; // 08-21 17:53:53.876 1053 2135 I am_restart_activity: // [0,188098346,127,com.google.android.gm/.ConversationListActivityGmail] - private static final Pattern ACTIVITY_RESTART = Pattern.compile("^\\d{2}-\\d{2} \\d{2}:\\d{2}" - + ":\\d{2}.\\d{3}\\s+\\d+\\s+\\d+ I am_restart_activity: " - + "\\[\\d+\\,\\d+\\,\\d+\\,(?.*)\\]$"); - // 08-21 17:57:15.363 1053 2095 I am_resume_activity: + private static final Pattern ACTIVITY_RESTART = Pattern.compile( + String.format("%s%s", EVENTS_PREFIX, "I am_restart_activity: " + + "\\[\\d+\\,\\d+\\,\\d+\\,(?.*)\\]$")); + // 08-21 17:53:53.876 1053 2135 I am_resume_activity: // [0,228277756,132,com.google.android.gm/.ConversationListActivityGmail] - private static final Pattern ACTIVITY_RESUME = Pattern.compile("^\\d{2}-\\d{2} \\d{2}:\\d{2}" - + ":\\d{2}.\\d{3}\\s+\\d+\\s+\\d+ I am_resume_activity: " - + "\\[\\d+\\,\\d+\\,\\d+\\,(?.*)\\]$"); - // 08-21 17:53:53.893 1053 1115 I sysui_action: [321,74] - private static final Pattern STARTING_WINDOW_DELAY = Pattern.compile("^\\d{2}-\\d{2} \\d{2}:" - + "\\d{2}:\\d{2}.\\d{3}\\s+\\d+\\s+\\d+ I sysui_action: \\[321,(?.*)\\]$"); - // 08-21 17:54:16.672 1053 1115 I sysui_action: [319,99] - private static final Pattern TRANSITION_DELAY = Pattern - .compile("^\\d{2}-\\d{2} \\d{2}:" - + "\\d{2}:\\d{2}.\\d{3}\\s+\\d+\\s+\\d+ I sysui_action: \\[319," - + "(?.*)\\]$"); + private static final Pattern ACTIVITY_RESUME = Pattern.compile( + String.format("%s%s", EVENTS_PREFIX, "I am_resume_activity: " + + "\\[\\d+\\,\\d+\\,\\d+\\,(?.*)\\]$")); + // 08-21 17:53:53.876 1053 2135 I sysui_action: [321,74] + private static final Pattern STARTING_WINDOW_DELAY = Pattern.compile( + String.format("%s%s", EVENTS_PREFIX, "I sysui_action: \\[321," + + "(?.*)\\]$")); + // 08-21 17:53:53.876 1053 2135 I sysui_action: [319,99] + private static final Pattern TRANSITION_DELAY = Pattern.compile( + String.format("%s%s", EVENTS_PREFIX, "I sysui_action: \\[319," + + "(?.*)\\]$")); + // 08-21 17:53:53.876 1053 2135 I sysui_latency: [1,50] + private static final Pattern ACTION_LATENCY = Pattern.compile( + String.format("%s%s", EVENTS_PREFIX, "I sysui_latency: \\[(?.*)," + + "(?.*)\\]$")); @Override public IItem parse(List lines) { @@ -71,7 +79,7 @@ public class EventsLogParser implements IParser { boolean isRecentStartWindowDelay = false; while ((line = input.readLine()) != null) { Matcher match = null; - if (((match = matches(ACTIVITY_RESTART, line))) != null || + if ((match = matches(ACTIVITY_RESTART, line)) != null || ((match = matches(ACTIVITY_RESUME, line)) != null)) { componentNameStack.add(match.group("componentname")); isRecentStartWindowDelay = false; @@ -97,6 +105,28 @@ public class EventsLogParser implements IParser { return transitionDelayItems; } + /** + * Method to parse the latency information from the events log + * + * @param input + * @return + * @throws IOException + */ + public List parseLatencyInfo(BufferedReader input) throws IOException { + List latencyItems = new ArrayList(); + String line; + while ((line = input.readLine()) != null) { + Matcher match = null; + if (((match = matches(ACTION_LATENCY, line))) != null) { + LatencyItem latencyItem = new LatencyItem(); + latencyItem.setActionId(Integer.parseInt(match.group("action"))); + latencyItem.setDelay(Long.parseLong(match.group("delay"))); + latencyItems.add(latencyItem); + } + } + return latencyItems; + } + /** * Checks whether {@code line} matches the given {@link Pattern}. * -- cgit v1.2.3