1 /*
2  * Copyright (C) 2011 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.DumpsysProcStatsItem;
19 
20 import java.util.List;
21 import java.util.regex.Matcher;
22 import java.util.regex.Pattern;
23 
24 /**
25  * A {@link IParser} to parse procstats and create a mapping table of process names and UIDs
26  */
27 public class DumpsysProcStatsParser implements IParser {
28 
29     /**
30      * Matches: * com.google.android.googlequicksearchbox:search / u0a19 / v300401240: -----
31      */
32     private static final Pattern UID = Pattern.compile("^\\s*\\* (.*):?.*/ (.*)/.*");
33 
34     /**
35      * {@inheritDoc}
36      *
37      * @return The {@link DumpsysProcStatsItem}.
38      */
39     @Override
parse(List<String> lines)40     public DumpsysProcStatsItem parse(List<String> lines) {
41         DumpsysProcStatsItem item = new DumpsysProcStatsItem();
42         for (String line : lines) {
43             Matcher m = UID.matcher(line);
44             if(m.matches()) {
45                 item.put(m.group(2).trim(), m.group(1).trim());
46             }
47         }
48         return item;
49     }
50 
51 }
52