diff options
author | gopinath <gelanchezhian@google.com> | 2019-07-30 14:56:26 -0700 |
---|---|---|
committer | Gopinath Elanchezhian <gelanchezhian@google.com> | 2019-07-31 00:00:58 +0000 |
commit | 47c5a970cef53d333eac4451cf4e2af9a9829a88 (patch) | |
tree | d42ce4e053723ddc0ec11c4afa2b898af1c8ec57 | |
parent | 258b08baf19272d21f38a4a41784cfbe41deeb58 (diff) | |
download | loganalysis-47c5a970cef53d333eac4451cf4e2af9a9829a88.tar.gz |
Add source in init action info logging.
Bug: b/135751856
Test: DmesgParserTest
9 Pass
Change-Id: I87d4f344b631690ffeaa3a1909adb845964ed1d3
Merged-In: If7c82c7e7162a575333948d87fcf9c2d993d03ef
3 files changed, 40 insertions, 32 deletions
diff --git a/src/com/android/loganalysis/item/DmesgActionInfoItem.java b/src/com/android/loganalysis/item/DmesgActionInfoItem.java index ac73b8e..482b426 100644 --- a/src/com/android/loganalysis/item/DmesgActionInfoItem.java +++ b/src/com/android/loganalysis/item/DmesgActionInfoItem.java @@ -27,12 +27,14 @@ import java.util.Set; public class DmesgActionInfoItem extends GenericItem { /** Constant for JSON output */ + public static final String SOURCE_NAME = "SOURCE_NAME"; + /** Constant for JSON output */ public static final String ACTION_NAME = "ACTION_NAME"; /** Constant for JSON output */ public static final String ACTION_START_TIME = "ACTION_START_TIME"; private static final Set<String> ATTRIBUTES = new HashSet<String>(Arrays.asList( - ACTION_NAME, ACTION_START_TIME)); + SOURCE_NAME, ACTION_NAME, ACTION_START_TIME)); /** * The constructor for {@link DmesgActionInfoItem}. @@ -44,13 +46,28 @@ public class DmesgActionInfoItem extends GenericItem { /** * The constructor for {@link DmesgActionInfoItem}. */ - public DmesgActionInfoItem(String name, Long startTime) { + public DmesgActionInfoItem(String source, String name, Long startTime) { super(ATTRIBUTES); + setAttribute(SOURCE_NAME, source); setAttribute(ACTION_NAME, name); setAttribute(ACTION_START_TIME, startTime); } /** + * Get the name of the source + */ + public String getSourceName() { + return (String) getAttribute(SOURCE_NAME); + } + + /** + * Set the name of the source + */ + public void setSourceName(String sourceName) { + setAttribute(SOURCE_NAME, sourceName); + } + + /** * Get the name of the action */ public String getActionName() { @@ -80,8 +97,11 @@ public class DmesgActionInfoItem extends GenericItem { @Override public String toString() { - return "ActionInfoItem [getActionName()=" + getActionName() + ", getStartTime()=" - + getStartTime() + "]"; + return "ActionInfoItem [" + + "getSourceName()=" + getSourceName() + + ", getActionName()=" + getActionName() + + ", getStartTime()=" + getStartTime() + + "]"; } } diff --git a/src/com/android/loganalysis/parser/DmesgParser.java b/src/com/android/loganalysis/parser/DmesgParser.java index be292ff..4b4d333 100644 --- a/src/com/android/loganalysis/parser/DmesgParser.java +++ b/src/com/android/loganalysis/parser/DmesgParser.java @@ -40,6 +40,7 @@ public class DmesgParser implements IParser { private static final String TIMESTAMP = "TIMESTAMP"; private static final String STAGE = "STAGE"; private static final String ACTION = "ACTION"; + private static final String SOURCE = "SOURCE"; private static final String DURATION = "DURATION"; private static final String UEVENTD = "ueventd"; private static final String INIT = "init"; @@ -74,21 +75,13 @@ public class DmesgParser implements IParser { // Matches: init: processing action (early-init) from (/init.rc:14) private static final String START_PROCESSING_ACTION_PREFIX = - String.format("processing action \\((?<%s>.*)\\) from.*$", ACTION); - - // Matches: init: processing action (early-init) - private static final String START_PROCESSING_ACTION_PREFIX_LEGACY = - String.format("processing action \\((?<%s>.*)\\).*$", ACTION); + String.format("processing action \\((?<%s>[^)]*)\\)( from \\((?<%s>.*)\\)|.*)$", + ACTION, SOURCE); // Matches: init: processing action (early-init) from (/init.rc:14) private static final Pattern START_PROCESSING_ACTION = Pattern.compile(String.format("%s%s", SERVICE_PREFIX, START_PROCESSING_ACTION_PREFIX)); - // Matches: init: processing action (early-init) - private static final Pattern START_PROCESSING_ACTION_LEGACY = - Pattern.compile( - String.format("%s%s", SERVICE_PREFIX, START_PROCESSING_ACTION_PREFIX_LEGACY)); - // Matches: [ 3.791635] ueventd: Coldboot took 0.695055 seconds private static final String STAGE_SUFFIX= String.format( "(?<%s>.*)\\s+took\\s+(?<%s>.*)\\s+seconds$", STAGE, DURATION); @@ -242,9 +235,11 @@ public class DmesgParser implements IParser { @VisibleForTesting boolean parseActionInfo(String line) { Matcher match = null; - if ((match = matches(START_PROCESSING_ACTION, line)) != null - || (match = matches(START_PROCESSING_ACTION_LEGACY, line)) != null) { + if ((match = matches(START_PROCESSING_ACTION, line)) != null) { DmesgActionInfoItem actionInfoItem = new DmesgActionInfoItem(); + if (match.group(SOURCE) != null) { + actionInfoItem.setSourceName(match.group(SOURCE)); + } actionInfoItem.setActionName(match.group(ACTION)); actionInfoItem.setStartTime((long) (Double.parseDouble( match.group(TIMESTAMP)) * 1000)); diff --git a/tests/src/com/android/loganalysis/parser/DmesgParserTest.java b/tests/src/com/android/loganalysis/parser/DmesgParserTest.java index 7cdbd36..4362c7a 100644 --- a/tests/src/com/android/loganalysis/parser/DmesgParserTest.java +++ b/tests/src/com/android/loganalysis/parser/DmesgParserTest.java @@ -215,22 +215,15 @@ public class DmesgParserTest extends TestCase { private static List<DmesgActionInfoItem> getExpectedActionInfoItems() { return Arrays.asList( - new DmesgActionInfoItem("early-init", (long) (Double.parseDouble("44942.872"))), - new DmesgActionInfoItem( - "set_mmap_rnd_bits", (long) (Double.parseDouble("47233.446"))), - new DmesgActionInfoItem( - "set_kptr_restrict", (long) (Double.parseDouble("47240.083"))), - new DmesgActionInfoItem("keychord_init", (long) (Double.parseDouble("47245.778"))), - new DmesgActionInfoItem( - "persist.sys.usb.config=* boot", (long) (Double.parseDouble("52361.049"))), - new DmesgActionInfoItem( - "enable_property_trigger", (long) (Double.parseDouble("52361.108"))), - new DmesgActionInfoItem( - "security.perf_harden=1", (long) (Double.parseDouble("52361.313"))), - new DmesgActionInfoItem( - "ro.debuggable=1", (long) (Double.parseDouble("52361.495"))), - new DmesgActionInfoItem( - "sys.boot_completed=1", (long) (Double.parseDouble("58298.293")))); + new DmesgActionInfoItem("/init.rc:13", "early-init", 44942L), + new DmesgActionInfoItem("<Builtin Action>:0", "set_mmap_rnd_bits", 47233L), + new DmesgActionInfoItem("<Builtin Action>:0", "set_kptr_restrict", 47240L), + new DmesgActionInfoItem("<Builtin Action>:0", "keychord_init", 47245L), + new DmesgActionInfoItem("<Builtin Action>:0", "persist.sys.usb.config=* boot", 52361L), + new DmesgActionInfoItem("<Builtin Action>:0", "enable_property_trigger", 52361L), + new DmesgActionInfoItem("/init.rc:677", "security.perf_harden=1", 52361L), + new DmesgActionInfoItem("/init.rc:700", "ro.debuggable=1", 52361L), + new DmesgActionInfoItem(null, "sys.boot_completed=1", 58298L)); } private static List<DmesgStageInfoItem> getExpectedStageInfoItems() { |