diff options
author | Michael Rosenfeld <mrosenfeld@google.com> | 2015-12-16 15:56:16 -0800 |
---|---|---|
committer | Michael Rosenfeld <mrosenfeld@google.com> | 2016-01-14 14:57:53 -0800 |
commit | a81b9db05d513c1284aed2a2802a193f2ec88b60 (patch) | |
tree | 50d4a865eab396418a90b2523b3a678ab456491d | |
parent | f19dfae757c834fefc56d7e28212692f9e45f0ad (diff) | |
download | loganalysis-a81b9db05d513c1284aed2a2802a193f2ec88b60.tar.gz |
Add swap memory to the compact memory info parser
Change-Id: I5f6bbf8ee41311ef7dfb3d60fd76c7d902c187f8
3 files changed, 54 insertions, 20 deletions
diff --git a/src/com/android/loganalysis/item/CompactMemInfoItem.java b/src/com/android/loganalysis/item/CompactMemInfoItem.java index fff79b9..9c52b88 100644 --- a/src/com/android/loganalysis/item/CompactMemInfoItem.java +++ b/src/com/android/loganalysis/item/CompactMemInfoItem.java @@ -32,6 +32,7 @@ public class CompactMemInfoItem implements IItem { public static final String PID_JSON_KEY = "pid"; public static final String NAME_JSON_KEY = "name"; public static final String PSS_JSON_KEY = "pss"; + public static final String SWAP_JSON_KEY = "swap"; public static final String TYPE_JSON_KEY = "type"; public static final String ACTIVITIES_JSON_KEY = "activities"; public static final String PROCESSES_JSON_KEY = "processes"; @@ -39,6 +40,7 @@ public class CompactMemInfoItem implements IItem { /** Constants for attributes HashMap */ private static final String NAME_ATTR_KEY = "name"; private static final String PSS_ATTR_KEY = "pss"; + private static final String SWAP_ATTR_KEY = "swap"; private static final String TYPE_ATTR_KEY = "type"; private static final String ACTIVITIES_ATTR_KEY = "activities"; @@ -66,6 +68,7 @@ public class CompactMemInfoItem implements IItem { proc.put(PID_JSON_KEY, pid); proc.put(NAME_JSON_KEY, getName(pid)); proc.put(PSS_JSON_KEY, getPss(pid)); + proc.put(SWAP_JSON_KEY, getSwap(pid)); proc.put(TYPE_JSON_KEY, getType(pid)); proc.put(ACTIVITIES_JSON_KEY, hasActivities(pid)); processes.put(proc); @@ -99,11 +102,12 @@ public class CompactMemInfoItem implements IItem { /** * Adds a process to the list stored in this item. */ - public void addPid(int pid, String name, String type, long pss, boolean activities) { + public void addPid(int pid, String name, String type, long pss, long swap, boolean activities) { Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put(NAME_ATTR_KEY, name); attributes.put(TYPE_ATTR_KEY, type); attributes.put(PSS_ATTR_KEY, pss); + attributes.put(SWAP_ATTR_KEY, swap); attributes.put(ACTIVITIES_ATTR_KEY, activities); mPids.put(pid, attributes); } @@ -123,6 +127,13 @@ public class CompactMemInfoItem implements IItem { } /** + * Return swap memory of the process with a given name. + */ + public long getSwap(int pid) { + return (Long)get(pid).get(SWAP_ATTR_KEY); + } + + /** * Returns the type of the process with a given pid. Some possible types are native, cached, * foreground and etc. */ diff --git a/src/com/android/loganalysis/parser/CompactMemInfoParser.java b/src/com/android/loganalysis/parser/CompactMemInfoParser.java index c3f29d0..a4223d2 100644 --- a/src/com/android/loganalysis/parser/CompactMemInfoParser.java +++ b/src/com/android/loganalysis/parser/CompactMemInfoParser.java @@ -38,7 +38,7 @@ import java.util.regex.Pattern; */ public class CompactMemInfoParser implements IParser { private static final Pattern PROC_PREFIX = Pattern.compile( - "proc,(.+),(.+),(\\d+),(\\d+),(.?)"); + "proc,(\\w+),([a-zA-Z_0-9\\.]+),(\\d+),(\\d+),((\\S+),)?(.*)"); private static final Pattern LOST_RAM_PREFIX = Pattern.compile( "lostram,(.+)"); @@ -57,8 +57,12 @@ public class CompactMemInfoParser implements IParser { try { int pid = Integer.parseInt(m.group(3)); long pss = Long.parseLong(m.group(4)); - boolean activities = "a".equals(m.group(5)); - item.addPid(pid, name, type, pss, activities); + long swap = 0; + if (m.group(6) != null && !"N/A".equals(m.group(6))) { + swap = Long.parseLong(m.group(6)); + } + boolean activities = "a".equals(m.group(6)); + item.addPid(pid, name, type, pss, swap, activities); continue; } catch (NumberFormatException nfe) { // ignore exception diff --git a/tests/src/com/android/loganalysis/parser/CompactMemInfoParserTest.java b/tests/src/com/android/loganalysis/parser/CompactMemInfoParserTest.java index 6400aca..009af1d 100644 --- a/tests/src/com/android/loganalysis/parser/CompactMemInfoParserTest.java +++ b/tests/src/com/android/loganalysis/parser/CompactMemInfoParserTest.java @@ -28,7 +28,20 @@ import java.util.List; public class CompactMemInfoParserTest extends TestCase { - public void testSingleProcLine() { + public void testSingleProcLineWithSwap() { + List<String> input = Arrays.asList("proc,cached,com.google.android.youtube1,2964,19345,1005,e"); + + CompactMemInfoItem item = new CompactMemInfoParser().parse(input); + + assertEquals(1, item.getPids().size()); + assertEquals("com.google.android.youtube1", item.getName(2964)); + assertEquals(19345, item.getPss(2964)); + assertEquals(1005, item.getSwap(2964)); + assertEquals("cached", item.getType(2964)); + assertEquals(false, item.hasActivities(2964)); + } + + public void testSingleProcLineWithoutSwap() { List<String> input = Arrays.asList("proc,cached,com.google.android.youtube,2964,19345,e"); CompactMemInfoItem item = new CompactMemInfoParser().parse(input); @@ -36,6 +49,7 @@ public class CompactMemInfoParserTest extends TestCase { assertEquals(1, item.getPids().size()); assertEquals("com.google.android.youtube", item.getName(2964)); assertEquals(19345, item.getPss(2964)); + assertEquals(0, item.getSwap(2964)); assertEquals("cached", item.getType(2964)); assertEquals(false, item.hasActivities(2964)); } @@ -49,6 +63,9 @@ public class CompactMemInfoParserTest extends TestCase { public void testSomeMalformedLines() { List<String> 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"); @@ -59,11 +76,11 @@ public class CompactMemInfoParserTest extends TestCase { public void testMultipleLines() { List<String> input = Arrays.asList( - "proc,cached,com.google.android.youtube,2964,19345,e", - "proc,cached,com.google.android.apps.plus,2877,9604,e", - "proc,cached,com.google.android.apps.magazines,2009,20111,e", - "proc,cached,com.google.android.apps.walletnfcrel,10790,11164,e", - "proc,cached,com.google.android.incallui,3410,9491,e", + "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"); CompactMemInfoItem item = new CompactMemInfoParser().parse(input); @@ -71,6 +88,7 @@ public class CompactMemInfoParserTest extends TestCase { assertEquals(5, item.getPids().size()); assertEquals("com.google.android.youtube", item.getName(2964)); assertEquals(19345, item.getPss(2964)); + assertEquals(123, item.getSwap(2964)); assertEquals("cached", item.getType(2964)); assertEquals(false, item.hasActivities(2964)); @@ -82,11 +100,11 @@ public class CompactMemInfoParserTest extends TestCase { List<String> input = Arrays.asList( "oom,cached,141357", - "proc,cached,com.google.android.youtube,2964,19345,e", - "proc,cached,com.google.android.apps.plus,2877,9604,e", - "proc,cached,com.google.android.apps.magazines,2009,20111,e", - "proc,cached,com.google.android.apps.walletnfcrel,10790,11164,e", - "proc,cached,com.google.android.incallui,3410,9491,e", + "proc,cached,com.google.android.youtube,2964,19345,54321,e", + "proc,cached,com.google.android.apps.plus,2877,9604,4321,e", + "proc,cached,com.google.android.apps.magazines,2009,20111,321,e", + "proc,cached,com.google.android.apps.walletnfcrel,10790,11164,21,e", + "proc,cached,com.google.android.incallui,3410,9491,1,e", "cat,Native,63169"); CompactMemInfoItem item = new CompactMemInfoParser().parse(input); @@ -94,6 +112,7 @@ public class CompactMemInfoParserTest extends TestCase { assertEquals(5, item.getPids().size()); assertEquals("com.google.android.youtube", item.getName(2964)); assertEquals(19345, item.getPss(2964)); + assertEquals(54321, item.getSwap(2964)); assertEquals("cached", item.getType(2964)); assertEquals(false, item.hasActivities(2964)); } @@ -101,11 +120,11 @@ public class CompactMemInfoParserTest extends TestCase { public void testJson() throws JSONException { List<String> input = Arrays.asList( "oom,cached,141357", - "proc,cached,com.google.android.youtube,2964,19345,e", - "proc,cached,com.google.android.apps.plus,2877,9604,e", - "proc,cached,com.google.android.apps.magazines,2009,20111,e", - "proc,cached,com.google.android.apps.walletnfcrel,10790,11164,e", - "proc,cached,com.google.android.incallui,3410,9491,e", + "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"); |