From 44e6c57bdf25abcf2b5b13cf958ed37eb55ae8a8 Mon Sep 17 00:00:00 2001 From: Netta Peterbursky Date: Tue, 23 May 2017 10:23:11 -0700 Subject: Add app versions to Bugreport parser (for event history view in stability dashboard). Bug: 38415015 Test: BugreportParserTest, DumpsysPackageStatsParserTest, DumpsysParserTest Change-Id: Id6e5ccbd39188be0b6908df751b310cd0f642593 --- .../android/loganalysis/item/AppVersionItem.java | 53 ++++ src/com/android/loganalysis/item/DumpsysItem.java | 25 +- .../loganalysis/item/DumpsysPackageStatsItem.java | 40 +++ .../parser/DumpsysPackageStatsParser.java | 75 +++++ .../android/loganalysis/parser/DumpsysParser.java | 5 + .../loganalysis/parser/BugreportParserTest.java | 325 +++++++++++---------- .../parser/DumpsysPackageStatsParserTest.java | 60 ++++ .../loganalysis/parser/DumpsysParserTest.java | 192 ++++++------ 8 files changed, 524 insertions(+), 251 deletions(-) create mode 100644 src/com/android/loganalysis/item/AppVersionItem.java create mode 100644 src/com/android/loganalysis/item/DumpsysPackageStatsItem.java create mode 100644 src/com/android/loganalysis/parser/DumpsysPackageStatsParser.java create mode 100644 tests/src/com/android/loganalysis/parser/DumpsysPackageStatsParserTest.java diff --git a/src/com/android/loganalysis/item/AppVersionItem.java b/src/com/android/loganalysis/item/AppVersionItem.java new file mode 100644 index 0000000..5c144f2 --- /dev/null +++ b/src/com/android/loganalysis/item/AppVersionItem.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2017 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 an app's version code and name. */ +public class AppVersionItem extends GenericItem { + + /** Constants for JSON output */ + public static final String VERSION_CODE = "VERSION_CODE"; + + public static final String VERSION_NAME = "VERSION_NAME"; + + private static final Set ATTRIBUTES = + new HashSet(Arrays.asList(VERSION_CODE, VERSION_NAME)); + + /** + * The constructor for {@link AppVersionItem} + * + * @param versionCode the version code + * @param versionName the version name + */ + public AppVersionItem(int versionCode, String versionName) { + super(ATTRIBUTES); + + setAttribute(VERSION_CODE, versionCode); + setAttribute(VERSION_NAME, versionName); + } + + public int getVersionCode() { + return (Integer) getAttribute(VERSION_CODE); + } + + public String getVersionName() { + return (String) getAttribute(VERSION_NAME); + } +} diff --git a/src/com/android/loganalysis/item/DumpsysItem.java b/src/com/android/loganalysis/item/DumpsysItem.java index 7f219bf..b66a82c 100644 --- a/src/com/android/loganalysis/item/DumpsysItem.java +++ b/src/com/android/loganalysis/item/DumpsysItem.java @@ -27,12 +27,15 @@ public class DumpsysItem extends GenericItem { /** Constant for JSON output */ private static final String BATTERY_STATS = "BATTERY_STATS"; /** Constant for JSON output */ + private static final String PACKAGE_STATS = "PACKAGE_STATS"; + /** Constant for JSON output */ private static final String PROC_STATS = "PROC_STATS"; /** Constant for JSON output */ private static final String WIFI_STATS = "WIFI_STATS"; - private static final Set ATTRIBUTES = new HashSet(Arrays.asList( - BATTERY_STATS, PROC_STATS, WIFI_STATS)); + private static final Set ATTRIBUTES = + new HashSet( + Arrays.asList(BATTERY_STATS, PACKAGE_STATS, PROC_STATS, WIFI_STATS)); /** * The constructor for {@link DumpsysItem}. @@ -48,9 +51,12 @@ public class DumpsysItem extends GenericItem { setAttribute(BATTERY_STATS, batteryStats); } - /** - * Set the {@link DumpsysProcStatsItem} of the bugreport. - */ + /** Set the {@link DumpsysPackageStatsItem} of the bugreport. */ + public void setPackageStats(DumpsysPackageStatsItem packageStats) { + setAttribute(PACKAGE_STATS, packageStats); + } + + /** Set the {@link DumpsysProcStatsItem} of the bugreport. */ public void setProcStats(DumpsysProcStatsItem procStats) { setAttribute(PROC_STATS, procStats); } @@ -69,9 +75,12 @@ public class DumpsysItem extends GenericItem { return (DumpsysBatteryStatsItem) getAttribute(BATTERY_STATS); } - /** - * Get the {@link DumpsysProcStatsItem} of the bugreport. - */ + /** Get the {@link DumpsysPackageStatsItem} of the bugreport. */ + public DumpsysPackageStatsItem getPackageStats() { + return (DumpsysPackageStatsItem) getAttribute(PACKAGE_STATS); + } + + /** Get the {@link DumpsysProcStatsItem} of the bugreport. */ public DumpsysProcStatsItem getProcStats() { return (DumpsysProcStatsItem) getAttribute(PROC_STATS); } diff --git a/src/com/android/loganalysis/item/DumpsysPackageStatsItem.java b/src/com/android/loganalysis/item/DumpsysPackageStatsItem.java new file mode 100644 index 0000000..14c4073 --- /dev/null +++ b/src/com/android/loganalysis/item/DumpsysPackageStatsItem.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2017 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 org.json.JSONException; +import org.json.JSONObject; + +/** An {@link IItem} used to store apps and their version codes and names. */ +public class DumpsysPackageStatsItem extends GenericMapItem { + private static final long serialVersionUID = 1L; + + /** Constant for JSON output */ + public static final String APP_VERSIONS = "APP_VERSIONS"; + + /** {@inheritDoc} */ + @Override + public JSONObject toJson() { + JSONObject object = new JSONObject(); + try { + object.put(APP_VERSIONS, super.toJson()); + } catch (JSONException e) { + // Ignore + } + return object; + } +} diff --git a/src/com/android/loganalysis/parser/DumpsysPackageStatsParser.java b/src/com/android/loganalysis/parser/DumpsysPackageStatsParser.java new file mode 100644 index 0000000..d06cfd5 --- /dev/null +++ b/src/com/android/loganalysis/parser/DumpsysPackageStatsParser.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2017 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.parser; + +import com.android.loganalysis.item.AppVersionItem; +import com.android.loganalysis.item.DumpsysPackageStatsItem; + +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** A {@link IParser} to parse package stats and create a mapping table of packages and versions */ +public class DumpsysPackageStatsParser implements IParser { + + /** Matches: Package [com.google.android.googlequicksearchbox] (607929e): */ + private static final Pattern PACKAGE_NAME = Pattern.compile("^\\s*Package \\[(.*)\\].*"); + + /** Matches: versionCode=300734793 minSdk=10000 targetSdk=10000 */ + private static final Pattern VERSION_CODE = Pattern.compile("^\\s*versionCode=(\\d+).*"); + + /** Matches: versionName=6.16.35.26.arm64 */ + private static final Pattern VERSION_NAME = Pattern.compile("^\\s*versionName=(.*)$"); + + /** + * {@inheritDoc} + * + * @return The {@link DumpsysPackageStatsItem}. + */ + @Override + public DumpsysPackageStatsItem parse(List lines) { + DumpsysPackageStatsItem item = new DumpsysPackageStatsItem(); + String packageName = null; + String versionCode = null; + String versionName = null; + + for (String line : lines) { + Matcher m = PACKAGE_NAME.matcher(line); + if (m.matches()) { + packageName = m.group(1); + versionCode = null; + versionName = null; + continue; + } + m = VERSION_CODE.matcher(line); + if (m.matches()) { + versionCode = m.group(1); + continue; + } + m = VERSION_NAME.matcher(line); + if (m.matches()) { + versionName = m.group(1).trim(); + if (packageName != null && versionCode != null) { + item.put( + packageName, + new AppVersionItem(Integer.parseInt(versionCode), versionName)); + } + packageName = null; + } + } + return item; + } +} diff --git a/src/com/android/loganalysis/parser/DumpsysParser.java b/src/com/android/loganalysis/parser/DumpsysParser.java index b74a86c..8c94e0b 100644 --- a/src/com/android/loganalysis/parser/DumpsysParser.java +++ b/src/com/android/loganalysis/parser/DumpsysParser.java @@ -18,6 +18,7 @@ package com.android.loganalysis.parser; import com.android.loganalysis.item.DumpsysBatteryStatsItem; import com.android.loganalysis.item.DumpsysItem; +import com.android.loganalysis.item.DumpsysPackageStatsItem; import com.android.loganalysis.item.DumpsysProcStatsItem; import com.android.loganalysis.item.DumpsysWifiStatsItem; @@ -29,11 +30,13 @@ import java.util.List; public class DumpsysParser extends AbstractSectionParser { private static final String BATTERY_STATS_SECTION_REGEX = "^DUMP OF SERVICE batterystats:$"; + private static final String PACKAGE_SECTION_REGEX = "^DUMP OF SERVICE package:"; private static final String PROC_STATS_SECTION_REGEX = "^DUMP OF SERVICE procstats:"; private static final String WIFI_SECTION_REGEX = "^DUMP OF SERVICE wifi:"; private static final String NOOP_SECTION_REGEX = "DUMP OF SERVICE .*"; private DumpsysBatteryStatsParser mBatteryStatsParser = new DumpsysBatteryStatsParser(); + private DumpsysPackageStatsParser mPackageStatsParser = new DumpsysPackageStatsParser(); private DumpsysProcStatsParser mProcStatsParser = new DumpsysProcStatsParser(); private DumpsysWifiStatsParser mWifiStatsParser = new DumpsysWifiStatsParser(); @@ -63,6 +66,7 @@ public class DumpsysParser extends AbstractSectionParser { */ protected void setup() { addSectionParser(mBatteryStatsParser, BATTERY_STATS_SECTION_REGEX); + addSectionParser(mPackageStatsParser, PACKAGE_SECTION_REGEX); addSectionParser(mProcStatsParser, PROC_STATS_SECTION_REGEX); addSectionParser(mWifiStatsParser, WIFI_SECTION_REGEX); addSectionParser(new NoopParser(), NOOP_SECTION_REGEX); @@ -80,6 +84,7 @@ public class DumpsysParser extends AbstractSectionParser { } if (mDumpsys != null) { mDumpsys.setBatteryInfo((DumpsysBatteryStatsItem) getSection(mBatteryStatsParser)); + mDumpsys.setPackageStats((DumpsysPackageStatsItem) getSection(mPackageStatsParser)); mDumpsys.setProcStats((DumpsysProcStatsItem) getSection(mProcStatsParser)); mDumpsys.setWifiStats((DumpsysWifiStatsItem) getSection(mWifiStatsParser)); } diff --git a/tests/src/com/android/loganalysis/parser/BugreportParserTest.java b/tests/src/com/android/loganalysis/parser/BugreportParserTest.java index b47ea22..4f40820 100644 --- a/tests/src/com/android/loganalysis/parser/BugreportParserTest.java +++ b/tests/src/com/android/loganalysis/parser/BugreportParserTest.java @@ -38,120 +38,128 @@ public class BugreportParserTest extends TestCase { * Test that a bugreport can be parsed. */ public void testParse() throws ParseException { - List lines = Arrays.asList( - "========================================================", - "== dumpstate: 2012-04-25 20:45:10", - "========================================================", - "------ SECTION ------", - "", - "------ MEMORY INFO (/proc/meminfo) ------", - "MemTotal: 353332 kB", - "MemFree: 65420 kB", - "Buffers: 20800 kB", - "Cached: 86204 kB", - "SwapCached: 0 kB", - "", - "------ CPU INFO (top -n 1 -d 1 -m 30 -t) ------", - "", - "User 3%, System 3%, IOW 0%, IRQ 0%", - "User 33 + Nice 0 + Sys 32 + Idle 929 + IOW 0 + IRQ 0 + SIRQ 0 = 994", - "", - "------ PROCRANK (procrank) ------", - " PID Vss Rss Pss Uss cmdline", - " 178 87136K 81684K 52829K 50012K system_server", - " 1313 78128K 77996K 48603K 45812K com.google.android.apps.maps", - " 3247 61652K 61492K 33122K 30972K com.android.browser", - " ------ ------ ------", - " 203624K 163604K TOTAL", - "RAM: 731448K total, 415804K free, 9016K buffers, 108548K cached", - "[procrank: 1.6s elapsed]", - "", - "------ KERNEL LOG (dmesg) ------", - "<6>[ 0.000000] Initializing cgroup subsys cpu", - "<3>[ 1.000000] benign message", - "", - "", - "------ SYSTEM LOG (logcat -v threadtime -d *:v) ------", - "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)", - "04-25 17:17:08.445 312 366 E ActivityManager: ANR (application not responding) in process: com.android.package", - "04-25 17:17:08.445 312 366 E ActivityManager: Reason: keyDispatchingTimedOut", - "04-25 17:17:08.445 312 366 E ActivityManager: Load: 0.71 / 0.83 / 0.51", - "04-25 17:17:08.445 312 366 E ActivityManager: 33% TOTAL: 21% user + 11% kernel + 0.3% iowait", - "04-25 18:33:27.273 115 115 I DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***", - "04-25 18:33:27.273 115 115 I DEBUG : Build fingerprint: 'product:build:target'", - "04-25 18:33:27.273 115 115 I DEBUG : pid: 3112, tid: 3112 >>> com.google.android.browser <<<", - "04-25 18:33:27.273 115 115 I DEBUG : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000", - "", - "------ SYSTEM PROPERTIES ------", - "[dalvik.vm.dexopt-flags]: [m=y]", - "[dalvik.vm.heapgrowthlimit]: [48m]", - "[dalvik.vm.heapsize]: [256m]", - "[gsm.version.ril-impl]: [android moto-ril-multimode 1.0]", - "", - "------ LAST KMSG (/proc/last_kmsg) ------", - "[ 0.000000] Initializing cgroup subsys cpu", - "[ 16.203491] benign message", - "", - "------ SECTION ------", - "", - "------ VM TRACES AT LAST ANR (/data/anr/traces.txt: 2012-04-25 17:17:08) ------", - "", - "", - "----- pid 2887 at 2012-04-25 17:17:08 -----", - "Cmd line: com.android.package", - "", - "DALVIK THREADS:", - "(mutexes: tll=0 tsl=0 tscl=0 ghl=0)", - "", - "\"main\" prio=5 tid=1 SUSPENDED", - " | group=\"main\" sCount=1 dsCount=0 obj=0x00000001 self=0x00000001", - " | sysTid=2887 nice=0 sched=0/0 cgrp=foreground handle=0000000001", - " | schedstat=( 0 0 0 ) utm=5954 stm=1017 core=0", - " at class.method1(Class.java:1)", - " at class.method2(Class.java:2)", - " at class.method2(Class.java:2)", - "", - "----- end 2887 -----", - "", - "------ SECTION ------", - "", - "------ DUMPSYS (dumpsys) ------", - "DUMP OF SERVICE batterystats:", - "Battery History (0% used, 1636 used of 256KB, 15 strings using 794):", - " 0 (15) RESET:TIME: 1970-01-10-06-23-28", - " +45s702ms (2) 001 80080000 volt=4187", - " +1m15s525ms (2) 001 80080000 temp=299 volt=4155", - "Statistics since last charged:", - " Time on battery: 1h 5m 2s 4ms (9%) realtime, 1h 5m 2s 4ms (9%) uptime", - " Time on battery screen off: 1h 4m 5s 8ms (9%) realtime, 1h 4m 5s 8ms (9%) uptime", - " All kernel wake locks:", - " Kernel Wake lock PowerManagerService.WakeLocks: 5m 10s 6ms (2 times) realtime", - " Kernel Wake lock msm_serial_hs_rx: 2m 13s 612ms (258 times) realtime", - "", - " All partial wake locks:", - " Wake lock 1001 ProxyController: 1h 4m 47s 565ms (4 times) realtime", - " Wake lock 1013 AudioMix: 1s 979ms (3 times) realtime", - "", - " All wakeup reasons:", - " Wakeup reason 2:bcmsdh_sdmmc:2:qcom,smd:2:msmgio: 1m 5s 4ms (2 times) realtime", - " Wakeup reason 2:qcom,smd-rpm:2:fc4c.qcom,spmi: 7m 1s 914ms (7 times) realtime", - "", - "========================================================", - "== Running Application Services", - "========================================================", - "------ APP SERVICES (dumpsys activity service all) ------", - "SERVICE com.google.android.gms/" - + "com.google.android.location.internal.GoogleLocationManagerService f4c9d pid=14", - " Location Request History By Package:", - "Interval effective/min/max 1/0/0[s] Duration: 140[minutes] [" - + "com.google.android.gms, PRIORITY_NO_POWER, UserLocationProducer] " - + "Num requests: 2 Active: true", - "Interval effective/min/max 284/285/3600[s] Duration: 140[minutes] " - + "[com.google.android.googlequicksearchbox, PRIORITY_BALANCED_POWER_ACCURACY] " - + "Num requests: 5 Active: true"); + List lines = + Arrays.asList( + "========================================================", + "== dumpstate: 2012-04-25 20:45:10", + "========================================================", + "------ SECTION ------", + "", + "------ MEMORY INFO (/proc/meminfo) ------", + "MemTotal: 353332 kB", + "MemFree: 65420 kB", + "Buffers: 20800 kB", + "Cached: 86204 kB", + "SwapCached: 0 kB", + "", + "------ CPU INFO (top -n 1 -d 1 -m 30 -t) ------", + "", + "User 3%, System 3%, IOW 0%, IRQ 0%", + "User 33 + Nice 0 + Sys 32 + Idle 929 + IOW 0 + IRQ 0 + SIRQ 0 = 994", + "", + "------ PROCRANK (procrank) ------", + " PID Vss Rss Pss Uss cmdline", + " 178 87136K 81684K 52829K 50012K system_server", + " 1313 78128K 77996K 48603K 45812K com.google.android.apps.maps", + " 3247 61652K 61492K 33122K 30972K com.android.browser", + " ------ ------ ------", + " 203624K 163604K TOTAL", + "RAM: 731448K total, 415804K free, 9016K buffers, 108548K cached", + "[procrank: 1.6s elapsed]", + "", + "------ KERNEL LOG (dmesg) ------", + "<6>[ 0.000000] Initializing cgroup subsys cpu", + "<3>[ 1.000000] benign message", + "", + "", + "------ SYSTEM LOG (logcat -v threadtime -d *:v) ------", + "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)", + "04-25 17:17:08.445 312 366 E ActivityManager: ANR (application not responding) in process: com.android.package", + "04-25 17:17:08.445 312 366 E ActivityManager: Reason: keyDispatchingTimedOut", + "04-25 17:17:08.445 312 366 E ActivityManager: Load: 0.71 / 0.83 / 0.51", + "04-25 17:17:08.445 312 366 E ActivityManager: 33% TOTAL: 21% user + 11% kernel + 0.3% iowait", + "04-25 18:33:27.273 115 115 I DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***", + "04-25 18:33:27.273 115 115 I DEBUG : Build fingerprint: 'product:build:target'", + "04-25 18:33:27.273 115 115 I DEBUG : pid: 3112, tid: 3112 >>> com.google.android.browser <<<", + "04-25 18:33:27.273 115 115 I DEBUG : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000", + "", + "------ SYSTEM PROPERTIES ------", + "[dalvik.vm.dexopt-flags]: [m=y]", + "[dalvik.vm.heapgrowthlimit]: [48m]", + "[dalvik.vm.heapsize]: [256m]", + "[gsm.version.ril-impl]: [android moto-ril-multimode 1.0]", + "", + "------ LAST KMSG (/proc/last_kmsg) ------", + "[ 0.000000] Initializing cgroup subsys cpu", + "[ 16.203491] benign message", + "", + "------ SECTION ------", + "", + "------ VM TRACES AT LAST ANR (/data/anr/traces.txt: 2012-04-25 17:17:08) ------", + "", + "", + "----- pid 2887 at 2012-04-25 17:17:08 -----", + "Cmd line: com.android.package", + "", + "DALVIK THREADS:", + "(mutexes: tll=0 tsl=0 tscl=0 ghl=0)", + "", + "\"main\" prio=5 tid=1 SUSPENDED", + " | group=\"main\" sCount=1 dsCount=0 obj=0x00000001 self=0x00000001", + " | sysTid=2887 nice=0 sched=0/0 cgrp=foreground handle=0000000001", + " | schedstat=( 0 0 0 ) utm=5954 stm=1017 core=0", + " at class.method1(Class.java:1)", + " at class.method2(Class.java:2)", + " at class.method2(Class.java:2)", + "", + "----- end 2887 -----", + "", + "------ SECTION ------", + "", + "------ DUMPSYS (dumpsys) ------", + "DUMP OF SERVICE batterystats:", + "Battery History (0% used, 1636 used of 256KB, 15 strings using 794):", + " 0 (15) RESET:TIME: 1970-01-10-06-23-28", + " +45s702ms (2) 001 80080000 volt=4187", + " +1m15s525ms (2) 001 80080000 temp=299 volt=4155", + "Statistics since last charged:", + " Time on battery: 1h 5m 2s 4ms (9%) realtime, 1h 5m 2s 4ms (9%) uptime", + " Time on battery screen off: 1h 4m 5s 8ms (9%) realtime, 1h 4m 5s 8ms (9%) uptime", + " All kernel wake locks:", + " Kernel Wake lock PowerManagerService.WakeLocks: 5m 10s 6ms (2 times) realtime", + " Kernel Wake lock msm_serial_hs_rx: 2m 13s 612ms (258 times) realtime", + "", + " All partial wake locks:", + " Wake lock 1001 ProxyController: 1h 4m 47s 565ms (4 times) realtime", + " Wake lock 1013 AudioMix: 1s 979ms (3 times) realtime", + "", + " All wakeup reasons:", + " Wakeup reason 2:bcmsdh_sdmmc:2:qcom,smd:2:msmgio: 1m 5s 4ms (2 times) realtime", + " Wakeup reason 2:qcom,smd-rpm:2:fc4c.qcom,spmi: 7m 1s 914ms (7 times) realtime", + "", + "DUMP OF SERVICE package:", + "Package [com.google.android.calculator] (e075c9d):", + " userId=10071", + " secondaryCpuAbi=null", + " versionCode=73000302 minSdk=10000 targetSdk=10000", + " versionName=7.3 (3821978)", + " splits=[base]", + "========================================================", + "== Running Application Services", + "========================================================", + "------ APP SERVICES (dumpsys activity service all) ------", + "SERVICE com.google.android.gms/" + + "com.google.android.location.internal.GoogleLocationManagerService f4c9d pid=14", + " Location Request History By Package:", + "Interval effective/min/max 1/0/0[s] Duration: 140[minutes] [" + + "com.google.android.gms, PRIORITY_NO_POWER, UserLocationProducer] " + + "Num requests: 2 Active: true", + "Interval effective/min/max 284/285/3600[s] Duration: 140[minutes] " + + "[com.google.android.googlequicksearchbox, PRIORITY_BALANCED_POWER_ACCURACY] " + + "Num requests: 5 Active: true"); BugreportItem bugreport = new BugreportParser().parse(lines); assertNotNull(bugreport); @@ -184,6 +192,7 @@ public class BugreportParserTest extends TestCase { assertNotNull(bugreport.getDumpsys()); assertNotNull(bugreport.getDumpsys().getBatteryStats()); + assertNotNull(bugreport.getDumpsys().getPackageStats()); assertNotNull(bugreport.getActivityService()); assertNotNull(bugreport.getActivityService().getLocationDumps().getLocationClients()); @@ -546,48 +555,57 @@ public class BugreportParserTest extends TestCase { * Test that section headers are correctly parsed. */ public void testSectionHeader() { - List lines = Arrays.asList( - "========================================================", - "== dumpstate: 2012-04-25 20:45:10", - "========================================================", - "------ DUMPSYS (dumpsys) ------", - "DUMP OF SERVICE SurfaceFlinger:", - "--DrmDisplayCompositor[0]: num_frames=1456 num_ms=475440 fps=3.06243", - "---- DrmDisplayCompositor Layers: num=3", - "------ DrmDisplayCompositor Layer: plane=17 crtc=20 crtc[x/y/w/h]=0/0/2560/1800", - "------ DrmDisplayCompositor Layer: plane=21 disabled", - "------ DrmDisplayCompositor Layer: plane=22 disabled", - "DUMP OF SERVICE batterystats:", - "Battery History (0% used, 1636 used of 256KB, 15 strings using 794):", - " 0 (15) RESET:TIME: 1970-01-10-06-23-28", - " +45s702ms (2) 001 80080000 volt=4187", - " +1m15s525ms (2) 001 80080000 temp=299 volt=4155", - "Statistics since last charged:", - " Time on battery: 1h 5m 2s 4ms (9%) realtime, 1h 5m 2s 4ms (9%) uptime", - " Time on battery screen off: 1h 4m 5s 8ms (9%) realtime, 1h 4m 5s 8ms (9%) uptime", - " All kernel wake locks:", - " Kernel Wake lock PowerManagerService.WakeLocks: 5m 10s 6ms (2 times) realtime", - " Kernel Wake lock msm_serial_hs_rx: 2m 13s 612ms (258 times) realtime", - "", - " All partial wake locks:", - " Wake lock 1001 ProxyController: 1h 4m 47s 565ms (4 times) realtime", - " Wake lock 1013 AudioMix: 1s 979ms (3 times) realtime", - "", - " All wakeup reasons:", - " Wakeup reason 2:bcmsdh_sdmmc:2:qcom,smd:2:msmgio: 1m 5s 4ms (2 times) realtime", - " Wakeup reason 2:qcom,smd-rpm:2:fc4c.qcom,spmi: 7m 1s 914ms (7 times) realtime", - "DUMP OF SERVICE procstats:", - "COMMITTED STATS FROM 2015-09-30-07-44-54:", - " * system / 1000 / v23:", - " TOTAL: 100% (118MB-118MB-118MB/71MB-71MB-71MB over 1)", - " Persistent: 100% (118MB-118MB-118MB/71MB-71MB-71MB over 1)", - " * com.android.phone / 1001 / v23:", - " TOTAL: 6.7%", - " Persistent: 6.7%", - ""); + List lines = + Arrays.asList( + "========================================================", + "== dumpstate: 2012-04-25 20:45:10", + "========================================================", + "------ DUMPSYS (dumpsys) ------", + "DUMP OF SERVICE SurfaceFlinger:", + "--DrmDisplayCompositor[0]: num_frames=1456 num_ms=475440 fps=3.06243", + "---- DrmDisplayCompositor Layers: num=3", + "------ DrmDisplayCompositor Layer: plane=17 crtc=20 crtc[x/y/w/h]=0/0/2560/1800", + "------ DrmDisplayCompositor Layer: plane=21 disabled", + "------ DrmDisplayCompositor Layer: plane=22 disabled", + "DUMP OF SERVICE batterystats:", + "Battery History (0% used, 1636 used of 256KB, 15 strings using 794):", + " 0 (15) RESET:TIME: 1970-01-10-06-23-28", + " +45s702ms (2) 001 80080000 volt=4187", + " +1m15s525ms (2) 001 80080000 temp=299 volt=4155", + "Statistics since last charged:", + " Time on battery: 1h 5m 2s 4ms (9%) realtime, 1h 5m 2s 4ms (9%) uptime", + " Time on battery screen off: 1h 4m 5s 8ms (9%) realtime, 1h 4m 5s 8ms (9%) uptime", + " All kernel wake locks:", + " Kernel Wake lock PowerManagerService.WakeLocks: 5m 10s 6ms (2 times) realtime", + " Kernel Wake lock msm_serial_hs_rx: 2m 13s 612ms (258 times) realtime", + "", + " All partial wake locks:", + " Wake lock 1001 ProxyController: 1h 4m 47s 565ms (4 times) realtime", + " Wake lock 1013 AudioMix: 1s 979ms (3 times) realtime", + "", + " All wakeup reasons:", + " Wakeup reason 2:bcmsdh_sdmmc:2:qcom,smd:2:msmgio: 1m 5s 4ms (2 times) realtime", + " Wakeup reason 2:qcom,smd-rpm:2:fc4c.qcom,spmi: 7m 1s 914ms (7 times) realtime", + "DUMP OF SERVICE package:", + "Package [com.google.android.calculator] (e075c9d):", + " use rId=10071", + " secondaryCpuAbi=null", + " versionCode=73000302 minSdk=10000 targetSdk=10000", + " versionName=7.3 (3821978)", + " splits=[base]", + "DUMP OF SERVICE procstats:", + "COMMITTED STATS FROM 2015-09-30-07-44-54:", + " * system / 1000 / v23:", + " TOTAL: 100% (118MB-118MB-118MB/71MB-71MB-71MB over 1)", + " Persistent: 100% (118MB-118MB-118MB/71MB-71MB-71MB over 1)", + " * com.android.phone / 1001 / v23:", + " TOTAL: 6.7%", + " Persistent: 6.7%", + ""); BugreportItem bugreport = new BugreportParser().parse(lines); assertNotNull(bugreport.getDumpsys()); assertNotNull(bugreport.getDumpsys().getBatteryStats()); + assertNotNull(bugreport.getDumpsys().getPackageStats()); assertNotNull(bugreport.getDumpsys().getProcStats()); } @@ -673,4 +691,3 @@ public class BugreportParserTest extends TestCase { return formatter.parse(timeStr); } } - diff --git a/tests/src/com/android/loganalysis/parser/DumpsysPackageStatsParserTest.java b/tests/src/com/android/loganalysis/parser/DumpsysPackageStatsParserTest.java new file mode 100644 index 0000000..faa51b2 --- /dev/null +++ b/tests/src/com/android/loganalysis/parser/DumpsysPackageStatsParserTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2017 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.parser; + +import com.android.loganalysis.item.DumpsysPackageStatsItem; +import com.android.loganalysis.item.AppVersionItem; + +import junit.framework.TestCase; + +import java.util.Arrays; +import java.util.List; + +/** Unit tests for {@link DumpsysPackageStatsParser} */ +public class DumpsysPackageStatsParserTest extends TestCase { + + /** Test that normal input is parsed. */ + public void testDumpsysPackageStatsParser() { + List inputBlock = + Arrays.asList( + "DUMP OF SERVICE package:", + "Package [com.google.android.calculator] (e075c9d):", + " userId=10071", + " secondaryCpuAbi=null", + " versionCode=73000302 minSdk=10000 targetSdk=10000", + " versionName=7.3 (3821978)", + " splits=[base]", + " Package [com.google.android.googlequicksearchbox] (607929e):", + " userId=10037", + " pkg=Package{af43294 com.google.android.googlequicksearchbox}", + " versionCode=300734793 minSdk=10000 targetSdk=10000", + " versionName=6.16.35.26.arm64", + " apkSigningVersion=2"); + + final DumpsysPackageStatsItem packagestats = + new DumpsysPackageStatsParser().parse(inputBlock); + assertEquals(2, packagestats.size()); + assertNotNull(packagestats.get("com.google.android.calculator")); + final AppVersionItem calculator = packagestats.get("com.google.android.calculator"); + assertEquals(73000302, calculator.getVersionCode()); + assertEquals("7.3 (3821978)", calculator.getVersionName()); + assertNotNull(packagestats.get("com.google.android.googlequicksearchbox")); + final AppVersionItem googlequicksearchbox = + packagestats.get("com.google.android.googlequicksearchbox"); + assertEquals(300734793, googlequicksearchbox.getVersionCode()); + assertEquals("6.16.35.26.arm64", googlequicksearchbox.getVersionName()); + } +} diff --git a/tests/src/com/android/loganalysis/parser/DumpsysParserTest.java b/tests/src/com/android/loganalysis/parser/DumpsysParserTest.java index a722ac6..020c724 100644 --- a/tests/src/com/android/loganalysis/parser/DumpsysParserTest.java +++ b/tests/src/com/android/loganalysis/parser/DumpsysParserTest.java @@ -31,99 +31,113 @@ public class DumpsysParserTest extends TestCase { * Test that normal input is parsed. */ public void testDumpsysParser() { - List inputBlock = Arrays.asList( - "DUMP OF SERVICE batterystats:", - "Battery History (37% used, 95KB used of 256KB, 166 strings using 15KB):", - " 0 (9) RESET:TIME: 2014-12-09-11-33-29", - " +1s067ms (1) 100 c0500020 -wifi_full_lock -wifi_scan", - " +3s297ms (2) 100 80400020 -wake_lock -screen", - " +30m02s075ms (1) 100 c0500020 wifi_signal_strength=4 wifi_suppl=completed", - " +30m03s012ms (2) 099 c0500020 temp=306 volt=4217", - " +33m48s967ms (1) 099 f8400020 +wifi_scan", - " +33m49s335ms (2) 098 f0400020 temp=324 -wifi_scan", - "Statistics since last charge:", - " Time on battery: 2h 21m 5s 622ms (12.0%) realtime, 7m 54s 146ms (0.7%) uptime", - " Time on battery screen off: 2h 5m 55s 3ms (1%) realtime, 7m 4s 5ms (7%) uptime", - " Total run time: 19h 38m 43s 650ms realtime, 17h 25m 32s 175ms uptime", - " All kernel wake locks:", - " Kernel Wake lock PowerManagerService.WakeLocks: 1h 3m 50s 5ms (8 times) realtime", - " Kernel Wake lock event0-2656 : 3m 49s 268ms (2399 times) realtime", - " Kernel Wake lock wlan_wd_wake: 3m 34s 639ms (1751 times) realtime", - " Kernel Wake lock wlan_rx_wake: 3m 19s 887ms (225 times) realtime", - " Kernel Wake lock wlan_tx_wake: 2m 19s 887ms (225 times) realtime", - " Kernel Wake lock tx_wake: 1m 19s 887ms (225 times) realtime", - " ", - " All partial wake locks:", - " Wake lock u0a7 NlpWakeLock: 8m 13s 203ms (1479 times) realtime", - " Wake lock u0a7 NlpCollectorWakeLock: 6m 29s 18ms (238 times) realtime", - " Wake lock u0a7 GCM_CONN_ALARM: 6m 8s 587ms (239 times) realtime", - " Wake lock 1000 *alarm*: 5m 11s 316ms (1469 times) realtime", - " Wake lock u10 xxx: 4m 11s 316ms (1469 times) realtime", - " Wake lock u30 cst: 2m 11s 316ms (1469 times) realtime", - " ", - " All wakeup reasons:", - " Wakeup reason 200:qcom,smd-rpm:222:fc4: 11m 49s 332ms (0 times) realtime", - " Wakeup reason 200:qcom,smd-rpm: 48s 45ms (0 times) realtime", - " Wakeup reason 2:qcom,smd-rpm:2:f0.qm,mm:22:fc4mi: 3s 417ms (0 times) realtime", - " Wakeup reason 188:qcom,smd-adsp:200:qcom,smd-rpm: 1s 656ms (0 times) realtime", - " Wakeup reason 58:qcom,smsm-modem:2:qcom,smd-rpm: 6m 16s 1ms (5 times) realtime", - " Wakeup reason 57:qcom,smd-modem:200:qcom,smd-rpm: 40s 995ms (0 times) realtime", - " Wakeup reason unknown: 8s 455ms (0 times) realtime", - " Wakeup reason 9:bcmsdh_sdmmc:2:qcomd-rpm:240:mso: 8m 5s 9ms (0 times) realtime", - " ", - " 0:", - " User activity: 2 other", - " Wake lock SCREEN_FROZEN realtime", - " Sensor 0: 9s 908ms realtime (1 times)", - " Sensor 1: 9s 997ms realtime (1 times)", - " Foreground for: 2h 21m 5s 622ms", - " Apk android:", - " 24 wakeup alarms", - " u0a9:", - " Mobile network: 8.1KB received, 1.6KB sent (packets 291 received, 342 sent)", - " Mobile radio active: 3m 43s 890ms (34.2%) 39x @ 354 mspp", - " Sensor 2: 12m 13s 15ms realtime (5 times)", - " Sensor 32: (not used)", - " Sensor 35: (not used)", - "DUMP OF SERVICE procstats:", - "COMMITTED STATS FROM 2015-03-20-02-01-02 (checked in):", - " * com.android.systemui / u0a22 / v22:", - " TOTAL: 100% (159MB-160MB-161MB/153MB-153MB-154MB over 13)", - " Persistent: 100% (159MB-160MB-161MB/153MB-153MB-154MB over 13)", - " * com.google.process.gapps / u0a9 / v22:", - " TOTAL: 100% (22MB-24MB-25MB/18MB-19MB-20MB over 13)", - " Imp Fg: 100% (22MB-24MB-25MB/18MB-19MB-20MB over 13)", - "DUMP OF SERVICE wifi:", - "Wi-Fi is enabled", - "rec[0]: time=10-09 00:25:16.737 processed=DefaultState org=DeviceActiveState " - + "dest= what=155654(0x26006)", - "mScreenOff true", - " rec[0]: time=10-08 16:49:55.034 processed=WatchdogEnabledState org=OnlineState " - + "dest=OnlineWatchState what=135170(0x21002)", - "rec[30]: time=10-08 13:06:50.379 processed=DriverStartedState org=ConnectedState " - + "dest= what=131143(0x20047) (1)CMD_START_SCAN rt=4720806/7884852 10013 51 " - + "ic=0 proc(ms):14 onGoing full started:1444334810368,11 cnt=24 rssi=-127 f=-1 " - + "sc=0 link=-1 tx=1.5, 1.7, 0.0 rx=8.4 fiv=20000 [on:3266 tx:65 rx:556 " - + "period:1268] from screen [on:266962 period:266959]", - "rec[357]: time=10-08 13:10:13.199 processed=DriverStartedState org=ConnectedState " - + "dest= what=131143(0x20047) (-2)CMD_START_SCAN rt=4923625/8087671 10013 " - + "175 ic=0 proc(ms):2 onGoing full started:1444335011199,1999 cnt=24 rssi=-127 " - + "f=-1 sc=0 link=-1 tx=8.4, 1.7, 0.0 rx=6.7 fiv=20000 [on:0 tx:0 rx:0 period:990]" - + "from screen [on:467747 period:469779]", - "WifiConfigStore - Log Begin ----", - "10-08 11:09:14.653 - Event [IFNAME=wlan0 CTRL-EVENT-SCAN-STARTED ]", - "10-08 13:06:29.489 - Event [IFNAME=wlan0 CTRL-EVENT-DISCONNECTED " - + "bssid=9c:1c:12:c3:d0:72 reason=0]", - "10-08 13:06:22.280 - Event [IFNAME=wlan0 CTRL-EVENT-SCAN-STARTED ]", - "10-08 13:06:25.363 - Event [IFNAME=wlan0 CTRL-EVENT-SCAN-STARTED ]", - "10-08 13:08:15.018 - Event [IFNAME=wlan0 CTRL-EVENT-DISCONNECTED " - + "bssid=9c:1c:12:e8:72:d2 reason=3 locally_generated=1]", - "10-08 13:08:15.324 - wlan0: 442:IFNAME=wlan0 ENABLE_NETWORK 0 -> true"); + List inputBlock = + Arrays.asList( + "DUMP OF SERVICE batterystats:", + "Battery History (37% used, 95KB used of 256KB, 166 strings using 15KB):", + " 0 (9) RESET:TIME: 2014-12-09-11-33-29", + " +1s067ms (1) 100 c0500020 -wifi_full_lock -wifi_scan", + " +3s297ms (2) 100 80400020 -wake_lock -screen", + " +30m02s075ms (1) 100 c0500020 wifi_signal_strength=4 wifi_suppl=completed", + " +30m03s012ms (2) 099 c0500020 temp=306 volt=4217", + " +33m48s967ms (1) 099 f8400020 +wifi_scan", + " +33m49s335ms (2) 098 f0400020 temp=324 -wifi_scan", + "Statistics since last charge:", + " Time on battery: 2h 21m 5s 622ms (12.0%) realtime, 7m 54s 146ms (0.7%) uptime", + " Time on battery screen off: 2h 5m 55s 3ms (1%) realtime, 7m 4s 5ms (7%) uptime", + " Total run time: 19h 38m 43s 650ms realtime, 17h 25m 32s 175ms uptime", + " All kernel wake locks:", + " Kernel Wake lock PowerManagerService.WakeLocks: 1h 3m 50s 5ms (8 times) realtime", + " Kernel Wake lock event0-2656 : 3m 49s 268ms (2399 times) realtime", + " Kernel Wake lock wlan_wd_wake: 3m 34s 639ms (1751 times) realtime", + " Kernel Wake lock wlan_rx_wake: 3m 19s 887ms (225 times) realtime", + " Kernel Wake lock wlan_tx_wake: 2m 19s 887ms (225 times) realtime", + " Kernel Wake lock tx_wake: 1m 19s 887ms (225 times) realtime", + " ", + " All partial wake locks:", + " Wake lock u0a7 NlpWakeLock: 8m 13s 203ms (1479 times) realtime", + " Wake lock u0a7 NlpCollectorWakeLock: 6m 29s 18ms (238 times) realtime", + " Wake lock u0a7 GCM_CONN_ALARM: 6m 8s 587ms (239 times) realtime", + " Wake lock 1000 *alarm*: 5m 11s 316ms (1469 times) realtime", + " Wake lock u10 xxx: 4m 11s 316ms (1469 times) realtime", + " Wake lock u30 cst: 2m 11s 316ms (1469 times) realtime", + " ", + " All wakeup reasons:", + " Wakeup reason 200:qcom,smd-rpm:222:fc4: 11m 49s 332ms (0 times) realtime", + " Wakeup reason 200:qcom,smd-rpm: 48s 45ms (0 times) realtime", + " Wakeup reason 2:qcom,smd-rpm:2:f0.qm,mm:22:fc4mi: 3s 417ms (0 times) realtime", + " Wakeup reason 188:qcom,smd-adsp:200:qcom,smd-rpm: 1s 656ms (0 times) realtime", + " Wakeup reason 58:qcom,smsm-modem:2:qcom,smd-rpm: 6m 16s 1ms (5 times) realtime", + " Wakeup reason 57:qcom,smd-modem:200:qcom,smd-rpm: 40s 995ms (0 times) realtime", + " Wakeup reason unknown: 8s 455ms (0 times) realtime", + " Wakeup reason 9:bcmsdh_sdmmc:2:qcomd-rpm:240:mso: 8m 5s 9ms (0 times) realtime", + " ", + " 0:", + " User activity: 2 other", + " Wake lock SCREEN_FROZEN realtime", + " Sensor 0: 9s 908ms realtime (1 times)", + " Sensor 1: 9s 997ms realtime (1 times)", + " Foreground for: 2h 21m 5s 622ms", + " Apk android:", + " 24 wakeup alarms", + " u0a9:", + " Mobile network: 8.1KB received, 1.6KB sent (packets 291 received, 342 sent)", + " Mobile radio active: 3m 43s 890ms (34.2%) 39x @ 354 mspp", + " Sensor 2: 12m 13s 15ms realtime (5 times)", + " Sensor 32: (not used)", + " Sensor 35: (not used)", + "DUMP OF SERVICE package:", + "Package [com.google.android.calculator] (e075c9d):", + " userId=10071", + " secondaryCpuAbi=null", + " versionCode=73000302 minSdk=10000 targetSdk=10000", + " versionName=7.3 (3821978)", + " splits=[base]", + "Package [com.google.android.googlequicksearchbox] (607929e):", + " userId=10037", + " pkg=Package{af43294 com.google.android.googlequicksearchbox}", + " versionCode=300734793 minSdk=10000 targetSdk=10000", + " versionName=6.16.35.26.arm64", + " apkSigningVersion=2", + "DUMP OF SERVICE procstats:", + "COMMITTED STATS FROM 2015-03-20-02-01-02 (checked in):", + " * com.android.systemui / u0a22 / v22:", + " TOTAL: 100% (159MB-160MB-161MB/153MB-153MB-154MB over 13)", + " Persistent: 100% (159MB-160MB-161MB/153MB-153MB-154MB over 13)", + " * com.google.process.gapps / u0a9 / v22:", + " TOTAL: 100% (22MB-24MB-25MB/18MB-19MB-20MB over 13)", + " Imp Fg: 100% (22MB-24MB-25MB/18MB-19MB-20MB over 13)", + "DUMP OF SERVICE wifi:", + "Wi-Fi is enabled", + "rec[0]: time=10-09 00:25:16.737 processed=DefaultState org=DeviceActiveState " + + "dest= what=155654(0x26006)", + "mScreenOff true", + " rec[0]: time=10-08 16:49:55.034 processed=WatchdogEnabledState org=OnlineState " + + "dest=OnlineWatchState what=135170(0x21002)", + "rec[30]: time=10-08 13:06:50.379 processed=DriverStartedState org=ConnectedState " + + "dest= what=131143(0x20047) (1)CMD_START_SCAN rt=4720806/7884852 10013 51 " + + "ic=0 proc(ms):14 onGoing full started:1444334810368,11 cnt=24 rssi=-127 f=-1 " + + "sc=0 link=-1 tx=1.5, 1.7, 0.0 rx=8.4 fiv=20000 [on:3266 tx:65 rx:556 " + + "period:1268] from screen [on:266962 period:266959]", + "rec[357]: time=10-08 13:10:13.199 processed=DriverStartedState org=ConnectedState " + + "dest= what=131143(0x20047) (-2)CMD_START_SCAN rt=4923625/8087671 10013 " + + "175 ic=0 proc(ms):2 onGoing full started:1444335011199,1999 cnt=24 rssi=-127 " + + "f=-1 sc=0 link=-1 tx=8.4, 1.7, 0.0 rx=6.7 fiv=20000 [on:0 tx:0 rx:0 period:990]" + + "from screen [on:467747 period:469779]", + "WifiConfigStore - Log Begin ----", + "10-08 11:09:14.653 - Event [IFNAME=wlan0 CTRL-EVENT-SCAN-STARTED ]", + "10-08 13:06:29.489 - Event [IFNAME=wlan0 CTRL-EVENT-DISCONNECTED " + + "bssid=9c:1c:12:c3:d0:72 reason=0]", + "10-08 13:06:22.280 - Event [IFNAME=wlan0 CTRL-EVENT-SCAN-STARTED ]", + "10-08 13:06:25.363 - Event [IFNAME=wlan0 CTRL-EVENT-SCAN-STARTED ]", + "10-08 13:08:15.018 - Event [IFNAME=wlan0 CTRL-EVENT-DISCONNECTED " + + "bssid=9c:1c:12:e8:72:d2 reason=3 locally_generated=1]", + "10-08 13:08:15.324 - wlan0: 442:IFNAME=wlan0 ENABLE_NETWORK 0 -> true"); DumpsysItem dumpsys = new DumpsysParser().parse(inputBlock); assertNotNull(dumpsys.getBatteryStats()); + assertNotNull(dumpsys.getPackageStats()); assertNotNull(dumpsys.getProcStats()); assertNotNull(dumpsys.getWifiStats()); } } - -- cgit v1.2.3 From 5011f40fdaf71f37a109bca97933e9df483908af Mon Sep 17 00:00:00 2001 From: Narayan Kamath Date: Mon, 12 Jun 2017 17:20:14 +0100 Subject: BugReportParserTest: Add a test case for new style traces. No implementation changes required, the regex is general enough to work in this case as well. Bug: 32064548 Test: java -classpath [...] junit.textui.TestRunner com.android.loganalysis.parser.BugreportParserTest Change-Id: I2c59eea446dfee92aa79c8dccc0f79b0d145e098 --- .../loganalysis/parser/BugreportParserTest.java | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/tests/src/com/android/loganalysis/parser/BugreportParserTest.java b/tests/src/com/android/loganalysis/parser/BugreportParserTest.java index 4f40820..5f3fc10 100644 --- a/tests/src/com/android/loganalysis/parser/BugreportParserTest.java +++ b/tests/src/com/android/loganalysis/parser/BugreportParserTest.java @@ -490,6 +490,79 @@ public class BugreportParserTest extends TestCase { assertNull(bugreport.getSystemLog().getAnrs().get(0).getTrace()); } + /** + * Add a test that ensures that the "new" style of stack dumping works. Traces aren't written to + * a global trace file. Instead, each ANR event is written to a separate trace file (note the + * "/data/anr/anr_4376042170248254515" instead of "/data/anr/traces.txt"). + */ + public void testAnrTraces_not_global_traceFile() { + List lines = + Arrays.asList( + "========================================================", + "== dumpstate: 2017-06-12 16:46:29", + "========================================================", + "------ SYSTEM LOG (logcat -v threadtime -v printable -v uid -d *:v) ------", + "--------- beginning of main ", + "02-18 04:26:31.829 logd 468 468 W auditd : type=2000 audit(0.0:1): initialized", + "02-18 04:26:33.783 logd 468 468 I auditd : type=1403 audit(0.0:2): policy loaded auid=4294967295 ses=4294967295", + "02-18 04:26:33.783 logd 468 468 W auditd : type=1404 audit(0.0:3): enforcing=1 old_enforcing=0 auid=4294967295 ses=4294967295", + "06-12 16:45:47.426 1000 1050 1124 E ActivityManager: ANR in com.example.android.helloactivity (com.example.android.helloactivity/.HelloActivity)", + "06-12 16:45:47.426 1000 1050 1124 E ActivityManager: PID: 7176", + "06-12 16:45:47.426 1000 1050 1124 E ActivityManager: Reason: Input dispatching timed out (Waiting because no window has focus but there is a focused application that may eventually add a window when it finishes starting up.)", + "06-12 16:45:47.426 1000 1050 1124 E ActivityManager: Load: 6.85 / 7.07 / 5.31", + "06-12 16:45:47.426 1000 1050 1124 E ActivityManager: CPU usage from 235647ms to 0ms ago (2017-06-12 16:41:49.415 to 2017-06-12 16:45:45.062):", + "06-12 16:45:47.426 1000 1050 1124 E ActivityManager: 7.7% 1848/com.ustwo.lwp: 4% user + 3.7% kernel / faults: 157 minor", + "06-12 16:45:47.426 1000 1050 1124 E ActivityManager: 7.7% 2536/com.google.android.googlequicksearchbox:search: 5.6% user + 2.1% kernel / faults: 195 minor", + "06-12 16:45:47.426 1000 1050 1124 E ActivityManager: 7.2% 1050/system_server: 4.5% user + 2.6% kernel / faults: 27117 minor ", + "06-12 16:45:47.426 1000 1050 1124 E ActivityManager: 5.3% 489/surfaceflinger: 2.9% user + 2.3% kernel / faults: 15 minor ", + "", + "------ VM TRACES AT LAST ANR (/data/anr/anr_4376042170248254515: 2017-06-12 16:45:47) ------", + "", + "----- pid 7176 at 2017-06-12 16:45:45 -----", + "Cmd line: com.example.android.helloactivity", + "", + "DALVIK THREADS:", + "(mutexes: tll=0 tsl=0 tscl=0 ghl=0)", + "", + "\"main\" daemon prio=5 tid=5 Waiting", + " | group=\"system\" sCount=1 dsCount=0 flags=1 obj=0x140805e8 self=0x7caf4bf400", + " | sysTid=7184 nice=4 cgrp=default sched=0/0 handle=0x7c9b4e44f0", + " | state=S schedstat=( 507031 579062 19 ) utm=0 stm=0 core=3 HZ=100", + " | stack=0x7c9b3e2000-0x7c9b3e4000 stackSize=1037KB", + " | held mutexes=", + " at java.lang.Object.wait(Native method)", + " - waiting on <0x0281f7b7> (a java.lang.Class)", + " at java.lang.Daemons$ReferenceQueueDaemon.runInternal(Daemons.java:178)", + " - locked <0x0281f7b7> (a java.lang.Class)", + " at java.lang.Daemons$Daemon.run(Daemons.java:103)", + " at java.lang.Thread.run(Thread.java:764)", + "", + "----- end 7176 -----"); + + // NOTE: The parser only extracts the main thread from the traces. + List expectedStack = + Arrays.asList( + "\"main\" daemon prio=5 tid=5 Waiting", + " | group=\"system\" sCount=1 dsCount=0 flags=1 obj=0x140805e8 self=0x7caf4bf400", + " | sysTid=7184 nice=4 cgrp=default sched=0/0 handle=0x7c9b4e44f0", + " | state=S schedstat=( 507031 579062 19 ) utm=0 stm=0 core=3 HZ=100", + " | stack=0x7c9b3e2000-0x7c9b3e4000 stackSize=1037KB", + " | held mutexes=", + " at java.lang.Object.wait(Native method)", + " - waiting on <0x0281f7b7> (a java.lang.Class)", + " at java.lang.Daemons$ReferenceQueueDaemon.runInternal(Daemons.java:178)", + " - locked <0x0281f7b7> (a java.lang.Class)", + " at java.lang.Daemons$Daemon.run(Daemons.java:103)", + " at java.lang.Thread.run(Thread.java:764)"); + + BugreportItem bugreport = new BugreportParser().parse(lines); + assertNotNull(bugreport.getSystemLog()); + assertEquals(1, bugreport.getSystemLog().getAnrs().size()); + assertEquals( + ArrayUtil.join("\n", expectedStack), + bugreport.getSystemLog().getAnrs().get(0).getTrace()); + } + /** * Test that missing sections in bugreport are set to {@code null}, not empty {@link IItem}s. */ -- cgit v1.2.3 From c72e8e31c48c06c9775365f8fe5837965cfe5e69 Mon Sep 17 00:00:00 2001 From: gopinath Date: Thu, 15 Jun 2017 18:37:48 -0700 Subject: Support parsing the boottime legacy log format (i.e processing actions) b/62394657 Test: OK (257 tests). Change-Id: Ib5f5f9db27426b1a334e3c05faa6eb183a2e2975 --- .../android/loganalysis/parser/DmesgParser.java | 22 ++++-- .../loganalysis/parser/DmesgParserTest.java | 83 +++++++++++----------- 2 files changed, 59 insertions(+), 46 deletions(-) diff --git a/src/com/android/loganalysis/parser/DmesgParser.java b/src/com/android/loganalysis/parser/DmesgParser.java index ce3d389..63026d4 100644 --- a/src/com/android/loganalysis/parser/DmesgParser.java +++ b/src/com/android/loganalysis/parser/DmesgParser.java @@ -71,13 +71,22 @@ public class DmesgParser implements IParser { private static final Pattern START_STAGE = Pattern.compile( String.format("%s%s", SERVICE_PREFIX, START_STAGE_PREFIX)); + // 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 = String.format( - "processing action \\((?<%s>.*)\\) from.*$", ACTION); + private static final String START_PROCESSING_ACTION_PREFIX_LEGACY = + String.format("processing action \\((?<%s>.*)\\).*$", ACTION); + + // 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: [ 14.942872] init: processing action (early-init) - 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( @@ -216,7 +225,8 @@ public class DmesgParser implements IParser { @VisibleForTesting boolean parseActionInfo(String line) { Matcher match = null; - if ((match = matches(START_PROCESSING_ACTION, line)) != null) { + if ((match = matches(START_PROCESSING_ACTION, line)) != null + || (match = matches(START_PROCESSING_ACTION_LEGACY, line)) != null) { DmesgActionInfoItem actionInfoItem = new DmesgActionInfoItem(); actionInfoItem.setActionName(match.group(ACTION)); actionInfoItem.setStartTime((long) (Double.parseDouble( diff --git a/tests/src/com/android/loganalysis/parser/DmesgParserTest.java b/tests/src/com/android/loganalysis/parser/DmesgParserTest.java index 7db2c49..20665ea 100644 --- a/tests/src/com/android/loganalysis/parser/DmesgParserTest.java +++ b/tests/src/com/android/loganalysis/parser/DmesgParserTest.java @@ -38,27 +38,30 @@ public class DmesgParserTest extends TestCase { private static final String BOOT_ANIMATION = "bootanim"; private static final String NETD = "netd"; - private static final String[] LINES = new String[] { - "[ 3.786943] ueventd: Coldboot took 0.701291 seconds", - "[ 22.962730] init: starting service 'bootanim'...", - "[ 23.252321] init: starting service 'netd'...", - "[ 29.331069] ipa-wan ipa_wwan_ioctl:1428 dev(rmnet_data0) register to IPA", - "[ 32.182592] ueventd: fixup /sys/devices/virtual/input/poll_delay 0 1004 660", - "[ 35.642666] SELinux: initialized (dev fuse, type fuse), uses genfs_contexts", - "[ 39.855818] init: Service 'bootanim' (pid 588) exited with status 0", - "[ 41.665818] init: init first stage started!", - "[ 44.942872] init: processing action (early-init) from (/init.rc:13)", - "[ 47.233446] init: processing action (set_mmap_rnd_bits) from (:0)", - "[ 47.240083] init: processing action (set_kptr_restrict) from (:0)", - "[ 47.245778] init: processing action (keychord_init) from (:0)", - "[ 52.361049] init: processing action (persist.sys.usb.config=* boot) from (:0)", - "[ 52.361108] init: processing action (enable_property_trigger) from (:0)", - "[ 52.361313] init: processing action (security.perf_harden=1) from (/init.rc:677)", - "[ 52.361495] init: processing action (ro.debuggable=1) from (/init.rc:700)", - "[ 59.331069] ipa-wan ipa_wwan_ioctl:1428 dev(rmnet_data0) register to IPA", - "[ 62.182592] ueventd: fixup /sys/devices/virtual/input/poll_delay 0 1004 660", - "[ 65.642666] SELinux: initialized (dev fuse, type fuse), uses genfs_contexts", - "[ 69.855818] init: Service 'bootanim' (pid 588) exited with status 0"}; + private static final String[] LINES = + new String[] { + "[ 3.786943] ueventd: Coldboot took 0.701291 seconds", + "[ 22.962730] init: starting service 'bootanim'...", + "[ 23.252321] init: starting service 'netd'...", + "[ 29.331069] ipa-wan ipa_wwan_ioctl:1428 dev(rmnet_data0) register to IPA", + "[ 32.182592] ueventd: fixup /sys/devices/virtual/input/poll_delay 0 1004 660", + "[ 35.642666] SELinux: initialized (dev fuse, type fuse), uses genfs_contexts", + "[ 39.855818] init: Service 'bootanim' (pid 588) exited with status 0", + "[ 41.665818] init: init first stage started!", + "[ 44.942872] init: processing action (early-init) from (/init.rc:13)", + "[ 47.233446] init: processing action (set_mmap_rnd_bits) from (:0)", + "[ 47.240083] init: processing action (set_kptr_restrict) from (:0)", + "[ 47.245778] init: processing action (keychord_init) from (:0)", + "[ 52.361049] init: processing action (persist.sys.usb.config=* boot) from (:0)", + "[ 52.361108] init: processing action (enable_property_trigger) from (:0)", + "[ 52.361313] init: processing action (security.perf_harden=1) from (/init.rc:677)", + "[ 52.361495] init: processing action (ro.debuggable=1) from (/init.rc:700)", + "[ 58.298293] init: processing action (sys.boot_completed=1)", + "[ 59.331069] ipa-wan ipa_wwan_ioctl:1428 dev(rmnet_data0) register to IPA", + "[ 62.182592] ueventd: fixup /sys/devices/virtual/input/poll_delay 0 1004 660", + "[ 65.642666] SELinux: initialized (dev fuse, type fuse), uses genfs_contexts", + "[ 69.855818] init: Service 'bootanim' (pid 588) exited with status 0" + }; private static final Map EXPECTED_SERVICE_INFO_ITEMS = getExpectedServiceInfoItems(); @@ -93,9 +96,9 @@ public class DmesgParserTest extends TestCase { assertEquals("Service info items list size should be 2", 2, dmesgParser.getServiceInfoItems().size()); - assertEquals("Stage info items list size should be 2", 2, + assertEquals("Stage info items list size should be 2",2, dmesgParser.getStageInfoItems().size()); - assertEquals("Action info items list size should be 8", 8, + assertEquals("Action info items list size should be 9",9, dmesgParser.getActionInfoItems().size()); assertEquals(EXPECTED_SERVICE_INFO_ITEMS, actualDmesgItem.getServiceInfoItems()); @@ -115,7 +118,7 @@ public class DmesgParserTest extends TestCase { dmesgParser.getServiceInfoItems().size()); assertEquals("Stage info items list size should be 2", 2, dmesgParser.getStageInfoItems().size()); - assertEquals("Action info items list size should be 8", 8, + assertEquals("Action info items list size should be 9",9, dmesgParser.getActionInfoItems().size()); } } @@ -198,35 +201,35 @@ public class DmesgParserTest extends TestCase { assertEquals(EXPECTED_STAGE_INFO_ITEMS, stageInfoItems); } - /** - * Test processing action start time logs - */ + /** Test processing action start time logs */ public void testCompleteActionInfo() { DmesgParser dmesgParser = new DmesgParser(); for (String line : LINES) { dmesgParser.parseActionInfo(line); } List actualActionInfoItems = dmesgParser.getActionInfoItems(); - assertEquals(8, actualActionInfoItems.size()); + assertEquals(9, actualActionInfoItems.size()); assertEquals(EXPECTED_ACTION_INFO_ITEMS, actualActionInfoItems); } private static List 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( + "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( + "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")))); } private static List getExpectedStageInfoItems() { -- cgit v1.2.3