blob: 1820830464711875179c7fb4eb56e672a6b6fe32 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17import java.io.IOException;
18import java.io.FileInputStream;
19import java.io.ObjectInputStream;
20import java.io.BufferedInputStream;
Bob Lee9d2d6e12009-08-13 14:41:54 -070021import java.io.Writer;
22import java.io.PrintStream;
Bob Lee2e93f652009-08-11 01:16:03 -070023import java.util.Set;
24import java.util.HashSet;
25import java.util.TreeSet;
Bob Lee9d2d6e12009-08-13 14:41:54 -070026import java.util.Iterator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027
28/**
29 * Prints raw information in CSV format.
30 */
31public class PrintCsv {
32
33 public static void main(String[] args)
34 throws IOException, ClassNotFoundException {
35 if (args.length != 1) {
36 System.err.println("Usage: PrintCsv [compiled log file]");
37 System.exit(0);
38 }
39
40 Root root = Root.fromFile(args[0]);
41
Bob Lee9d2d6e12009-08-13 14:41:54 -070042 printHeaders(System.out);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043
Bob Lee9d2d6e12009-08-13 14:41:54 -070044 MemoryUsage baseline = MemoryUsage.baseline();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045
46 for (LoadedClass loadedClass : root.loadedClasses.values()) {
47 if (!loadedClass.systemClass) {
48 continue;
49 }
50
Bob Lee9d2d6e12009-08-13 14:41:54 -070051 printRow(System.out, baseline, loadedClass);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052 }
53 }
Bob Lee9d2d6e12009-08-13 14:41:54 -070054
55 static void printHeaders(PrintStream out) {
56 out.println("Name"
57 + ",Preloaded"
58 + ",Median Load Time (us)"
59 + ",Median Init Time (us)"
60 + ",Process Names"
61 + ",Load Count"
62 + ",Init Count"
63 + ",Managed Heap (B)"
64 + ",Native Heap (B)"
65 + ",Managed Pages (kB)"
66 + ",Native Pages (kB)"
67 + ",Other Pages (kB)");
68 }
69
70 static void printRow(PrintStream out, MemoryUsage baseline,
71 LoadedClass loadedClass) {
72 out.print(loadedClass.name);
73 out.print(',');
74 out.print(loadedClass.preloaded);
75 out.print(',');
76 out.print(loadedClass.medianLoadTimeMicros());
77 out.print(',');
78 out.print(loadedClass.medianInitTimeMicros());
79 out.print(',');
80 out.print('"');
81
82 Set<String> procNames = new TreeSet<String>();
83 for (Operation op : loadedClass.loads)
84 procNames.add(op.process.name);
85 for (Operation op : loadedClass.initializations)
86 procNames.add(op.process.name);
87
88 if (procNames.size() <= 3) {
89 for (String name : procNames) {
90 out.print(name + "\n");
91 }
92 } else {
93 Iterator<String> i = procNames.iterator();
94 out.print(i.next() + "\n");
95 out.print(i.next() + "\n");
96 out.print("...and " + (procNames.size() - 2)
97 + " others.");
98 }
99
100 out.print('"');
101 out.print(',');
102 out.print(loadedClass.loads.size());
103 out.print(',');
104 out.print(loadedClass.initializations.size());
105
106 if (loadedClass.memoryUsage.isAvailable()) {
107 MemoryUsage subtracted
108 = loadedClass.memoryUsage.subtract(baseline);
109
110 out.print(',');
111 out.print(subtracted.javaHeapSize());
112 out.print(',');
113 out.print(subtracted.nativeHeapSize);
114 out.print(',');
115 out.print(subtracted.javaPagesInK());
116 out.print(',');
117 out.print(subtracted.nativePagesInK());
118 out.print(',');
119 out.print(subtracted.otherPagesInK());
120
121 } else {
122 out.print(",n/a,n/a,n/a,n/a,n/a");
123 }
124
125 out.println();
126 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127}