1 | /* |
2 | * Copyright 2008 Eric Caspole |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this |
5 | * file except in compliance with the License. You may obtain a copy of the License at |
6 | * |
7 | * http://www.apache.org/licenses/LICENSE-2.0 |
8 | * |
9 | * Unless required by applicable law or agreed to in writing, software distributed under |
10 | * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
11 | * KIND, either express or implied. See the License for the specific language governing |
12 | * permissions and limitations under the License. |
13 | */ |
14 | package net.sf.madmap; |
15 | |
16 | import java.io.*; |
17 | import java.util.*; |
18 | import java.awt.*; |
19 | import java.awt.event.*; |
20 | import javax.swing.*; |
21 | import javax.swing.filechooser.*; |
22 | |
23 | |
24 | public class LiveHeapTableModel extends javax.swing.table.AbstractTableModel { |
25 | |
26 | java.util.List<HprofClassElement> heap; |
27 | long totalLiveSize; |
28 | |
29 | private String[] columnNames = { |
30 | "ClassName@ClassAddr", |
31 | "Live Size", |
32 | "Pct of Live Size", |
33 | "Count", |
34 | "Avg Size" |
35 | }; |
36 | |
37 | private Class[] columnType = { |
38 | (java.lang.Class)((new String("")).getClass()), |
39 | (java.lang.Class)((new Long(0)).getClass()), |
40 | (java.lang.Class)((new Double(0.0)).getClass()), |
41 | (java.lang.Class)((new Long(0)).getClass()), |
42 | (java.lang.Class)((new Double(0.0)).getClass()) |
43 | }; |
44 | |
45 | public LiveHeapTableModel( java.util.List<HprofClassElement> initialSortedHeap, long liveSize ) { |
46 | heap = initialSortedHeap; |
47 | totalLiveSize = liveSize; |
48 | } |
49 | |
50 | public Class getColumnClass(int c) { |
51 | return columnType[c]; |
52 | } |
53 | |
54 | public String getColumnName(int col) { |
55 | return columnNames[col]; |
56 | } |
57 | |
58 | public int getColumnCount() { return columnType.length; } |
59 | public int getRowCount() { return heap.size(); } |
60 | |
61 | public Object getValueAt(int row, int col) { |
62 | Iterator<HprofClassElement> ihoc3 = heap.iterator(); |
63 | int i = 0; |
64 | |
65 | while( ihoc3.hasNext() ) { |
66 | HprofClassElement hk = ihoc3.next(); |
67 | |
68 | if ( i == row ) { |
69 | if ( col == 0 ) { |
70 | return new String( hk.className() + "@" + Long.toHexString(hk.addr()) ); |
71 | } else if ( col == 1 ) { |
72 | return hk.getInstanceSize(); |
73 | } else if ( col == 2 ) { |
74 | return new Double( (double) hk.getInstanceSize() / (double) totalLiveSize ) * 100; |
75 | } else if ( col == 3 ) { |
76 | return hk.getInstanceCount(); |
77 | } else if ( col == 4 ) { |
78 | return new Double( (double) hk.getInstanceSize() / (double) hk.getInstanceCount() ); |
79 | } |
80 | } |
81 | |
82 | i += 1; |
83 | } |
84 | |
85 | assert true == false : "Should not reach here!" ; |
86 | return null; |
87 | } |
88 | }; |