1 /* 2 * Copyright (C) 2015 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 import com.android.loganalysis.item.InterruptItem; 19 import com.android.loganalysis.item.InterruptItem.InterruptCategory; 20 21 import java.util.List; 22 import java.util.regex.Matcher; 23 import java.util.regex.Pattern; 24 25 /** 26 * A {@link IParser} to parse wake up interrupts 27 */ 28 public class InterruptParser implements IParser { 29 30 /** 31 * Matches: Wakeup reason 289:bcmsdh_sdmmc:200:qcom,smd-rpm:240:msmgpio: 32 * 20m 5s 194ms (1485 times) realtime 33 */ 34 private static final Pattern Interrupt = Pattern.compile( 35 "^\\s*Wakeup reason (.*): (?:\\d+h )?(?:\\d+m )?(?:\\d+s )(?:\\d+ms )" + 36 "\\((\\d+) times\\) realtime"); 37 38 private InterruptItem mItem = new InterruptItem(); 39 40 /** 41 * {@inheritDoc} 42 * 43 * @return The {@link InterruptItem}. 44 */ 45 @Override 46 public InterruptItem parse(List<String> lines) { 47 for (String line : lines) { 48 Matcher m = Interrupt.matcher(line); 49 if(m.matches()) { 50 final String interruptName = m.group(1); 51 final int interruptCount = Integer.parseInt(m.group(2)); 52 mItem.addInterrupt(interruptName, interruptCount, 53 getInterruptCategory(interruptName)); 54 } else { 55 // Done with interrupts 56 break; 57 } 58 } 59 return mItem; 60 } 61 62 /** 63 * Get the {@link InterruptItem}. 64 * <p> 65 * Exposed for unit testing. 66 * </p> 67 */ 68 InterruptItem getItem() { 69 return mItem; 70 } 71 72 private InterruptCategory getInterruptCategory(String interruptName) { 73 if (interruptName.contains("bcmsdh_sdmmc") || interruptName.contains("msm_pcie_wake")) { 74 return InterruptCategory.WIFI_INTERRUPT; 75 } else if (interruptName.contains("smd-modem") || 76 interruptName.contains("smsm-modem")) { 77 return InterruptCategory.MODEM_INTERRUPT; 78 } else if (interruptName.contains("smd-adsp")) { 79 return InterruptCategory.ADSP_INTERRUPT; 80 } else if (interruptName.contains("max77686-irq") || 81 interruptName.contains("cpcap-irq") || 82 interruptName.contains("TWL6030-PIH")) { 83 return InterruptCategory.ALARM_INTERRUPT; 84 } 85 86 return InterruptCategory.UNKNOWN_INTERRUPT; 87 } 88 89 } 90