summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Rowe <erowe@google.com>2013-12-12 19:41:08 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-12-12 19:41:08 +0000
commitb9a677c06570dbfdf0adf984c21f5a3da4abb954 (patch)
treeb6bc9d9001ed4be1467082ac3b83a88f7157d31f
parente006c399723e4770c023b67478a5f6d3e479950e (diff)
parent3b87b00dc86c8e35f35b715e1c8e732c1fcfd581 (diff)
downloadloganalysis-b9a677c06570dbfdf0adf984c21f5a3da4abb954.tar.gz
Merge "Stop parsing between reboot and new log."
-rw-r--r--src/com/android/loganalysis/parser/LogcatParser.java26
-rw-r--r--tests/src/com/android/loganalysis/parser/LogcatParserTest.java44
2 files changed, 64 insertions, 6 deletions
diff --git a/src/com/android/loganalysis/parser/LogcatParser.java b/src/com/android/loganalysis/parser/LogcatParser.java
index 4a709a0..ffd8fb2 100644
--- a/src/com/android/loganalysis/parser/LogcatParser.java
+++ b/src/com/android/loganalysis/parser/LogcatParser.java
@@ -117,6 +117,8 @@ public class LogcatParser implements IParser {
private Date mStartTime = null;
private Date mStopTime = null;
+ private boolean mIsParsing = true;
+
/**
* Constructor for {@link LogcatParser}.
*/
@@ -209,15 +211,27 @@ public class LogcatParser implements IParser {
tag = tm.group(3);
pid = Integer.parseInt(tm.group(4));
msg = tm.group(5);
- } else {
- // CLog.w("Failed to parse line '%s'", line);
- return;
}
- if (mStartTime == null) {
- mStartTime = time;
+ if (time != null) {
+ if (mStartTime == null) {
+ mStartTime = time;
+ }
+ mStopTime = time;
+ }
+
+ // Don't parse any lines after device begins reboot until a new log is detected.
+ if ("I".equals(level) && "ShutdownThread".equals(tag) &&
+ Pattern.matches("Rebooting, reason: .*", msg)) {
+ mIsParsing = false;
+ }
+ if (Pattern.matches(".*--------- beginning of /dev/log/main", line)) {
+ mIsParsing = true;
+ }
+
+ if (!mIsParsing || !(m.matches() || tm.matches())) {
+ return;
}
- mStopTime = time;
// ANRs are split when START matches a line. The newest entry is kept in the dataMap
// for quick lookup while all entries are added to the list.
diff --git a/tests/src/com/android/loganalysis/parser/LogcatParserTest.java b/tests/src/com/android/loganalysis/parser/LogcatParserTest.java
index 4ae1460..bfc9297 100644
--- a/tests/src/com/android/loganalysis/parser/LogcatParserTest.java
+++ b/tests/src/com/android/loganalysis/parser/LogcatParserTest.java
@@ -431,6 +431,50 @@ public class LogcatParserTest extends TestCase {
}
/**
+ * Test that events while the device is rebooting are ignored.
+ */
+ public void testParse_reboot() throws ParseException {
+ List<String> lines = Arrays.asList(
+ "04-25 09:15:47.799 123 3082 I ShutdownThread: Rebooting, reason: null",
+ "04-25 09:55:47.799 3064 3082 E AndroidRuntime: java.lang.Exception",
+ "04-25 09:55:47.799 3064 3082 E AndroidRuntime: \tat class.method1(Class.java:1)",
+ "04-25 09:55:47.799 3064 3082 E AndroidRuntime: \tat class.method2(Class.java:2)",
+ "04-25 09:55:47.799 3064 3082 E AndroidRuntime: \tat class.method3(Class.java:3)");
+
+ LogcatItem logcat = new LogcatParser("2012").parse(lines);
+ assertNotNull(logcat);
+ assertEquals(parseTime("2012-04-25 09:15:47.799"), logcat.getStartTime());
+ assertEquals(parseTime("2012-04-25 09:55:47.799"), logcat.getStopTime());
+ assertEquals(0, logcat.getEvents().size());
+ }
+
+ /**
+ * Test that events while the device is rebooting are ignored, but devices after the reboot are
+ * captured.
+ */
+ public void testParse_reboot_resume() throws ParseException {
+ List<String> lines = Arrays.asList(
+ "04-25 09:15:47.799 123 3082 I ShutdownThread: Rebooting, reason: null",
+ "04-25 09:55:47.799 3064 3082 E AndroidRuntime: java.lang.Exception",
+ "04-25 09:55:47.799 3064 3082 E AndroidRuntime: \tat class.method1(Class.java:1)",
+ "04-25 09:55:47.799 3064 3082 E AndroidRuntime: \tat class.method2(Class.java:2)",
+ "04-25 09:55:47.799 3064 3082 E AndroidRuntime: \tat class.method3(Class.java:3)",
+ "logcat interrupted. May see duplicated content in log.--------- beginning of /dev/log/main",
+ "04-25 09:59:47.799 3064 3082 E AndroidRuntime: java.lang.Exception2",
+ "04-25 09:59:47.799 3064 3082 E AndroidRuntime: \tat class.method1(Class.java:1)",
+ "04-25 09:59:47.799 3064 3082 E AndroidRuntime: \tat class.method2(Class.java:2)",
+ "04-25 09:59:47.799 3064 3082 E AndroidRuntime: \tat class.method3(Class.java:3)");
+
+
+ LogcatItem logcat = new LogcatParser("2012").parse(lines);
+ assertNotNull(logcat);
+ assertEquals(parseTime("2012-04-25 09:15:47.799"), logcat.getStartTime());
+ assertEquals(parseTime("2012-04-25 09:59:47.799"), logcat.getStopTime());
+ assertEquals(1, logcat.getEvents().size());
+ assertEquals("java.lang.Exception2", logcat.getJavaCrashes().get(0).getException());
+ }
+
+ /**
* Test that the time logcat format can be parsed.
*/
public void testParse_time() throws ParseException {