summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Rowe <erowe@google.com>2015-12-14 14:32:31 -0800
committerEric Rowe <erowe@google.com>2015-12-14 14:40:28 -0800
commit8fa96e09ad86d44115fd778b638bd71513b3c4e5 (patch)
tree9bb99d2b2dd5c9b54666a295cafea62d053d8094
parent21a5f6afae53e05fdfe9c9ee2cc82d9b8f9da37e (diff)
downloadloganalysis-8fa96e09ad86d44115fd778b638bd71513b3c4e5.tar.gz
Add support for more fields in procrank
Bug: 26140048 Change-Id: I9b7e46ee9fb5eb34de56ff4832ec942947b5b2cc
-rw-r--r--src/com/android/loganalysis/parser/ProcrankParser.java21
-rw-r--r--tests/src/com/android/loganalysis/parser/ProcrankParserTest.java35
2 files changed, 51 insertions, 5 deletions
diff --git a/src/com/android/loganalysis/parser/ProcrankParser.java b/src/com/android/loganalysis/parser/ProcrankParser.java
index c54e7ef..8dc8fd6 100644
--- a/src/com/android/loganalysis/parser/ProcrankParser.java
+++ b/src/com/android/loganalysis/parser/ProcrankParser.java
@@ -30,13 +30,18 @@ public class ProcrankParser implements IParser {
/** Match a valid line, such as:
* " 1313 78128K 77996K 48603K 45812K com.google.android.apps.maps" */
- private static final Pattern LINE_PAT = Pattern.compile(
+ private static final Pattern SHORT_LINE_PAT = Pattern.compile(
"\\s*(\\d+)\\s+" + /* PID [1] */
"(\\d+)K\\s+(\\d+)K\\s+(\\d+)K\\s+(\\d+)K\\s+" + /* Vss Rss Pss Uss [2-5] */
"(\\S+)" /* process name [6] */);
+ private static final Pattern LONG_LINE_PAT = Pattern.compile(
+ "\\s*(\\d+)\\s+" + /* PID [1] */
+ "(\\d+)K\\s+(\\d+)K\\s+(\\d+)K\\s+(\\d+)K\\s+" + /* Vss Rss Pss Uss [2-5] */
+ "(\\d+)K\\s+(\\d+)K\\s+(\\d+)K\\s+(\\d+)K\\s+" + /* Swap PSwap USwap ZSwap [6-9] */
+ "(\\S+)" /* process name [10] */);
- /** Match the end of the Procrank table, determined by three sets of "------". */
- private static final Pattern END_PAT = Pattern.compile("^\\s+-{6}\\s+-{6}\\s+-{6}");
+ /** Match the end of the Procrank table, determined by three or more sets of "------". */
+ private static final Pattern END_PAT = Pattern.compile("^(\\s+-{6}){3,}$");
/**
* {@inheritDoc}
@@ -58,11 +63,19 @@ public class ProcrankParser implements IParser {
return item;
}
- Matcher m = LINE_PAT.matcher(line);
+ Matcher m = SHORT_LINE_PAT.matcher(line);
if (m.matches()) {
item.addProcrankLine(Integer.parseInt(m.group(1)), m.group(6),
Integer.parseInt(m.group(2)), Integer.parseInt(m.group(3)),
Integer.parseInt(m.group(4)), Integer.parseInt(m.group(5)));
+ continue;
+ }
+
+ m = LONG_LINE_PAT.matcher(line);
+ if (m.matches()) {
+ item.addProcrankLine(Integer.parseInt(m.group(1)), m.group(10),
+ Integer.parseInt(m.group(2)), Integer.parseInt(m.group(3)),
+ Integer.parseInt(m.group(4)), Integer.parseInt(m.group(5)));
}
}
diff --git a/tests/src/com/android/loganalysis/parser/ProcrankParserTest.java b/tests/src/com/android/loganalysis/parser/ProcrankParserTest.java
index a5be424..c47b750 100644
--- a/tests/src/com/android/loganalysis/parser/ProcrankParserTest.java
+++ b/tests/src/com/android/loganalysis/parser/ProcrankParserTest.java
@@ -31,7 +31,7 @@ public class ProcrankParserTest extends TestCase {
/**
* Test that normal input is parsed.
*/
- public void testProcRankParser() {
+ public void testProcRankParserShortLine() {
List<String> inputBlock = Arrays.asList(
" PID Vss Rss Pss Uss cmdline",
" 178 87136K 81684K 52829K 50012K system_server",
@@ -62,6 +62,39 @@ public class ProcrankParserTest extends TestCase {
}
/**
+ * Test that normal input is parsed.
+ */
+ public void testProcRankParserLongLine() {
+ List<String> inputBlock = Arrays.asList(
+ " PID Vss Rss Pss Uss Swap PSwap USwap ZSwap cmdline",
+ " 6711 3454396K 146300K 108431K 105524K 31540K 20522K 20188K 4546K com.google.android.GoogleCamera",
+ " 1515 2535920K 131984K 93750K 89440K 42676K 31792K 31460K 7043K system_server",
+ "19906 2439540K 130228K 85418K 69296K 11680K 353K 0K 78K com.android.chrome:sandboxed_process10",
+ "13790 2596308K 124424K 75673K 69680K 11336K 334K 0K 74K com.google.android.youtube",
+ " 9288 2437704K 119496K 74288K 69532K 11344K 334K 0K 74K com.google.android.videos",
+ " 51312K 22911K 20608K 0K 0K 0K invalid.format",
+ " ------ ------ ------ ------ ------ ------ ------",
+ " 1061237K 940460K 619796K 225468K 201688K 49950K TOTAL",
+ "ZRAM: 52892K physical used for 238748K in swap (520908K total swap)",
+ "RAM: 1857348K total, 51980K free, 3780K buffers, 456272K cached, 29220K shmem, 97560K slab",
+ "[/system/xbin/su: 3.260s elapsed]");
+
+ ProcrankItem procrank = new ProcrankParser().parse(inputBlock);
+
+ // Ensures that only valid lines are parsed. Only 6 of the 11 lines under the header are
+ // valid.
+ assertEquals(5, procrank.getPids().size());
+
+ // Make sure all expected rows are present, and do a diagonal check of values
+ assertEquals((Integer) 3454396, procrank.getVss(6711));
+ assertEquals((Integer) 146300, procrank.getRss(6711));
+ assertEquals((Integer) 108431, procrank.getPss(6711));
+ assertEquals((Integer) 105524, procrank.getUss(6711));
+ assertEquals("com.google.android.GoogleCamera", procrank.getProcessName(6711));
+ assertEquals(ArrayUtil.join("\n", inputBlock), procrank.getText());
+ }
+
+ /**
* Test that an empty input returns {@code null}.
*/
public void testEmptyInput() {