From 56ced067cc6c72a917d8e4846cd54df0657d1d7b Mon Sep 17 00:00:00 2001 From: Michael Rosenfeld Date: Mon, 15 May 2017 19:22:01 -0700 Subject: Add new parsed fields to the compact meminfo parser. * Free RAM, Total ZRAM, Swap Free ZRAM, and Tuning Level Test: CompactMemInfoParserTest Change-Id: Id95bae62f98119f04a9f0e5046ec3f28760921ef --- .../loganalysis/item/CompactMemInfoItem.java | 54 +++++++++++- .../loganalysis/parser/CompactMemInfoParser.java | 46 ++++++++-- .../parser/CompactMemInfoParserTest.java | 97 +++++++++++++++++----- 3 files changed, 166 insertions(+), 31 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> mPids = new HashMap>(); + 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/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 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/tests/src/com/android/loganalysis/parser/CompactMemInfoParserTest.java b/tests/src/com/android/loganalysis/parser/CompactMemInfoParserTest.java index 32119bd..ed4b39b 100644 --- a/tests/src/com/android/loganalysis/parser/CompactMemInfoParserTest.java +++ b/tests/src/com/android/loganalysis/parser/CompactMemInfoParserTest.java @@ -74,14 +74,49 @@ public class CompactMemInfoParserTest extends TestCase { assertEquals(1005, item.getLostRam()); } + public void testSingleRamLine() { + List input = Arrays.asList("ram,2866484,1221694,1112777"); + CompactMemInfoItem item = new CompactMemInfoParser().parse(input); + assertEquals(1221694, item.getFreeRam()); + } + + public void testSingleZramLine() { + List input = Arrays.asList("zram,5800,520908,491632"); + CompactMemInfoItem item = new CompactMemInfoParser().parse(input); + assertEquals(5800, item.getTotalZram()); + assertEquals(491632, item.getFreeSwapZram()); + } + + public void testSingleTuningLine() { + // With specific configuration + List input1 = Arrays.asList("tuning,192,512,322560,high-end-gfx"); + CompactMemInfoItem item1 = new CompactMemInfoParser().parse(input1); + assertEquals(322560, item1.getTuningLevel()); + // Without specific configuration + List input2 = Arrays.asList("tuning,193,513,322561"); + CompactMemInfoItem item2 = new CompactMemInfoParser().parse(input2); + assertEquals(322561, item2.getTuningLevel()); + } + public void testSomeMalformedLines() { - List input = Arrays.asList( - "proc,cached,com.google.android.youtube,a,b,e", - "proc,cached,com.google.android.youtube,2964,c,e", - "proc,cached,com.google.android.youtube,2964,e", - "proc,cached,com.google.android.youtube,2964,19345,a,e", - "lostram,a,1000", - "lostram,1000,a"); + List input = + Arrays.asList( + "proc,cached,com.google.android.youtube,a,b,e", + "proc,cached,com.google.android.youtube,2964,c,e", + "proc,cached,com.google.android.youtube,2964,e", + "proc,cached,com.google.android.youtube,2964,19345,a,e", + "lostram,a,1000", + "lostram,1000,a", + "ram,123,345", + "ram,123,345,abc", + "ram,123,345,456,678", + "ram,123,345,456,abc", + "zram,123,345", + "zram,123,345,abc", + "zram,123,345,456,678", + "zram,123,345,456,abc", + "tuning,123,345", + "tuning,123,345,abc"); CompactMemInfoItem item = new CompactMemInfoParser().parse(input); @@ -89,13 +124,17 @@ public class CompactMemInfoParserTest extends TestCase { } public void testMultipleLines() { - List input = Arrays.asList( - "proc,cached,com.google.android.youtube,2964,19345,123,e", - "proc,cached,com.google.android.apps.plus,2877,9604,N/A,e", - "proc,cached,com.google.android.apps.magazines,2009,20111,N/A,e", - "proc,cached,com.google.android.apps.walletnfcrel,10790,11164,100,e", - "proc,cached,com.google.android.incallui,3410,9491,N/A,e", - "lostram,1005"); + List input = + Arrays.asList( + "proc,cached,com.google.android.youtube,2964,19345,123,e", + "proc,cached,com.google.android.apps.plus,2877,9604,N/A,e", + "proc,cached,com.google.android.apps.magazines,2009,20111,N/A,e", + "proc,cached,com.google.android.apps.walletnfcrel,10790,11164,100,e", + "proc,cached,com.google.android.incallui,3410,9491,N/A,e", + "lostram,1005", + "ram,2866484,1221694,1112777", + "zram,5800,520908,491632", + "tuning,193,513,322561"); CompactMemInfoItem item = new CompactMemInfoParser().parse(input); @@ -107,6 +146,10 @@ public class CompactMemInfoParserTest extends TestCase { assertEquals(false, item.hasActivities(2964)); assertEquals(1005, item.getLostRam()); + assertEquals(1221694, item.getFreeRam()); + assertEquals(5800, item.getTotalZram()); + assertEquals(491632, item.getFreeSwapZram()); + assertEquals(322561, item.getTuningLevel()); } public void testSkipNonProcLines() { @@ -132,15 +175,19 @@ public class CompactMemInfoParserTest extends TestCase { } public void testJson() throws JSONException { - List input = Arrays.asList( - "oom,cached,141357", - "proc,cached,com.google.android.youtube,2964,19345,N/A,e", - "proc,cached,com.google.android.apps.plus,2877,9604,50,e", - "proc,cached,com.google.android.apps.magazines,2009,20111,100,e", - "proc,cached,com.google.android.apps.walletnfcrel,10790,11164,0,e", - "proc,cached,com.google.android.incallui,3410,9491,500,e", - "lostram,1005", - "cat,Native,63169"); + List input = + Arrays.asList( + "oom,cached,141357", + "proc,cached,com.google.android.youtube,2964,19345,N/A,e", + "proc,cached,com.google.android.apps.plus,2877,9604,50,e", + "proc,cached,com.google.android.apps.magazines,2009,20111,100,e", + "proc,cached,com.google.android.apps.walletnfcrel,10790,11164,0,e", + "proc,cached,com.google.android.incallui,3410,9491,500,e", + "lostram,1005", + "ram,2866484,1221694,1112777", + "zram,5800,520908,491632", + "tuning,193,513,322561", + "cat,Native,63169"); CompactMemInfoItem item = new CompactMemInfoParser().parse(input); JSONObject json = item.toJson(); @@ -150,5 +197,9 @@ public class CompactMemInfoParserTest extends TestCase { assertEquals(5, processes.length()); assertEquals(1005, (long)json.get("lostRam")); + assertEquals(1221694, (long) json.get("freeRam")); + assertEquals(5800, (long) json.get("totalZram")); + assertEquals(491632, (long) json.get("freeSwapZram")); + assertEquals(322561, (long) json.get("tuningLevel")); } } -- cgit v1.2.3