The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [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.IOException; |
| 18 | import java.io.FileInputStream; |
| 19 | import java.io.ObjectInputStream; |
| 20 | import java.io.BufferedInputStream; |
Bob Lee | 2e93f65 | 2009-08-11 01:16:03 -0700 | [diff] [blame] | 21 | import java.util.Set; |
| 22 | import java.util.HashSet; |
| 23 | import java.util.TreeSet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * Prints raw information in CSV format. |
| 27 | */ |
| 28 | public class PrintCsv { |
| 29 | |
| 30 | public static void main(String[] args) |
| 31 | throws IOException, ClassNotFoundException { |
| 32 | if (args.length != 1) { |
| 33 | System.err.println("Usage: PrintCsv [compiled log file]"); |
| 34 | System.exit(0); |
| 35 | } |
| 36 | |
| 37 | Root root = Root.fromFile(args[0]); |
| 38 | |
| 39 | System.out.println("Name" |
| 40 | + ",Preloaded" |
| 41 | + ",Median Load Time (us)" |
| 42 | + ",Median Init Time (us)" |
Bob Lee | 2e93f65 | 2009-08-11 01:16:03 -0700 | [diff] [blame] | 43 | + ",Process Names" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | + ",Load Count" |
Bob Lee | 2e93f65 | 2009-08-11 01:16:03 -0700 | [diff] [blame] | 45 | + ",Init Count"); |
| 46 | // + ",Managed Heap (B)" |
| 47 | // + ",Native Heap (B)" |
| 48 | // + ",Managed Pages (kB)" |
| 49 | // + ",Native Pages (kB)" |
| 50 | // + ",Other Pages (kB)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | |
| 52 | MemoryUsage baseline = root.baseline; |
| 53 | |
| 54 | for (LoadedClass loadedClass : root.loadedClasses.values()) { |
| 55 | if (!loadedClass.systemClass) { |
| 56 | continue; |
| 57 | } |
| 58 | |
| 59 | System.out.print(loadedClass.name); |
| 60 | System.out.print(','); |
| 61 | System.out.print(loadedClass.preloaded); |
| 62 | System.out.print(','); |
| 63 | System.out.print(loadedClass.medianLoadTimeMicros()); |
| 64 | System.out.print(','); |
| 65 | System.out.print(loadedClass.medianInitTimeMicros()); |
| 66 | System.out.print(','); |
Bob Lee | 2e93f65 | 2009-08-11 01:16:03 -0700 | [diff] [blame] | 67 | System.out.print('"'); |
| 68 | |
| 69 | Set<String> procNames = new TreeSet<String>(); |
| 70 | for (Operation op : loadedClass.loads) |
| 71 | procNames.add(op.process.name); |
| 72 | for (Operation op : loadedClass.initializations) |
| 73 | procNames.add(op.process.name); |
| 74 | for (String name : procNames) { |
| 75 | System.out.print(name + "\n"); |
| 76 | } |
| 77 | |
| 78 | System.out.print('"'); |
| 79 | System.out.print(','); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | System.out.print(loadedClass.loads.size()); |
| 81 | System.out.print(','); |
| 82 | System.out.print(loadedClass.initializations.size()); |
Bob Lee | 2e93f65 | 2009-08-11 01:16:03 -0700 | [diff] [blame] | 83 | /* |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | if (loadedClass.memoryUsage.isAvailable()) { |
| 85 | MemoryUsage subtracted |
| 86 | = loadedClass.memoryUsage.subtract(baseline); |
| 87 | |
| 88 | System.out.print(','); |
| 89 | System.out.print(subtracted.javaHeapSize()); |
| 90 | System.out.print(','); |
| 91 | System.out.print(subtracted.nativeHeapSize); |
| 92 | System.out.print(','); |
| 93 | System.out.print(subtracted.javaPagesInK()); |
| 94 | System.out.print(','); |
| 95 | System.out.print(subtracted.nativePagesInK()); |
| 96 | System.out.print(','); |
| 97 | System.out.print(subtracted.otherPagesInK()); |
| 98 | |
| 99 | } else { |
| 100 | System.out.print(",n/a,n/a,n/a,n/a,n/a"); |
| 101 | } |
Bob Lee | 2e93f65 | 2009-08-11 01:16:03 -0700 | [diff] [blame] | 102 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | System.out.println(); |
| 104 | } |
| 105 | } |
| 106 | } |