The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 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.InputStreamReader; |
| 19 | import java.io.IOException; |
| 20 | import java.io.FileInputStream; |
| 21 | import java.io.FileOutputStream; |
| 22 | import java.io.ObjectOutputStream; |
| 23 | import java.io.BufferedOutputStream; |
| 24 | import java.util.List; |
| 25 | import java.util.ArrayList; |
| 26 | import java.lang.reflect.InvocationTargetException; |
| 27 | |
| 28 | /** |
| 29 | * Parses and analyzes a log, pulling our PRELOAD information. If you have |
| 30 | * an emulator or device running in the background, this class will use it |
| 31 | * to measure and record the memory usage of each class. |
| 32 | */ |
| 33 | public class Compile { |
| 34 | |
| 35 | public static void main(String[] args) |
| 36 | throws IOException, NoSuchMethodException, IllegalAccessException, |
| 37 | InvocationTargetException { |
| 38 | if (args.length != 2) { |
| 39 | System.err.println("Usage: Compile [log file] [output file]"); |
| 40 | System.exit(0); |
| 41 | } |
| 42 | |
| 43 | Root root = new Root(); |
| 44 | |
| 45 | List<Record> records = new ArrayList<Record>(); |
| 46 | |
| 47 | BufferedReader in = new BufferedReader(new InputStreamReader( |
| 48 | new FileInputStream(args[0]))); |
| 49 | |
| 50 | String line; |
| 51 | while ((line = in.readLine()) != null) { |
| 52 | if (line.startsWith("I/PRELOAD")) { |
| 53 | line = line.substring(19); |
| 54 | records.add(new Record(line)); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | for (Record record : records) { |
| 59 | root.indexProcess(record); |
| 60 | } |
| 61 | |
| 62 | for (Record record : records) { |
| 63 | root.indexClassOperation(record); |
| 64 | } |
| 65 | |
| 66 | in.close(); |
| 67 | |
| 68 | root.toFile(args[1]); |
| 69 | } |
| 70 | } |