2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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;
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.
29 * TODO: Should analyze lines and select substring dynamically (instead of hardcoded 19)
31 public class Compile {
33 public static void main(String[] args) throws IOException {
34 if (args.length != 2) {
35 System.err.println("Usage: Compile [log file] [output file]");
39 Root root = new Root();
41 List<Record> records = new ArrayList<Record>();
43 BufferedReader in = new BufferedReader(new InputStreamReader(
44 new FileInputStream(args[0])));
48 while ((line = in.readLine()) != null) {
50 if (line.startsWith("I/PRELOAD")) {
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);
61 for (Record record : records) {
62 root.indexProcess(record);
65 for (Record record : records) {
66 root.indexClassOperation(record);