aboutsummaryrefslogtreecommitdiffstats
path: root/ddms
diff options
context:
space:
mode:
authorSiva Velusamy <vsiva@google.com>2012-03-06 14:46:46 -0800
committerSiva Velusamy <vsiva@google.com>2012-03-06 14:46:46 -0800
commit240768b9433e3cb394fe6a8d35de0eb324bf799d (patch)
treed7e60fd8c73f5e221538f6a41bfaae3a6ae1b13e /ddms
parent5879c13d7bfa88e181062178d492713e3ddbadfb (diff)
downloadsdk-240768b9433e3cb394fe6a8d35de0eb324bf799d.zip
sdk-240768b9433e3cb394fe6a8d35de0eb324bf799d.tar.gz
sdk-240768b9433e3cb394fe6a8d35de0eb324bf799d.tar.bz2
logcat: support new format for "logcat -v long"
The thread id's output in "logcat -v long" used to be encoded in hex, but not anymore. This fixes the logcat parser to accomodate both the old and the new formats. Change-Id: I0871a68f2f82c5e4660c404ec8970063d7b68a88
Diffstat (limited to 'ddms')
-rw-r--r--ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatMessage.java18
-rw-r--r--ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatMessageParser.java6
-rw-r--r--ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/LogCatFilterTest.java30
-rw-r--r--ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/LogCatMessageParserTest.java7
4 files changed, 42 insertions, 19 deletions
diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatMessage.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatMessage.java
index 2a9640f..aea4ead 100644
--- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatMessage.java
+++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatMessage.java
@@ -27,6 +27,7 @@ import com.android.ddmlib.Log.LogLevel;
public final class LogCatMessage {
private final LogLevel mLogLevel;
private final String mPid;
+ private final String mTid;
private final String mAppName;
private final String mTag;
private final String mTime;
@@ -35,7 +36,7 @@ public final class LogCatMessage {
/**
* Construct an immutable log message object.
*/
- public LogCatMessage(LogLevel logLevel, String pid, String appName,
+ public LogCatMessage(LogLevel logLevel, String pid, String tid, String appName,
String tag, String time, String msg) {
mLogLevel = logLevel;
mPid = pid;
@@ -43,6 +44,17 @@ public final class LogCatMessage {
mTag = tag;
mTime = time;
mMessage = msg;
+
+ long tidValue;
+ try {
+ // Thread id's may be in hex on some platforms.
+ // Decode and store them in radix 10.
+ tidValue = Long.decode(tid.trim());
+ } catch (NumberFormatException e) {
+ tidValue = -1;
+ }
+
+ mTid = Long.toString(tidValue);
}
public LogLevel getLogLevel() {
@@ -53,6 +65,10 @@ public final class LogCatMessage {
return mPid;
}
+ public String getTid() {
+ return mTid;
+ }
+
public String getAppName() {
return mAppName;
}
diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatMessageParser.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatMessageParser.java
index 930af95..b69a433 100644
--- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatMessageParser.java
+++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatMessageParser.java
@@ -29,6 +29,7 @@ import java.util.regex.Pattern;
public final class LogCatMessageParser {
private LogLevel mCurLogLevel = LogLevel.WARN;
private String mCurPid = "?";
+ private String mCurTid = "?";
private String mCurTag = "?";
private String mCurTime = "?:??";
@@ -48,7 +49,7 @@ public final class LogCatMessageParser {
*/
private static Pattern sLogHeaderPattern = Pattern.compile(
"^\\[\\s(\\d\\d-\\d\\d\\s\\d\\d:\\d\\d:\\d\\d\\.\\d+)"
- + "\\s+(\\d*):(0x[0-9a-fA-F]+)\\s([VDIWEAF])/(.*)\\]$");
+ + "\\s+(\\d*):\\s*(\\S+)\\s([VDIWEAF])/(.*)\\]$");
/**
* Parse a list of strings into {@link LogCatMessage} objects. This method
@@ -71,6 +72,7 @@ public final class LogCatMessageParser {
if (matcher.matches()) {
mCurTime = matcher.group(1);
mCurPid = matcher.group(2);
+ mCurTid = matcher.group(3);
mCurLogLevel = LogLevel.getByLetterString(matcher.group(4));
mCurTag = matcher.group(5).trim();
@@ -80,7 +82,7 @@ public final class LogCatMessageParser {
mCurLogLevel = LogLevel.ASSERT;
}
} else {
- LogCatMessage m = new LogCatMessage(mCurLogLevel, mCurPid,
+ LogCatMessage m = new LogCatMessage(mCurLogLevel, mCurPid, mCurTid,
pidToNameMapper.getName(mCurPid),
mCurTag, mCurTime, line);
messages.add(m);
diff --git a/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/LogCatFilterTest.java b/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/LogCatFilterTest.java
index c471f1f..7fedb08 100644
--- a/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/LogCatFilterTest.java
+++ b/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/LogCatFilterTest.java
@@ -28,12 +28,12 @@ public class LogCatFilterTest extends TestCase {
/* filter message below filter's log level */
LogCatMessage msg = new LogCatMessage(LogLevel.VERBOSE,
- "", "", "", "", "");
+ "", "", "", "", "", "");
assertEquals(false, filter.matches(msg));
/* do not filter message above filter's log level */
msg = new LogCatMessage(LogLevel.ERROR,
- "", "", "", "", "");
+ "", "", "", "", "", "");
assertEquals(true, filter.matches(msg));
}
@@ -43,12 +43,12 @@ public class LogCatFilterTest extends TestCase {
/* show message with pid matching filter */
LogCatMessage msg = new LogCatMessage(LogLevel.VERBOSE,
- "123", "", "", "", "");
+ "123", "", "", "", "", "");
assertEquals(true, filter.matches(msg));
/* don't show message with pid not matching filter */
msg = new LogCatMessage(LogLevel.VERBOSE,
- "12", "", "", "", "");
+ "12", "", "", "", "", "");
assertEquals(false, filter.matches(msg));
}
@@ -58,12 +58,12 @@ public class LogCatFilterTest extends TestCase {
/* show message with pid matching filter */
LogCatMessage msg = new LogCatMessage(LogLevel.VERBOSE,
- "", "dalvikvm1", "", "", "");
+ "", "", "dalvikvm1", "", "", "");
assertEquals(true, filter.matches(msg));
/* don't show message with pid not matching filter */
msg = new LogCatMessage(LogLevel.VERBOSE,
- "", "system", "", "", "");
+ "", "", "system", "", "", "");
assertEquals(false, filter.matches(msg));
}
@@ -73,11 +73,11 @@ public class LogCatFilterTest extends TestCase {
/* show message with tag matching filter */
LogCatMessage msg = new LogCatMessage(LogLevel.VERBOSE,
- "", "", "tag123", "", "");
+ "", "", "", "tag123", "", "");
assertEquals(true, filter.matches(msg));
msg = new LogCatMessage(LogLevel.VERBOSE,
- "", "", "ta123", "", "");
+ "", "", "", "ta123", "", "");
assertEquals(false, filter.matches(msg));
}
@@ -87,17 +87,17 @@ public class LogCatFilterTest extends TestCase {
/* show message with text matching filter */
LogCatMessage msg = new LogCatMessage(LogLevel.VERBOSE,
- "", "", "", "", "text123");
+ "", "", "", "", "", "text123");
assertEquals(true, filter.matches(msg));
msg = new LogCatMessage(LogLevel.VERBOSE,
- "", "", "", "", "te123");
+ "", "", "", "", "", "te123");
assertEquals(false, filter.matches(msg));
}
public void testMatchingText() {
LogCatMessage msg = new LogCatMessage(LogLevel.VERBOSE,
- "", "", "", "", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ "", "", "", "", "", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"message with word1 and word2"); //$NON-NLS-1$
assertEquals(true, search("word1 with", msg)); //$NON-NLS-1$
assertEquals(true, search("text:w.* ", msg)); //$NON-NLS-1$
@@ -106,7 +106,7 @@ public class LogCatFilterTest extends TestCase {
public void testTagKeyword() {
LogCatMessage msg = new LogCatMessage(LogLevel.VERBOSE,
- "", "", "tag", "", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ "", "", "", "tag", "", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"sample message"); //$NON-NLS-1$
assertEquals(false, search("t.*", msg)); //$NON-NLS-1$
assertEquals(true, search("tag:t.*", msg)); //$NON-NLS-1$
@@ -114,7 +114,7 @@ public class LogCatFilterTest extends TestCase {
public void testPidKeyword() {
LogCatMessage msg = new LogCatMessage(LogLevel.VERBOSE,
- "123", "", "", "", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ "123", "", "", "", "", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"sample message"); //$NON-NLS-1$
assertEquals(false, search("123", msg)); //$NON-NLS-1$
assertEquals(true, search("pid:123", msg)); //$NON-NLS-1$
@@ -122,7 +122,7 @@ public class LogCatFilterTest extends TestCase {
public void testAppNameKeyword() {
LogCatMessage msg = new LogCatMessage(LogLevel.VERBOSE,
- "", "dalvik", "", "", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ "", "", "dalvik", "", "", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"sample message"); //$NON-NLS-1$
assertEquals(false, search("dalv.*", msg)); //$NON-NLS-1$
assertEquals(true, search("app:dal.*k", msg)); //$NON-NLS-1$
@@ -130,7 +130,7 @@ public class LogCatFilterTest extends TestCase {
public void testCaseSensitivity() {
LogCatMessage msg = new LogCatMessage(LogLevel.VERBOSE,
- "", "", "", "",
+ "", "", "", "", "",
"Sample message");
// if regex has an upper case character, it should be
diff --git a/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/LogCatMessageParserTest.java b/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/LogCatMessageParserTest.java
index dd5cbc2..dfde250 100644
--- a/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/LogCatMessageParserTest.java
+++ b/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/LogCatMessageParserTest.java
@@ -46,7 +46,7 @@ public final class LogCatMessageParserTest extends TestCase {
private static final String[] MESSAGES = new String[] {
"[ 08-11 19:11:07.132 495:0x1ef D/dtag ]", //$NON-NLS-1$
"debug message", //$NON-NLS-1$
- "[ 08-11 19:11:07.132 495:0x1ef E/etag ]", //$NON-NLS-1$
+ "[ 08-11 19:11:07.132 495: 234 E/etag ]", //$NON-NLS-1$
"error message", //$NON-NLS-1$
"[ 08-11 19:11:07.132 495:0x1ef I/itag ]", //$NON-NLS-1$
"info message", //$NON-NLS-1$
@@ -91,4 +91,9 @@ public final class LogCatMessageParserTest extends TestCase {
public void testMessage() {
assertEquals(mParsedMessages.get(2).getMessage(), MESSAGES[5]);
}
+
+ public void testTid() {
+ assertEquals(mParsedMessages.get(0).getTid(), Integer.toString(0x1ef));
+ assertEquals(mParsedMessages.get(1).getTid(), "234");
+ }
}