1 /* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.loganalysis.parser; 17 18 19 import com.android.loganalysis.item.DumpsysBatteryStatsItem; 20 import com.android.loganalysis.item.DumpsysItem; 21 import com.android.loganalysis.item.DumpsysPackageStatsItem; 22 import com.android.loganalysis.item.DumpsysProcStatsItem; 23 import com.android.loganalysis.item.DumpsysWifiStatsItem; 24 25 import java.util.List; 26 27 /** 28 * A {@link IParser} to handle the output of the dumpsys section of the bugreport. 29 */ 30 public class DumpsysParser extends AbstractSectionParser { 31 32 private static final String BATTERY_STATS_SECTION_REGEX = "^DUMP OF SERVICE batterystats:$"; 33 private static final String PACKAGE_SECTION_REGEX = "^DUMP OF SERVICE package:"; 34 private static final String PROC_STATS_SECTION_REGEX = "^DUMP OF SERVICE procstats:"; 35 private static final String WIFI_SECTION_REGEX = "^DUMP OF SERVICE wifi:"; 36 private static final String NOOP_SECTION_REGEX = "DUMP OF SERVICE .*"; 37 38 private DumpsysBatteryStatsParser mBatteryStatsParser = new DumpsysBatteryStatsParser(); 39 private DumpsysPackageStatsParser mPackageStatsParser = new DumpsysPackageStatsParser(); 40 private DumpsysProcStatsParser mProcStatsParser = new DumpsysProcStatsParser(); 41 private DumpsysWifiStatsParser mWifiStatsParser = new DumpsysWifiStatsParser(); 42 43 private DumpsysItem mDumpsys = null; 44 45 /** 46 * {@inheritDoc} 47 * 48 * @return The {@link DumpsysItem} 49 */ 50 @Override parse(List<String> lines)51 public DumpsysItem parse(List<String> lines) { 52 setup(); 53 for (String line : lines) { 54 if (mDumpsys == null && !"".equals(line.trim())) { 55 mDumpsys = new DumpsysItem(); 56 } 57 parseLine(line); 58 } 59 commit(); 60 61 return mDumpsys; 62 } 63 64 /** 65 * Sets up the parser by adding the section parsers. 66 */ setup()67 protected void setup() { 68 addSectionParser(mBatteryStatsParser, BATTERY_STATS_SECTION_REGEX); 69 addSectionParser(mPackageStatsParser, PACKAGE_SECTION_REGEX); 70 addSectionParser(mProcStatsParser, PROC_STATS_SECTION_REGEX); 71 addSectionParser(mWifiStatsParser, WIFI_SECTION_REGEX); 72 addSectionParser(new NoopParser(), NOOP_SECTION_REGEX); 73 } 74 75 /** 76 * {@inheritDoc} 77 */ 78 @Override commit()79 protected void commit() { 80 // signal EOF 81 super.commit(); 82 if (mDumpsys == null) { 83 mDumpsys = new DumpsysItem(); 84 } 85 if (mDumpsys != null) { 86 mDumpsys.setBatteryInfo((DumpsysBatteryStatsItem) getSection(mBatteryStatsParser)); 87 mDumpsys.setPackageStats((DumpsysPackageStatsItem) getSection(mPackageStatsParser)); 88 mDumpsys.setProcStats((DumpsysProcStatsItem) getSection(mProcStatsParser)); 89 mDumpsys.setWifiStats((DumpsysWifiStatsItem) getSection(mWifiStatsParser)); 90 } 91 } 92 } 93