Skip to content

Commit

Permalink
Fix parsing of some tricky process and logcat sections
Browse files Browse the repository at this point in the history
* EVENT LOG TAGS section of ancient android versions was tripping over
  the parser, which attempted to read it as an event log
* PROCESSES section is reported to be very variable in the wild, though
  I don't have hands-on dumpstates with such logs.

Issue: #119
  • Loading branch information
mlopatkin committed Dec 26, 2023
1 parent d5a1624 commit cba4a50
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static boolean isSectionEnd(CharSequence line) {
* @return {@code true} if the section is a process list section
*/
public static boolean isProcessSection(String sectionName) {
return "PROCESSES (ps -P)".equals(sectionName);
return "PROCESSES".equals(sectionName) || sectionName.startsWith("PROCESSES (");
}

/**
Expand Down Expand Up @@ -139,7 +139,8 @@ public static Optional<LogRecord.Buffer> getBufferFromLogcatSectionName(String s
}

private static boolean isLogcatSectionName(String sectionName, String bufferSectionNamePart) {
return sectionName.startsWith(bufferSectionNamePart + " LOG");
var nameWithBuffer = bufferSectionNamePart + " LOG";
return sectionName.equals(nameWithBuffer) || sectionName.startsWith(nameWithBuffer + " (");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ void canDetermineNotSectionEnd(String line) {

@ParameterizedTest
@ValueSource(strings = {
"PROCESSES (ps -P)"
"PROCESSES (ps -P)",
"PROCESSES",
"PROCESSES (ps -P --abi)",
// TODO(mlopatkin) This need more supported cases
})
void canDetermineProcessSection(String sectionName) {
Expand All @@ -141,7 +143,6 @@ void canDetermineProcessSection(String sectionName) {
"PROCRANK",
"PROCESSES AND THREADS (ps -t -p -P)",
"PROCESSES AND THREADS",
"PROCESSES", // TODO(mlopatkin) this should actually be supported
})
void canDetermineNotProcessSection(String sectionName) {
assertThat(DumpstateElements.isProcessSection(sectionName)).isFalse();
Expand Down Expand Up @@ -169,6 +170,7 @@ void canDetermineLogcatSection(String sectionName, String expectedBufferName) {
"PROCESSES",
"KERNEL LOG (dmesg)",
"KERNEL LOG",
"EVENT LOG TAGS",
"BINDER FAILED TRANSACTION LOG (/sys/kernel/debug/binder/failed_transaction_log)",
"LAST RADIO LOG (parse_radio_log /proc/last_radio_log)" // TODO(mlopatkin) Can we parse it?
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ protected ParserControl logRecord(LogRecord record) {

@Override
public ParserControl unparseableLine(CharSequence line) {
logger.debug("Failed to parse dumpstate logcat line: " + line);
if (line.length() > 0) {
logger.debug("Failed to parse dumpstate logcat line: " + line);
}
return ParserControl.proceed();
}
});
Expand Down

0 comments on commit cba4a50

Please sign in to comment.