• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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 
17 import java.io.BufferedReader;
18 import java.io.FileInputStream;
19 import java.io.IOException;
20 import java.io.InputStreamReader;
21 import java.util.ArrayList;
22 import java.util.List;
23 
24 /**
25  * Parses and analyzes a log, pulling our PRELOAD information. If you have
26  * an emulator or device running in the background, this class will use it
27  * to measure and record the memory usage of each class.
28  *
29  * TODO: Should analyze lines and select substring dynamically (instead of hardcoded 19)
30  */
31 public class Compile {
32 
main(String[] args)33     public static void main(String[] args) throws IOException {
34         if (args.length != 2) {
35             System.err.println("Usage: Compile [log file] [output file]");
36             System.exit(0);
37         }
38 
39         Root root = new Root();
40 
41         List<Record> records = new ArrayList<Record>();
42 
43         BufferedReader in = new BufferedReader(new InputStreamReader(
44                 new FileInputStream(args[0])));
45 
46         String line;
47         int lineNumber = 0;
48         while ((line = in.readLine()) != null) {
49             lineNumber++;
50             if (line.startsWith("I/PRELOAD")) {
51                 try {
52                     String clipped = line.substring(19);
53                     records.add(new Record(clipped, lineNumber));
54                 } catch (RuntimeException e) {
55                     throw new RuntimeException(
56                             "Exception while recording line " + lineNumber + ": " + line, e);
57                 }
58             }
59         }
60 
61         for (Record record : records) {
62             root.indexProcess(record);
63         }
64 
65         for (Record record : records) {
66             root.indexClassOperation(record);
67         }
68 
69         in.close();
70 
71         root.toFile(args[1]);
72     }
73 }
74