1 /* 2 * Copyright (C) 2012 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.NativeCrashItem; 19 20 import java.util.List; 21 import java.util.regex.Matcher; 22 import java.util.regex.Pattern; 23 24 /** 25 * An {@link IParser} to handle native crashes. 26 */ 27 public class NativeCrashParser implements IParser { 28 29 /** Matches: Build fingerprint: 'fingerprint' */ 30 public static final Pattern FINGERPRINT = Pattern.compile("^Build fingerprint: '(.*)'$"); 31 /** Matches: pid: 957, tid: 963 >>> com.android.camera <<< */ 32 private static final Pattern APP = Pattern.compile( 33 "^pid: (\\d+), tid: (\\d+)(, name: .+)? >>> (\\S+) <<<$"); 34 35 /** 36 * {@inheritDoc} 37 * 38 * @return The {@link NativeCrashItem}. 39 */ 40 @Override parse(List<String> lines)41 public NativeCrashItem parse(List<String> lines) { 42 NativeCrashItem nc = null; 43 StringBuilder stack = new StringBuilder(); 44 45 for (String line : lines) { 46 Matcher m = FINGERPRINT.matcher(line); 47 if (m.matches()) { 48 nc = new NativeCrashItem(); 49 nc.setFingerprint(m.group(1)); 50 } 51 52 if (nc != null) { 53 m = APP.matcher(line); 54 if (m.matches()) { 55 nc.setPid(Integer.valueOf(m.group(1))); 56 nc.setTid(Integer.valueOf(m.group(2))); 57 nc.setApp(m.group(4)); 58 } 59 60 stack.append(line); 61 stack.append("\n"); 62 } 63 } 64 if (nc != null) { 65 nc.setStack(stack.toString().trim()); 66 } 67 return nc; 68 } 69 } 70 71