1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package net.sf.madmap;
16
17 import java.io.*;
18 import java.util.*;
19 import javax.swing.*;
20
21
22
23
24
25
26 public class CumulativeRetainedHeapTableModel extends MadmapTableModel {
27
28 ArrayList _classes;
29 long _retSizes[];
30 long _totalLiveSize;
31 int _rows;
32
33 private String[] columnNames = {
34 "Type Name",
35 "Type Address",
36 "Instance Count",
37 "Cumulative Retained Size",
38 "Pct of Cum Retained Size"
39 };
40
41 private Class[] columnType = {
42 (java.lang.Class)((new String("")).getClass()),
43 (java.lang.Class)((new String("")).getClass()),
44 (java.lang.Class)((new Long(0)).getClass()),
45 (java.lang.Class)((new Long(0)).getClass()),
46 (java.lang.Class)((new Double(0.0)).getClass())
47 };
48
49 public CumulativeRetainedHeapTableModel( Madmap m, ArrayList classes, long liveSize ) {
50 super(m);
51 _classes = classes;
52 _rows = _classes.size();
53 _retSizes = new long[_rows];
54 for( int i = 0; i < _rows; i++ ) {
55 _retSizes[i] = ((HprofHeapCollectable)_classes.get(i)).getRetainedSize();
56 }
57
58 _totalLiveSize = liveSize;
59 }
60
61 public Class getColumnClass(int c) {
62 return columnType[c];
63 }
64
65 public String getColumnName(int col) {
66 return columnNames[col];
67 }
68
69 public int getColumnCount() { return columnNames.length; }
70 public int getRowCount() { return _rows; }
71
72
73
74
75
76
77
78
79
80
81 public Vector getStack(int row) {
82 String s = new String( " <no stack trace available>" + "\n" );
83 Vector stk = new Vector();
84 stk.add(s);
85 return stk;
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101 }
102
103
104
105
106
107
108
109 public String childrenSummary(int row) {
110 HprofHeapCollectable hk = (HprofHeapCollectable)_classes.get(row);
111 return hk.toString();
112 }
113
114
115 public Object getValueAt(int row, int col) {
116 Iterator<HprofClassElement> ihoc3 = _classes.iterator();
117 int i = 0;
118
119 while( ihoc3.hasNext() ) {
120 HprofClassElement hk = ihoc3.next();
121 long rs = _retSizes[i];
122 double pctLiveSize = ((double) rs / (double) _totalLiveSize) * (double)100.0;
123
124 if ( i == row ) {
125 if ( col == 0 ) {
126 return new String( hk.className() );
127 } else if ( col == 1 ) {
128 return new String( Long.toHexString(hk.addr()) );
129 } else if ( col == 2 ) {
130 return hk.getInstanceCount();
131 } else if ( col == 3 ) {
132 return rs;
133 } else if ( col == 4 ) {
134 return pctLiveSize;
135 }
136 }
137 i += 1;
138 }
139
140 assert true == false : "Should not reach here!" ;
141 return null;
142 }
143 };