diff options
Diffstat (limited to 'src/com')
5 files changed, 147 insertions, 21 deletions
diff --git a/src/com/android/loganalysis/item/CompactMemInfoItem.java b/src/com/android/loganalysis/item/CompactMemInfoItem.java index 9c52b88..cf9bff9 100644 --- a/src/com/android/loganalysis/item/CompactMemInfoItem.java +++ b/src/com/android/loganalysis/item/CompactMemInfoItem.java @@ -37,6 +37,10 @@ public class CompactMemInfoItem implements IItem { public static final String ACTIVITIES_JSON_KEY = "activities"; public static final String PROCESSES_JSON_KEY = "processes"; public static final String LOST_RAM_JSON_KEY = "lostRam"; + public static final String TOTAL_ZRAM_JSON_KEY = "totalZram"; + public static final String FREE_SWAP_ZRAM_JSON_KEY = "freeSwapZram"; + public static final String FREE_RAM_JSON_KEY = "freeRam"; + public static final String TUNING_LEVEL_JSON_KEY = "tuningLevel"; /** Constants for attributes HashMap */ private static final String NAME_ATTR_KEY = "name"; private static final String PSS_ATTR_KEY = "pss"; @@ -45,7 +49,11 @@ public class CompactMemInfoItem implements IItem { private static final String ACTIVITIES_ATTR_KEY = "activities"; private Map<Integer, Map<String, Object>> mPids = new HashMap<Integer, Map<String, Object>>(); + private long mFreeRam; + private long mFreeSwapZram; private long mLostRam; + private long mTotalZram; + private long mTuningLevel; @Override public IItem merge(IItem other) throws ConflictingItemException { @@ -78,8 +86,12 @@ public class CompactMemInfoItem implements IItem { } try { object.put(PROCESSES_JSON_KEY, processes); - // Add the lost RAM field + // Add the additional non-process field object.put(LOST_RAM_JSON_KEY, getLostRam()); + object.put(TOTAL_ZRAM_JSON_KEY, getTotalZram()); + object.put(FREE_SWAP_ZRAM_JSON_KEY, getFreeSwapZram()); + object.put(FREE_RAM_JSON_KEY, getFreeRam()); + object.put(TUNING_LEVEL_JSON_KEY, getTuningLevel()); } catch (JSONException e) { // ignore } @@ -161,4 +173,44 @@ public class CompactMemInfoItem implements IItem { public long getLostRam() { return mLostRam; } + + /** Sets the free RAM field */ + public void setFreeRam(long freeRam) { + mFreeRam = freeRam; + } + + /** Returns the free RAM field */ + public long getFreeRam() { + return mFreeRam; + } + + /** Sets the total ZRAM field */ + public void setTotalZram(long totalZram) { + mTotalZram = totalZram; + } + + /** Returns the total ZRAM field */ + public long getTotalZram() { + return mTotalZram; + } + + /** Sets the free swap ZRAM field */ + public void setFreeSwapZram(long freeSwapZram) { + mFreeSwapZram = freeSwapZram; + } + + /** Returns the free swap ZRAM field */ + public long getFreeSwapZram() { + return mFreeSwapZram; + } + + /** Sets the tuning level field */ + public void setTuningLevel(long tuningLevel) { + mTuningLevel = tuningLevel; + } + + /** Returns the tuning level field */ + public long getTuningLevel() { + return mTuningLevel; + } } diff --git a/src/com/android/loganalysis/item/DmesgStageInfoItem.java b/src/com/android/loganalysis/item/DmesgStageInfoItem.java index a5bfd39..a446090 100644 --- a/src/com/android/loganalysis/item/DmesgStageInfoItem.java +++ b/src/com/android/loganalysis/item/DmesgStageInfoItem.java @@ -30,9 +30,11 @@ public class DmesgStageInfoItem extends GenericItem { public static final String STAGE_NAME = "STAGE_NAME"; /** Constant for JSON output */ public static final String STAGE_START_TIME = "STAGE_START_TIME"; + /** Constant for JSON output */ + public static final String STAGE_DURATION = "STAGE_DURATION"; private static final Set<String> ATTRIBUTES = new HashSet<String>(Arrays.asList( - STAGE_NAME, STAGE_START_TIME)); + STAGE_NAME, STAGE_START_TIME, STAGE_DURATION)); /** * The constructor for {@link DmesgStageInfoItem}. @@ -44,10 +46,11 @@ public class DmesgStageInfoItem extends GenericItem { /** * The constructor for {@link DmesgStageInfoItem}. */ - public DmesgStageInfoItem(String name, Long startTime) { + public DmesgStageInfoItem(String name, Long startTime, Long duration) { super(ATTRIBUTES); setAttribute(STAGE_NAME, name); setAttribute(STAGE_START_TIME, startTime); + setAttribute(STAGE_DURATION, duration); } /** @@ -78,10 +81,24 @@ public class DmesgStageInfoItem extends GenericItem { setAttribute(STAGE_START_TIME, startTime); } + /** + * Get the duration in msecs + */ + public Long getDuration() { + return (Long) getAttribute(STAGE_DURATION); + } + + /** + * Set the duration in msecs + */ + public void setDuration(Long duration) { + setAttribute(STAGE_DURATION, duration); + } + @Override public String toString() { return "StageInfoItem [getStageName()=" + getStageName() + ", getStartTime()=" - + getStartTime() + "]"; + + getStartTime() + ", getDuration()=" + getDuration() + "]"; } } diff --git a/src/com/android/loganalysis/parser/CompactMemInfoParser.java b/src/com/android/loganalysis/parser/CompactMemInfoParser.java index 788cd8b..263cdf1 100644 --- a/src/com/android/loganalysis/parser/CompactMemInfoParser.java +++ b/src/com/android/loganalysis/parser/CompactMemInfoParser.java @@ -37,10 +37,12 @@ import java.util.regex.Pattern; * */ public class CompactMemInfoParser implements IParser { - private static final Pattern PROC_PREFIX = Pattern.compile( - "proc,(\\w+),([a-zA-Z_0-9\\.]+),(\\d+),(\\d+),((\\S+),)?(.*)"); - private static final Pattern LOST_RAM_PREFIX = Pattern.compile( - "lostram,(.+)"); + private static final Pattern PROC_PATTERN = + Pattern.compile("proc,(\\w+),([a-zA-Z_0-9\\.]+),(\\d+),(\\d+),((\\S+),)?(.*)"); + private static final Pattern LOST_RAM_PATTERN = Pattern.compile("lostram,(\\d+)"); + private static final Pattern RAM_PATTERN = Pattern.compile("ram,(\\d+),(\\d+),(\\d+)"); + private static final Pattern ZRAM_PATTERN = Pattern.compile("zram,(\\d+),(\\d+),(\\d+)"); + private static final Pattern TUNING_PATTERN = Pattern.compile("tuning,(\\d+),(\\d+),(\\d+).*"); /** * Parse compact meminfo log. Output a CompactMemInfoItem which contains @@ -50,7 +52,7 @@ public class CompactMemInfoParser implements IParser { public CompactMemInfoItem parse(List<String> lines) { CompactMemInfoItem item = new CompactMemInfoItem(); for (String line : lines) { - Matcher m = PROC_PREFIX.matcher(line); + Matcher m = PROC_PATTERN.matcher(line); if (m.matches()) { String type = m.group(1); String name = m.group(2); @@ -69,9 +71,8 @@ public class CompactMemInfoParser implements IParser { } } - m = LOST_RAM_PREFIX.matcher(line); + m = LOST_RAM_PATTERN.matcher(line); if (m.matches()) { - String name = "Lost RAM"; try { long lostRam = Long.parseLong(m.group(1)); item.setLostRam(lostRam); @@ -80,6 +81,37 @@ public class CompactMemInfoParser implements IParser { // ignore exception } } + + m = RAM_PATTERN.matcher(line); + if (m.matches()) { + try { + item.setFreeRam(Long.parseLong(m.group(2))); + continue; + } catch (NumberFormatException nfe) { + // ignore exception + } + } + + m = ZRAM_PATTERN.matcher(line); + if (m.matches()) { + try { + item.setTotalZram(Long.parseLong(m.group(1))); + item.setFreeSwapZram(Long.parseLong(m.group(3))); + continue; + } catch (NumberFormatException nfe) { + // ignore exception + } + } + + m = TUNING_PATTERN.matcher(line); + if (m.matches()) { + try { + item.setTuningLevel(Long.parseLong(m.group(3))); + continue; + } catch (NumberFormatException nfe) { + // ignore exception + } + } } return item; } diff --git a/src/com/android/loganalysis/parser/DmesgParser.java b/src/com/android/loganalysis/parser/DmesgParser.java index ba802cf..ce3d389 100644 --- a/src/com/android/loganalysis/parser/DmesgParser.java +++ b/src/com/android/loganalysis/parser/DmesgParser.java @@ -40,15 +40,22 @@ public class DmesgParser implements IParser { private static final String TIMESTAMP = "TIMESTAMP"; private static final String STAGE = "STAGE"; private static final String ACTION = "ACTION"; + private static final String DURATION = "DURATION"; + private static final String UEVENTD = "ueventd"; + // Matches: [ 14.822691] init: private static final String SERVICE_PREFIX = String.format("^\\[\\s+(?<%s>.*)\\] init:\\s+", TIMESTAMP); + // Matches: [ 3.791635] ueventd: + private static final String UEVENTD_PREFIX = String.format("^\\[\\s+(?<%s>.*)\\] ueventd:\\s+", + TIMESTAMP); + // Matches: starting service 'ueventd'... private static final String START_SERVICE_SUFFIX = String.format("starting service " + "\\'(?<%s>.*)\\'...", SERVICENAME); // Matches: Service 'ueventd' (pid 439) exited with status 0 private static final String EXIT_SERVICE_SUFFIX = String.format("Service \\'(?<%s>.*)\\'\\s+" - + "\\((?<PID>.*)\\) exited with status 0", SERVICENAME); + + "\\((?<PID>.*)\\) exited with status 0.*", SERVICENAME); private static final Pattern START_SERVICE = Pattern.compile( String.format("%s%s", SERVICE_PREFIX, START_SERVICE_SUFFIX)); @@ -65,15 +72,19 @@ public class DmesgParser implements IParser { String.format("%s%s", SERVICE_PREFIX, START_STAGE_PREFIX)); // Matches: init: processing action (early-init) - // must not match: init: processing action (vold.decrypt=trigger_restart_framework) private static final String START_PROCESSING_ACTION_PREFIX = String.format( - "processing action \\((?<%s>[^=]+)\\)", ACTION); + "processing action \\((?<%s>.*)\\) from.*$", ACTION); // Matches: [ 14.942872] init: processing action (early-init) - // Does not match: [ 22.361049] init: processing action (persist.sys.usb.config=* boot) private static final Pattern START_PROCESSING_ACTION = Pattern.compile( String.format("%s%s", SERVICE_PREFIX, START_PROCESSING_ACTION_PREFIX)); + // Matches: [ 3.791635] ueventd: Coldboot took 0.695055 seconds + private static final String STAGE_SUFFIX= String.format( + "(?<%s>.*)\\s+took\\s+(?<%s>.*)\\s+seconds$", STAGE, DURATION); + private static final Pattern UEVENTD_STAGE_INFO = Pattern.compile( + String.format("%s%s", UEVENTD_PREFIX, STAGE_SUFFIX)); + private DmesgItem mDmesgItem = new DmesgItem(); @@ -166,7 +177,8 @@ public class DmesgParser implements IParser { /** * Parse init stages log from each {@code line} of dmesg log and - * store the stage name and start time in a {@link DmesgStageInfoItem} object + * store the stage name, start time and duration if available in a + * {@link DmesgStageInfoItem} object * * @param individual line of the dmesg log * @return {@code true}, if the {@code line} indicates start of a boot stage, @@ -183,6 +195,13 @@ public class DmesgParser implements IParser { mDmesgItem.addStageInfoItem(stageInfoItem); return true; } + if((match = matches(UEVENTD_STAGE_INFO, line)) != null) { + DmesgStageInfoItem stageInfoItem = new DmesgStageInfoItem(); + stageInfoItem.setStageName(String.format("%s_%s", UEVENTD, match.group(STAGE))); + stageInfoItem.setDuration((long) (Double.parseDouble( + match.group(DURATION)) * 1000)); + mDmesgItem.addStageInfoItem(stageInfoItem); + } return false; } diff --git a/src/com/android/loganalysis/parser/LogcatParser.java b/src/com/android/loganalysis/parser/LogcatParser.java index 96cd1c2..b32536d 100644 --- a/src/com/android/loganalysis/parser/LogcatParser.java +++ b/src/com/android/loganalysis/parser/LogcatParser.java @@ -54,12 +54,18 @@ public class LogcatParser implements IParser { /** * Match a single line of `logcat -v threadtime`, such as: - * 05-26 11:02:36.886 5689 5689 D AndroidRuntime: CheckJNI is OFF + * + * <pre>05-26 11:02:36.886 5689 5689 D AndroidRuntime: CheckJNI is OFF.</pre> */ - private static final Pattern THREADTIME_LINE = Pattern.compile( - "^(\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}.\\d{3})\\s+" + /* timestamp [1] */ - "(\\d+)\\s+(\\d+)\\s+([A-Z])\\s+" + /* pid/tid and log level [2-4] */ - "(.+?)\\s*: (.*)$" /* tag and message [5-6]*/); + private static final Pattern THREADTIME_LINE = + // UID was added to logcat. It could either be a number or a string. + Pattern.compile( + // timestamp[1] + "^(\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}.\\d{3})" + // pid/tid and log level [2-4] + + "(?:\\s+[0-9A-Za-z]+)?\\s+(\\d+)\\s+(\\d+)\\s+([A-Z])\\s+" + // tag and message [5-6] + + "(.+?)\\s*: (.*)$"); /** * Match a single line of `logcat -v time`, such as: |