diff options
author | Lisa Liu <liulisa@google.com> | 2021-02-25 11:34:07 +0800 |
---|---|---|
committer | Lisa Liu <liulisa@google.com> | 2021-03-04 15:16:25 +0800 |
commit | abb0ccaf24ddbdbe5b9da79ec35f12cd813f756c (patch) | |
tree | 50fa108b76aad72b5807f09bbbb9926a8d2003db /src | |
parent | 73f4d8b44799337efc3a70fb283eba67142add2c (diff) | |
download | loganalysis-abb0ccaf24ddbdbe5b9da79ec35f12cd813f756c.tar.gz |
Add module info to dmesg parser
Parse module name, load duration and count from dmesg.
BUG: 174796470
Test: run_tradefed_tests.sh --class com.android.loganalysis.parser.DmesgParserTest
Change-Id: I4943ed10e7fa73519204cbfa028a3b8d75af2204
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/loganalysis/item/DmesgItem.java | 14 | ||||
-rw-r--r-- | src/com/android/loganalysis/item/DmesgModuleInfoItem.java | 122 | ||||
-rw-r--r-- | src/com/android/loganalysis/parser/DmesgParser.java | 74 |
3 files changed, 207 insertions, 3 deletions
diff --git a/src/com/android/loganalysis/item/DmesgItem.java b/src/com/android/loganalysis/item/DmesgItem.java index de70145..43fc04d 100644 --- a/src/com/android/loganalysis/item/DmesgItem.java +++ b/src/com/android/loganalysis/item/DmesgItem.java @@ -33,6 +33,8 @@ public class DmesgItem extends GenericItem { private List<DmesgActionInfoItem> mActionInfoItems = new ArrayList<>(); + private Map<String, DmesgModuleInfoItem> mModuleInfoItems = new HashMap<>(); + public DmesgItem() { super(Collections.emptySet()); } @@ -80,4 +82,16 @@ public class DmesgItem extends GenericItem { mActionInfoItems.add(actionInfoItem); } + /** @return moduleInfoItem */ + public Map<String, DmesgModuleInfoItem> getModuleInfoItems() { + return mModuleInfoItems; + } + + /** + * @param key to identify module info item + * @param moduleInfoItem to be added to the list + */ + public void addModuleInfoItem(String key, DmesgModuleInfoItem moduleInfoItem) { + mModuleInfoItems.put(key, moduleInfoItem); + } } diff --git a/src/com/android/loganalysis/item/DmesgModuleInfoItem.java b/src/com/android/loganalysis/item/DmesgModuleInfoItem.java new file mode 100644 index 0000000..dca6721 --- /dev/null +++ b/src/com/android/loganalysis/item/DmesgModuleInfoItem.java @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.loganalysis.item; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +/** An {@link IItem} used to store Module info logged in dmesg. */ +public class DmesgModuleInfoItem extends GenericItem { + + /** Constant for JSON output */ + public static final String MODULE_NAME = "MODULE_NAME"; + + public static final String MODULE_START_TIME = "MODULE_START_TIME"; + + public static final String MODULE_END_TIME = "MODULE_END_TIME"; + + public static final String MODULE_COUNT = "MODULE_COUNT"; + + public static final String MODULE_DURATION = "MODULE_DURATION"; + + private static final Set<String> ATTRIBUTES = + new HashSet<String>( + Arrays.asList( + MODULE_NAME, + MODULE_START_TIME, + MODULE_END_TIME, + MODULE_COUNT, + MODULE_DURATION)); + + /** The constructor for {@link DmesgModuleInfoItem}. */ + public DmesgModuleInfoItem() { + super(ATTRIBUTES); + } + + /** Set the name of the Module */ + public void setModuleName(String moduleName) { + setAttribute(MODULE_NAME, moduleName); + } + + /** Get the name of the Module */ + public String getModuleName() { + return (String) getAttribute(MODULE_NAME); + } + + /** Get the count of modules */ + public String getModuleCount() { + return (String) getAttribute(MODULE_COUNT); + } + + /** Set the count of modules */ + public void setModuleCount(String moduleName) { + setAttribute(MODULE_COUNT, moduleName); + } + + /** Get the start time in msecs */ + public Long getStartTime() { + return (Long) getAttribute(MODULE_START_TIME); + } + + /** Set the start time in msecs */ + public void setStartTime(Long startTime) { + setAttribute(MODULE_START_TIME, startTime); + } + + /** Get the end time in msecs */ + public Long getEndTime() { + return (Long) getAttribute(MODULE_END_TIME); + } + + /** Set the end time in msecs */ + public void setEndTime(Long endTime) { + setAttribute(MODULE_END_TIME, endTime); + } + + /** + * Get the module loading time in msecs If the start or end time is not present then return -1 + */ + public Long getModuleDuration() { + if (null != getAttribute(MODULE_DURATION)) { + return (Long) getAttribute(MODULE_DURATION); + } + if (null != getAttribute(MODULE_END_TIME) && null != getAttribute(MODULE_START_TIME)) { + long duration = getEndTime() - getStartTime(); + setModuleDuration(duration); + return duration; + } + return -1L; + } + + /** Get the duration in msec */ + public void setModuleDuration(Long duration) { + setAttribute(MODULE_DURATION, duration); + } + + @Override + public String toString() { + return "ModuleInfoItem [" + + "getModuleName()=" + + getModuleName() + + ", getStartTime()=" + + getStartTime() + + ", getDuration()=" + + getModuleDuration() + + "]"; + } +} diff --git a/src/com/android/loganalysis/parser/DmesgParser.java b/src/com/android/loganalysis/parser/DmesgParser.java index ffb6faa..53514d2 100644 --- a/src/com/android/loganalysis/parser/DmesgParser.java +++ b/src/com/android/loganalysis/parser/DmesgParser.java @@ -20,6 +20,7 @@ import com.android.loganalysis.item.DmesgActionInfoItem; import com.android.loganalysis.item.DmesgItem; import com.android.loganalysis.item.DmesgServiceInfoItem; import com.android.loganalysis.item.DmesgStageInfoItem; +import com.android.loganalysis.item.DmesgModuleInfoItem; import com.google.common.annotations.VisibleForTesting; @@ -44,6 +45,8 @@ public class DmesgParser implements IParser { private static final String DURATION = "DURATION"; private static final String UEVENTD = "ueventd"; private static final String INIT = "init"; + private static final String WAIT_PROPERTY = "Wait for property "; + private static final String TOTAL_MODULE = "TOTAL_MODULE"; // Matches: [ 14.822691] init: private static final String SERVICE_PREFIX = String.format("^\\[\\s+(?<%s>.*)\\] init:\\s+", @@ -82,14 +85,34 @@ public class DmesgParser implements IParser { private static final Pattern START_PROCESSING_ACTION = Pattern.compile(String.format("%s%s", SERVICE_PREFIX, START_PROCESSING_ACTION_PREFIX)); + // Matches: [ 1.175984] [ T1] init: Loaded 198 kernel modules took 808 ms + private static final Pattern MODULES_INFO = + Pattern.compile( + String.format( + "%sLoaded (?<count>\\d+) kernel modules took (?<%s>\\d+) ms.*$", + SERVICE_PREFIX, DURATION)); + + // Matches: [ 0.503853] [ T1] init: Loading module /lib/modules/exynos_dit.ko with args '' + private static final Pattern MODULE_LOADING = + Pattern.compile( + String.format( + "%sLoading module \\S+\\/(?<koname>\\S+)\\.ko with args.*", + SERVICE_PREFIX)); + + // Matches: [ 0.503803] [ T1] init: Loaded kernel module /lib/modules/boot_device_spi.ko + private static final Pattern MODULE_LOADED = + Pattern.compile( + String.format( + "%sLoaded kernel module \\S+\\/(?<koname>\\S+)\\.ko", SERVICE_PREFIX)); + // 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); private static final Pattern UEVENTD_STAGE_INFO = Pattern.compile( String.format("%s%s", UEVENTD_PREFIX, STAGE_SUFFIX)); - private static final String PROPERTY_SUFFIX= String.format( - "(?<%s>.*)\\s+took\\s+(?<%s>.*)ms$", STAGE, DURATION); + private static final String PROPERTY_SUFFIX = + String.format("Wait for property\\s(?<%s>.*)\\s+took\\s+(?<%s>.*)ms$", STAGE, DURATION); // Matches [ 7.270487] init: Wait for property 'apexd.status=ready' took 230ms private static final Pattern WAIT_FOR_PROPERTY_INFO = Pattern.compile( String.format("%s%s", SERVICE_PREFIX, PROPERTY_SUFFIX)); @@ -151,6 +174,9 @@ public class DmesgParser implements IParser { if (parseActionInfo(line)) { return; } + if (parseModuleInfo(line)) { + return; + } } /** @@ -214,7 +240,8 @@ public class DmesgParser implements IParser { } if((match = matches(WAIT_FOR_PROPERTY_INFO, line)) != null) { DmesgStageInfoItem stageInfoItem = new DmesgStageInfoItem(); - stageInfoItem.setStageName(String.format("%s_%s", INIT, match.group(STAGE))); + stageInfoItem.setStageName( + String.format("%s_%s%s", INIT, WAIT_PROPERTY, match.group(STAGE))); stageInfoItem.setDuration((long) Double.parseDouble(match.group(DURATION))); mDmesgItem.addStageInfoItem(stageInfoItem); return true; @@ -249,6 +276,44 @@ public class DmesgParser implements IParser { } /** + * Parse modules from each {@code line} of dmesg log and store the module name and loading time + * in {@link DmesgModuleInfoItem} object + * + * @param individual {@code line} of the dmesg log + * @return {@code true}, if {@code line} indicates start, end of a module loading or the summary + * {@code false}, otherwise + */ + @VisibleForTesting + boolean parseModuleInfo(String line) { + Matcher match = null; + if ((match = matches(MODULES_INFO, line)) != null) { + DmesgModuleInfoItem moduleInfoItem = new DmesgModuleInfoItem(); + moduleInfoItem.setModuleName(TOTAL_MODULE); + moduleInfoItem.setModuleDuration((long) Double.parseDouble(match.group(DURATION))); + moduleInfoItem.setModuleCount(match.group("count")); + mDmesgItem.addModuleInfoItem(TOTAL_MODULE, moduleInfoItem); + return true; + } + + if ((match = matches(MODULE_LOADING, line)) != null) { + DmesgModuleInfoItem moduleInfoItem = new DmesgModuleInfoItem(); + moduleInfoItem.setModuleName(match.group("koname")); + moduleInfoItem.setStartTime((long) (Double.parseDouble(match.group(TIMESTAMP)) * 1000)); + mDmesgItem.addModuleInfoItem(match.group("koname"), moduleInfoItem); + return true; + } else if ((match = matches(MODULE_LOADED, line)) != null) { + if (getModuleInfoItems().containsKey(match.group("koname"))) { + DmesgModuleInfoItem moduleInfoItem = + getModuleInfoItems().get(match.group("koname")); + moduleInfoItem.setEndTime( + (long) (Double.parseDouble(match.group(TIMESTAMP)) * 1000)); + } + return true; + } + return false; + } + + /** * Checks whether {@code line} matches the given {@link Pattern}. * * @return The resulting {@link Matcher} obtained by matching the {@code line} against @@ -277,4 +342,7 @@ public class DmesgParser implements IParser { return mDmesgItem.getActionInfoItems(); } + public Map<String, DmesgModuleInfoItem> getModuleInfoItems() { + return mDmesgItem.getModuleInfoItems(); + } }
\ No newline at end of file |