author | alanb |
Fri, 02 Nov 2012 15:50:11 +0000 | |
changeset 14342 | 8435a30053c1 |
parent 12851 | 3334e1c781d0 |
child 19429 | 7de30a1db3b3 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
14342
8435a30053c1
7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents:
12851
diff
changeset
|
2 |
* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.tools.jconsole; |
|
27 |
||
28 |
import java.awt.*; |
|
29 |
import java.awt.event.*; |
|
30 |
import java.io.*; |
|
31 |
import java.lang.management.*; |
|
32 |
import java.lang.reflect.*; |
|
33 |
import java.util.*; |
|
34 |
import java.util.concurrent.*; |
|
35 |
||
36 |
import javax.accessibility.*; |
|
37 |
import javax.management.*; |
|
38 |
import javax.management.openmbean.CompositeData; |
|
39 |
import javax.swing.*; |
|
40 |
import javax.swing.border.*; |
|
41 |
||
42 |
||
43 |
import static sun.tools.jconsole.Formatter.*; |
|
44 |
import static sun.tools.jconsole.Utilities.*; |
|
45 |
||
46 |
@SuppressWarnings("serial") |
|
47 |
class MemoryTab extends Tab implements ActionListener, ItemListener { |
|
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
48 |
JComboBox<Plotter> plotterChoice; |
2 | 49 |
TimeComboBox timeComboBox; |
50 |
JButton gcButton; |
|
51 |
||
52 |
PlotterPanel plotterPanel; |
|
53 |
JPanel bottomPanel; |
|
54 |
HTMLPane details; |
|
55 |
PoolChart poolChart; |
|
56 |
||
57 |
ArrayList<Plotter> plotterList; |
|
58 |
Plotter heapPlotter, nonHeapPlotter; |
|
59 |
||
60 |
private MemoryOverviewPanel overviewPanel; |
|
61 |
||
62 |
private static final String usedKey = "used"; |
|
63 |
private static final String committedKey = "committed"; |
|
64 |
private static final String maxKey = "max"; |
|
65 |
private static final String thresholdKey = "threshold"; |
|
66 |
private static final Color usedColor = Plotter.defaultColor; |
|
67 |
private static final Color committedColor = null; |
|
68 |
private static final Color maxColor = null; |
|
69 |
private static final Color thresholdColor = Color.red; |
|
70 |
||
71 |
/* |
|
72 |
Hierarchy of panels and layouts for this tab: |
|
73 |
||
74 |
MemoryTab (BorderLayout) |
|
75 |
||
76 |
North: topPanel (BorderLayout) |
|
77 |
||
78 |
Center: controlPanel (FlowLayout) |
|
79 |
plotterChoice, timeComboBox |
|
80 |
||
81 |
East: topRightPanel (FlowLayout) |
|
82 |
gcButton |
|
83 |
||
84 |
Center: plotterPanel |
|
85 |
||
86 |
Center: plotter |
|
87 |
||
88 |
South: bottomPanel (BorderLayout) |
|
89 |
||
90 |
Center: details |
|
91 |
East: poolChart |
|
92 |
*/ |
|
93 |
||
94 |
||
95 |
public static String getTabName() { |
|
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
96 |
return Messages.MEMORY; |
2 | 97 |
} |
98 |
||
99 |
public MemoryTab(VMPanel vmPanel) { |
|
100 |
super(vmPanel, getTabName()); |
|
101 |
||
102 |
setLayout(new BorderLayout(0, 0)); |
|
103 |
setBorder(new EmptyBorder(4, 4, 3, 4)); |
|
104 |
||
105 |
JPanel topPanel = new JPanel(new BorderLayout()); |
|
106 |
plotterPanel = new PlotterPanel(null); |
|
107 |
bottomPanel = new JPanel(new BorderLayout()); |
|
108 |
||
109 |
add(topPanel, BorderLayout.NORTH); |
|
110 |
add(plotterPanel, BorderLayout.CENTER); |
|
111 |
||
112 |
JPanel controlPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 20, 5)); |
|
113 |
topPanel.add(controlPanel, BorderLayout.CENTER); |
|
114 |
||
115 |
// Plotter choice |
|
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
116 |
plotterChoice = new JComboBox<Plotter>(); |
2 | 117 |
plotterChoice.addItemListener(this); |
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
118 |
controlPanel.add(new LabeledComponent(Messages.CHART_COLON, |
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
119 |
Resources.getMnemonicInt(Messages.CHART_COLON), |
2 | 120 |
plotterChoice)); |
121 |
||
122 |
// Range control |
|
123 |
timeComboBox = new TimeComboBox(); |
|
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
124 |
controlPanel.add(new LabeledComponent(Messages.TIME_RANGE_COLON, |
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
125 |
Resources.getMnemonicInt(Messages.TIME_RANGE_COLON), |
2 | 126 |
timeComboBox)); |
127 |
||
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
128 |
gcButton = new JButton(Messages.PERFORM_GC); |
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
129 |
gcButton.setMnemonic(Resources.getMnemonicInt(Messages.PERFORM_GC)); |
2 | 130 |
gcButton.addActionListener(this); |
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
131 |
gcButton.setToolTipText(Messages.PERFORM_GC_TOOLTIP); |
2 | 132 |
JPanel topRightPanel = new JPanel(); |
133 |
topRightPanel.setBorder(new EmptyBorder(0, 65-8, 0, 70)); |
|
134 |
topRightPanel.add(gcButton); |
|
135 |
topPanel.add(topRightPanel, BorderLayout.AFTER_LINE_ENDS); |
|
136 |
||
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
137 |
bottomPanel.setBorder(new CompoundBorder(new TitledBorder(Messages.DETAILS), |
2 | 138 |
new EmptyBorder(10, 10, 10, 10))); |
139 |
||
140 |
details = new HTMLPane(); |
|
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
141 |
setAccessibleName(details, Messages.DETAILS); |
2 | 142 |
bottomPanel.add(new JScrollPane(details), BorderLayout.CENTER); |
143 |
||
144 |
poolChart = new PoolChart(); |
|
145 |
bottomPanel.add(poolChart, BorderLayout.AFTER_LINE_ENDS); |
|
146 |
} |
|
147 |
||
148 |
||
149 |
private void createPlotters() throws IOException { |
|
150 |
plotterList = new ArrayList<Plotter>(); |
|
151 |
||
152 |
ProxyClient proxyClient = vmPanel.getProxyClient(); |
|
153 |
||
154 |
heapPlotter = new Plotter(Plotter.Unit.BYTES) { |
|
155 |
public String toString() { |
|
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
156 |
return Messages.HEAP_MEMORY_USAGE; |
2 | 157 |
} |
158 |
}; |
|
159 |
proxyClient.addWeakPropertyChangeListener(heapPlotter); |
|
160 |
||
161 |
nonHeapPlotter = new Plotter(Plotter.Unit.BYTES) { |
|
162 |
public String toString() { |
|
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
163 |
return Messages.NON_HEAP_MEMORY_USAGE; |
2 | 164 |
} |
165 |
}; |
|
166 |
||
167 |
setAccessibleName(heapPlotter, |
|
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
168 |
Messages.MEMORY_TAB_HEAP_PLOTTER_ACCESSIBLE_NAME); |
2 | 169 |
setAccessibleName(nonHeapPlotter, |
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
170 |
Messages.MEMORY_TAB_NON_HEAP_PLOTTER_ACCESSIBLE_NAME); |
2 | 171 |
|
172 |
proxyClient.addWeakPropertyChangeListener(nonHeapPlotter); |
|
173 |
||
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
174 |
heapPlotter.createSequence(usedKey, Messages.USED, usedColor, true); |
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
175 |
heapPlotter.createSequence(committedKey, Messages.COMMITTED, committedColor, false); |
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
176 |
heapPlotter.createSequence(maxKey, Messages.MAX, maxColor, false); |
2 | 177 |
|
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
178 |
nonHeapPlotter.createSequence(usedKey, Messages.USED, usedColor, true); |
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
179 |
nonHeapPlotter.createSequence(committedKey, Messages.COMMITTED, committedColor, false); |
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
180 |
nonHeapPlotter.createSequence(maxKey, Messages.MAX, maxColor, false); |
2 | 181 |
|
182 |
plotterList.add(heapPlotter); |
|
183 |
plotterList.add(nonHeapPlotter); |
|
184 |
||
185 |
// Now add memory pools |
|
186 |
Map<ObjectName, MBeanInfo> mBeanMap = proxyClient.getMBeans("java.lang"); |
|
187 |
Set<ObjectName> keys = mBeanMap.keySet(); |
|
188 |
ObjectName[] objectNames = keys.toArray(new ObjectName[keys.size()]); |
|
189 |
ArrayList<PoolPlotter> nonHeapPlotters = new ArrayList<PoolPlotter>(2); |
|
190 |
for (ObjectName objectName : objectNames) { |
|
191 |
String type = objectName.getKeyProperty("type"); |
|
192 |
if (type.equals("MemoryPool")) { |
|
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
193 |
String name = Resources.format(Messages.MEMORY_POOL_LABEL, |
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
194 |
objectName.getKeyProperty("name")); |
2 | 195 |
// Heap or non-heap? |
196 |
boolean isHeap = false; |
|
197 |
AttributeList al = |
|
198 |
proxyClient.getAttributes(objectName, |
|
199 |
new String[] { "Type" }); |
|
200 |
if (al.size() > 0) { |
|
201 |
isHeap = MemoryType.HEAP.name().equals(((Attribute)al.get(0)).getValue()); |
|
202 |
} |
|
203 |
PoolPlotter poolPlotter = new PoolPlotter(objectName, name, isHeap); |
|
204 |
proxyClient.addWeakPropertyChangeListener(poolPlotter); |
|
205 |
||
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
206 |
poolPlotter.createSequence(usedKey, Messages.USED, usedColor, true); |
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
207 |
poolPlotter.createSequence(committedKey, Messages.COMMITTED, committedColor, false); |
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
208 |
poolPlotter.createSequence(maxKey, Messages.MAX, maxColor, false); |
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
209 |
poolPlotter.createSequence(thresholdKey, Messages.THRESHOLD, thresholdColor, false); |
2 | 210 |
poolPlotter.setUseDashedTransitions(thresholdKey, true); |
211 |
||
212 |
if (isHeap) { |
|
213 |
plotterList.add(poolPlotter); |
|
214 |
} else { |
|
215 |
// Will be added to plotterList below |
|
216 |
nonHeapPlotters.add(poolPlotter); |
|
217 |
} |
|
218 |
} |
|
219 |
} |
|
220 |
// Add non-heap plotters last |
|
221 |
for (PoolPlotter poolPlotter : nonHeapPlotters) { |
|
222 |
plotterList.add(poolPlotter); |
|
223 |
} |
|
224 |
} |
|
225 |
||
226 |
||
227 |
public void itemStateChanged(ItemEvent ev) { |
|
228 |
if (ev.getStateChange() == ItemEvent.SELECTED) { |
|
229 |
Plotter plotter = (Plotter)plotterChoice.getSelectedItem(); |
|
230 |
plotterPanel.setPlotter(plotter); |
|
231 |
} |
|
232 |
} |
|
233 |
||
234 |
public void gc() { |
|
235 |
new Thread("MemoryPanel.gc") { |
|
236 |
public void run() { |
|
237 |
ProxyClient proxyClient = vmPanel.getProxyClient(); |
|
238 |
try { |
|
239 |
proxyClient.getMemoryMXBean().gc(); |
|
240 |
} catch (UndeclaredThrowableException e) { |
|
241 |
proxyClient.markAsDead(); |
|
242 |
} catch (IOException e) { |
|
243 |
// Ignore |
|
244 |
} |
|
245 |
} |
|
246 |
}.start(); |
|
247 |
} |
|
248 |
||
249 |
public SwingWorker<?, ?> newSwingWorker() { |
|
250 |
return new SwingWorker<Boolean, Object>() { |
|
251 |
private long[] used, committed, max, threshold; |
|
252 |
private long timeStamp; |
|
253 |
private String detailsStr; |
|
254 |
private boolean initialRun = false; |
|
255 |
||
256 |
public Boolean doInBackground() { |
|
257 |
ProxyClient proxyClient = vmPanel.getProxyClient(); |
|
258 |
||
259 |
if (plotterList == null) { |
|
260 |
try { |
|
261 |
createPlotters(); |
|
262 |
} catch (UndeclaredThrowableException e) { |
|
263 |
proxyClient.markAsDead(); |
|
264 |
return false; |
|
265 |
} catch (final IOException ex) { |
|
266 |
return false; |
|
267 |
} |
|
268 |
initialRun = true; |
|
269 |
} |
|
270 |
||
271 |
int n = plotterList.size(); |
|
272 |
used = new long[n]; |
|
273 |
committed = new long[n]; |
|
274 |
max = new long[n]; |
|
275 |
threshold = new long[n]; |
|
276 |
timeStamp = System.currentTimeMillis(); |
|
277 |
||
278 |
for (int i = 0; i < n; i++) { |
|
279 |
Plotter plotter = plotterList.get(i); |
|
280 |
MemoryUsage mu = null; |
|
281 |
used[i] = -1L; |
|
282 |
threshold[i] = -1L; |
|
283 |
||
284 |
try { |
|
285 |
if (plotter instanceof PoolPlotter) { |
|
286 |
PoolPlotter poolPlotter = (PoolPlotter)plotter; |
|
287 |
ObjectName objectName = poolPlotter.objectName; |
|
288 |
AttributeList al = |
|
289 |
proxyClient.getAttributes(objectName, |
|
290 |
new String[] { "Usage", "UsageThreshold" }); |
|
291 |
if (al.size() > 0) { |
|
292 |
CompositeData cd = (CompositeData)((Attribute)al.get(0)).getValue(); |
|
293 |
mu = MemoryUsage.from(cd); |
|
294 |
||
295 |
if (al.size() > 1) { |
|
296 |
threshold[i] = (Long)((Attribute)al.get(1)).getValue(); |
|
297 |
} |
|
298 |
} |
|
299 |
} else if (plotter == heapPlotter) { |
|
300 |
mu = proxyClient.getMemoryMXBean().getHeapMemoryUsage(); |
|
301 |
} else if (plotter == nonHeapPlotter) { |
|
302 |
mu = proxyClient.getMemoryMXBean().getNonHeapMemoryUsage(); |
|
303 |
} |
|
304 |
} catch (UndeclaredThrowableException e) { |
|
305 |
proxyClient.markAsDead(); |
|
306 |
return false; |
|
307 |
} catch (IOException ex) { |
|
308 |
// Skip this plotter |
|
309 |
} |
|
310 |
||
311 |
if (mu != null) { |
|
312 |
used[i] = mu.getUsed(); |
|
313 |
committed[i] = mu.getCommitted(); |
|
314 |
max[i] = mu.getMax(); |
|
315 |
} |
|
316 |
} |
|
317 |
detailsStr = formatDetails(); |
|
318 |
||
319 |
return true; |
|
320 |
} |
|
321 |
||
322 |
protected void done() { |
|
323 |
try { |
|
324 |
if (!get()) { |
|
325 |
return; |
|
326 |
} |
|
327 |
} catch (InterruptedException ex) { |
|
328 |
return; |
|
329 |
} catch (ExecutionException ex) { |
|
330 |
if (JConsole.isDebug()) { |
|
331 |
ex.printStackTrace(); |
|
332 |
} |
|
333 |
return; |
|
334 |
} |
|
335 |
||
336 |
if (initialRun) { |
|
337 |
// Add Memory Pools |
|
338 |
for (Plotter p : plotterList) { |
|
339 |
plotterChoice.addItem(p); |
|
340 |
timeComboBox.addPlotter(p); |
|
341 |
} |
|
342 |
add(bottomPanel, BorderLayout.SOUTH); |
|
343 |
} |
|
344 |
||
345 |
||
346 |
int n = plotterList.size(); |
|
347 |
int poolCount = 0; |
|
348 |
||
349 |
for (int i = 0; i < n; i++) { |
|
350 |
Plotter plotter = plotterList.get(i); |
|
351 |
if (used[i] >= 0L) { |
|
352 |
if (plotter instanceof PoolPlotter) { |
|
353 |
plotter.addValues(timeStamp, used[i], committed[i], max[i], threshold[i]); |
|
354 |
if (threshold[i] > 0L) { |
|
355 |
plotter.setIsPlotted(thresholdKey, true); |
|
356 |
} |
|
357 |
poolChart.setValue(poolCount++, (PoolPlotter)plotter, |
|
358 |
used[i], threshold[i], max[i]); |
|
359 |
} else { |
|
360 |
plotter.addValues(timeStamp, used[i], committed[i], max[i]); |
|
361 |
} |
|
362 |
||
363 |
if (plotter == heapPlotter && overviewPanel != null) { |
|
364 |
overviewPanel.getPlotter().addValues(timeStamp, used[i]); |
|
365 |
overviewPanel.updateMemoryInfo(used[i], committed[i], max[i]); |
|
366 |
} |
|
367 |
} |
|
368 |
} |
|
369 |
details.setText(detailsStr); |
|
370 |
} |
|
371 |
}; |
|
372 |
} |
|
373 |
||
374 |
private String formatDetails() { |
|
375 |
ProxyClient proxyClient = vmPanel.getProxyClient(); |
|
376 |
if (proxyClient.isDead()) { |
|
377 |
return ""; |
|
378 |
} |
|
379 |
||
380 |
String text = "<table cellspacing=0 cellpadding=0>"; |
|
381 |
||
382 |
Plotter plotter = (Plotter)plotterChoice.getSelectedItem(); |
|
383 |
if (plotter == null) { |
|
384 |
return ""; |
|
385 |
} |
|
386 |
||
387 |
//long time = plotter.getLastTimeStamp(); |
|
388 |
long time = System.currentTimeMillis(); |
|
389 |
String timeStamp = formatDateTime(time); |
|
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
390 |
text += newRow(Messages.TIME, timeStamp); |
2 | 391 |
|
392 |
long used = plotter.getLastValue(usedKey); |
|
393 |
long committed = plotter.getLastValue(committedKey); |
|
394 |
long max = plotter.getLastValue(maxKey); |
|
395 |
long threshold = plotter.getLastValue(thresholdKey); |
|
396 |
||
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
397 |
text += newRow(Messages.USED, formatKBytes(used)); |
2 | 398 |
if (committed > 0L) { |
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
399 |
text += newRow(Messages.COMMITTED, formatKBytes(committed)); |
2 | 400 |
} |
401 |
if (max > 0L) { |
|
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
402 |
text += newRow(Messages.MAX, formatKBytes(max)); |
2 | 403 |
} |
404 |
if (threshold > 0L) { |
|
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
405 |
text += newRow(Messages.USAGE_THRESHOLD, formatKBytes(threshold)); |
2 | 406 |
} |
407 |
||
408 |
try { |
|
409 |
Collection<GarbageCollectorMXBean> garbageCollectors = |
|
410 |
proxyClient.getGarbageCollectorMXBeans(); |
|
411 |
||
412 |
boolean descPrinted = false; |
|
413 |
for (GarbageCollectorMXBean garbageCollectorMBean : garbageCollectors) { |
|
414 |
String gcName = garbageCollectorMBean.getName(); |
|
415 |
long gcCount = garbageCollectorMBean.getCollectionCount(); |
|
416 |
long gcTime = garbageCollectorMBean.getCollectionTime(); |
|
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
417 |
String str = Resources.format(Messages.GC_TIME_DETAILS, justify(formatTime(gcTime), 14), |
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
418 |
gcName, |
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
419 |
String.format("%,d",gcCount)); |
2 | 420 |
if (!descPrinted) { |
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
421 |
text += newRow(Messages.GC_TIME, str); |
2 | 422 |
descPrinted = true; |
423 |
} else { |
|
424 |
text += newRow(null, str); |
|
425 |
} |
|
426 |
} |
|
427 |
} catch (IOException e) { |
|
428 |
} |
|
429 |
||
430 |
return text; |
|
431 |
} |
|
432 |
||
433 |
public void actionPerformed(ActionEvent ev) { |
|
434 |
Object src = ev.getSource(); |
|
435 |
if (src == gcButton) { |
|
436 |
gc(); |
|
437 |
} |
|
438 |
} |
|
439 |
||
440 |
private class PoolPlotter extends Plotter { |
|
441 |
ObjectName objectName; |
|
442 |
String name; |
|
443 |
boolean isHeap; |
|
444 |
long value, threshold, max; |
|
445 |
int barX; |
|
446 |
||
447 |
public PoolPlotter(ObjectName objectName, String name, boolean isHeap) { |
|
448 |
super(Plotter.Unit.BYTES); |
|
449 |
||
450 |
this.objectName = objectName; |
|
451 |
this.name = name; |
|
452 |
this.isHeap = isHeap; |
|
453 |
||
454 |
setAccessibleName(this, |
|
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
455 |
Resources.format(Messages.MEMORY_TAB_POOL_PLOTTER_ACCESSIBLE_NAME, |
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
456 |
name)); |
2 | 457 |
} |
458 |
||
459 |
||
460 |
public String toString() { |
|
461 |
return name; |
|
462 |
} |
|
463 |
} |
|
464 |
||
465 |
private class PoolChart extends BorderedComponent |
|
466 |
implements Accessible, MouseListener { |
|
467 |
final int height = 150; |
|
468 |
final int leftMargin = 50; |
|
469 |
final int rightMargin = 23; |
|
470 |
final int bottomMargin = 35; |
|
471 |
final int barWidth = 22; |
|
472 |
final int barGap = 3; |
|
473 |
final int groupGap = 8; |
|
474 |
final int barHeight = height * 2 / 3; |
|
475 |
||
476 |
final Color greenBar = new Color(100, 255, 100); |
|
477 |
final Color greenBarBackground = new Color(210, 255, 210); |
|
478 |
final Color redBarBackground = new Color(255, 210, 210); |
|
479 |
||
480 |
Font smallFont = null; |
|
481 |
||
482 |
ArrayList<PoolPlotter> poolPlotters = new ArrayList<PoolPlotter>(5); |
|
483 |
||
484 |
int nHeapPools = 0; |
|
485 |
int nNonHeapPools = 0; |
|
486 |
Rectangle heapRect = new Rectangle(leftMargin, height - bottomMargin + 6, barWidth, 20); |
|
487 |
Rectangle nonHeapRect = new Rectangle(leftMargin + groupGap, height - bottomMargin + 6, barWidth, 20); |
|
488 |
||
489 |
public PoolChart() { |
|
490 |
super(null, null); |
|
491 |
||
492 |
setFocusable(true); |
|
493 |
addMouseListener(this); |
|
494 |
ToolTipManager.sharedInstance().registerComponent(this); |
|
495 |
} |
|
496 |
||
497 |
public void setValue(int poolIndex, PoolPlotter poolPlotter, |
|
498 |
long value, long threshold, long max) { |
|
499 |
poolPlotter.value = value; |
|
500 |
poolPlotter.threshold = threshold; |
|
501 |
poolPlotter.max = max; |
|
502 |
||
503 |
if (poolIndex == poolPlotters.size()) { |
|
504 |
poolPlotters.add(poolPlotter); |
|
505 |
if (poolPlotter.isHeap) { |
|
506 |
poolPlotter.barX = nHeapPools * (barWidth + barGap); |
|
507 |
nHeapPools++; |
|
508 |
heapRect.width = nHeapPools * barWidth + (nHeapPools - 1) * barGap; |
|
509 |
nonHeapRect.x = leftMargin + heapRect.width + groupGap; |
|
510 |
} else { |
|
511 |
poolPlotter.barX = nonHeapRect.x - leftMargin + nNonHeapPools * (barWidth + barGap); |
|
512 |
nNonHeapPools++; |
|
513 |
nonHeapRect.width = nNonHeapPools * barWidth + (nNonHeapPools - 1) * barGap; |
|
514 |
} |
|
515 |
} else { |
|
516 |
poolPlotters.set(poolIndex, poolPlotter); |
|
517 |
} |
|
518 |
repaint(); |
|
519 |
} |
|
520 |
||
521 |
private void paintPoolBar(Graphics g, PoolPlotter poolPlotter) { |
|
522 |
Rectangle barRect = getBarRect(poolPlotter); |
|
523 |
g.setColor(Color.gray); |
|
524 |
g.drawRect(barRect.x, barRect.y, barRect.width, barRect.height); |
|
525 |
||
526 |
long value = poolPlotter.value; |
|
527 |
long max = poolPlotter.max; |
|
528 |
if (max > 0L) { |
|
529 |
g.translate(barRect.x, barRect.y); |
|
530 |
||
531 |
// Paint green background |
|
532 |
g.setColor(greenBarBackground); |
|
533 |
g.fillRect(1, 1, barRect.width - 1, barRect.height - 1); |
|
534 |
||
535 |
int greenHeight = (int)(value * barRect.height / max); |
|
536 |
long threshold = poolPlotter.threshold; |
|
537 |
if (threshold > 0L) { |
|
538 |
int redHeight = (int)(threshold * barRect.height / max); |
|
539 |
||
540 |
// Paint red background |
|
541 |
g.setColor(redBarBackground); |
|
542 |
g.fillRect(1, 1, barRect.width - 1, barRect.height - redHeight); |
|
543 |
||
544 |
if (value > threshold) { |
|
545 |
// Over threshold, paint red bar |
|
546 |
g.setColor(thresholdColor); |
|
547 |
g.fillRect(1, barRect.height - greenHeight, |
|
548 |
barRect.width - 1, greenHeight - redHeight); |
|
549 |
greenHeight = redHeight; |
|
550 |
} |
|
551 |
} |
|
552 |
||
553 |
// Paint green bar |
|
554 |
g.setColor(greenBar); |
|
555 |
g.fillRect(1, barRect.height - greenHeight, |
|
556 |
barRect.width - 1, greenHeight); |
|
557 |
||
558 |
g.translate(-barRect.x, -barRect.y); |
|
559 |
} |
|
560 |
} |
|
561 |
||
562 |
public void paintComponent(Graphics g) { |
|
563 |
super.paintComponent(g); |
|
564 |
||
565 |
if (poolPlotters.size() == 0) { |
|
566 |
return; |
|
567 |
} |
|
568 |
||
569 |
if (smallFont == null) { |
|
570 |
smallFont = g.getFont().deriveFont(9.0F); |
|
571 |
} |
|
572 |
||
573 |
// Paint background for chart area |
|
574 |
g.setColor(getBackground()); |
|
575 |
Rectangle r = g.getClipBounds(); |
|
576 |
g.fillRect(r.x, r.y, r.width, r.height); |
|
577 |
||
578 |
g.setFont(smallFont); |
|
579 |
FontMetrics fm = g.getFontMetrics(); |
|
580 |
int fontDescent = fm.getDescent(); |
|
581 |
||
582 |
// Paint percentage axis |
|
583 |
g.setColor(getForeground()); |
|
584 |
for (int pc : new int[] { 0, 25, 50, 75, 100 }) { |
|
585 |
String str = pc + "% --"; |
|
586 |
g.drawString(str, |
|
587 |
leftMargin - fm.stringWidth(str) - 4, |
|
588 |
height - bottomMargin - (pc * barHeight / 100) + fontDescent + 1); |
|
589 |
} |
|
590 |
||
591 |
for (PoolPlotter poolPlotter : poolPlotters) { |
|
592 |
paintPoolBar(g, poolPlotter); |
|
593 |
} |
|
594 |
||
595 |
g.setColor(Color.gray); |
|
596 |
g.drawRect(heapRect.x, heapRect.y, heapRect.width, heapRect.height); |
|
597 |
g.drawRect(nonHeapRect.x, nonHeapRect.y, nonHeapRect.width, nonHeapRect.height); |
|
598 |
||
599 |
Color heapColor = greenBar; |
|
600 |
Color nonHeapColor = greenBar; |
|
601 |
||
602 |
||
603 |
for (PoolPlotter poolPlotter : poolPlotters) { |
|
604 |
if (poolPlotter.threshold > 0L && poolPlotter.value > poolPlotter.threshold) { |
|
605 |
if (poolPlotter.isHeap) { |
|
606 |
heapColor = thresholdColor; |
|
607 |
} else { |
|
608 |
nonHeapColor = thresholdColor; |
|
609 |
} |
|
610 |
} |
|
611 |
} |
|
612 |
g.setColor(heapColor); |
|
613 |
g.fillRect(heapRect.x + 1, heapRect.y + 1, heapRect.width - 1, heapRect.height - 1); |
|
614 |
g.setColor(nonHeapColor); |
|
615 |
g.fillRect(nonHeapRect.x + 1, nonHeapRect.y + 1, nonHeapRect.width - 1, nonHeapRect.height - 1); |
|
616 |
||
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
617 |
String str = Messages.HEAP; |
2 | 618 |
int stringWidth = fm.stringWidth(str); |
619 |
int x = heapRect.x + (heapRect.width - stringWidth) / 2; |
|
620 |
int y = heapRect.y + heapRect.height - 6; |
|
621 |
g.setColor(Color.white); |
|
622 |
g.drawString(str, x-1, y-1); |
|
623 |
g.drawString(str, x+1, y-1); |
|
624 |
g.drawString(str, x-1, y+1); |
|
625 |
g.drawString(str, x+1, y+1); |
|
626 |
g.setColor(Color.black); |
|
627 |
g.drawString(str, x, y); |
|
628 |
||
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
629 |
str = Messages.NON_HEAP; |
2 | 630 |
stringWidth = fm.stringWidth(str); |
631 |
x = nonHeapRect.x + (nonHeapRect.width - stringWidth) / 2; |
|
632 |
y = nonHeapRect.y + nonHeapRect.height - 6; |
|
633 |
g.setColor(Color.white); |
|
634 |
g.drawString(str, x-1, y-1); |
|
635 |
g.drawString(str, x+1, y-1); |
|
636 |
g.drawString(str, x-1, y+1); |
|
637 |
g.drawString(str, x+1, y+1); |
|
638 |
g.setColor(Color.black); |
|
639 |
g.drawString(str, x, y); |
|
640 |
||
641 |
// Highlight current plotter |
|
642 |
g.setColor(Color.blue); |
|
643 |
r = null; |
|
644 |
Plotter plotter = (Plotter)plotterChoice.getSelectedItem(); |
|
645 |
if (plotter == heapPlotter) { |
|
646 |
r = heapRect; |
|
647 |
} else if (plotter == nonHeapPlotter) { |
|
648 |
r = nonHeapRect; |
|
649 |
} else if (plotter instanceof PoolPlotter) { |
|
650 |
r = getBarRect((PoolPlotter)plotter); |
|
651 |
} |
|
652 |
if (r != null) { |
|
653 |
g.drawRect(r.x - 1, r.y - 1, r.width + 2, r.height + 2); |
|
654 |
} |
|
655 |
} |
|
656 |
||
657 |
private Rectangle getBarRect(PoolPlotter poolPlotter) { |
|
658 |
return new Rectangle(leftMargin + poolPlotter.barX, |
|
659 |
height - bottomMargin - barHeight, |
|
660 |
barWidth, barHeight); |
|
661 |
} |
|
662 |
||
663 |
public Dimension getPreferredSize() { |
|
664 |
return new Dimension(nonHeapRect.x + nonHeapRect.width + rightMargin, |
|
665 |
height); |
|
666 |
} |
|
667 |
||
668 |
public void mouseClicked(MouseEvent e) { |
|
669 |
requestFocusInWindow(); |
|
670 |
Plotter plotter = getPlotter(e); |
|
671 |
||
672 |
if (plotter != null && plotter != plotterChoice.getSelectedItem()) { |
|
673 |
plotterChoice.setSelectedItem(plotter); |
|
674 |
repaint(); |
|
675 |
} |
|
676 |
} |
|
677 |
||
678 |
public String getToolTipText(MouseEvent e) { |
|
679 |
Plotter plotter = getPlotter(e); |
|
680 |
||
681 |
return (plotter != null) ? plotter.toString() : null; |
|
682 |
} |
|
683 |
||
684 |
private Plotter getPlotter(MouseEvent e) { |
|
685 |
Point p = e.getPoint(); |
|
686 |
Plotter plotter = null; |
|
687 |
||
688 |
if (heapRect.contains(p)) { |
|
689 |
plotter = heapPlotter; |
|
690 |
} else if (nonHeapRect.contains(p)) { |
|
691 |
plotter = nonHeapPlotter; |
|
692 |
} else { |
|
693 |
for (PoolPlotter poolPlotter : poolPlotters) { |
|
694 |
if (getBarRect(poolPlotter).contains(p)) { |
|
695 |
plotter = poolPlotter; |
|
696 |
break; |
|
697 |
} |
|
698 |
} |
|
699 |
} |
|
700 |
return plotter; |
|
701 |
} |
|
702 |
||
703 |
public void mousePressed(MouseEvent e) {} |
|
704 |
public void mouseReleased(MouseEvent e) {} |
|
705 |
public void mouseEntered(MouseEvent e) {} |
|
706 |
public void mouseExited(MouseEvent e) {} |
|
707 |
||
708 |
||
709 |
public AccessibleContext getAccessibleContext() { |
|
710 |
if (accessibleContext == null) { |
|
711 |
accessibleContext = new AccessiblePoolChart(); |
|
712 |
} |
|
713 |
return accessibleContext; |
|
714 |
} |
|
715 |
||
716 |
protected class AccessiblePoolChart extends AccessibleJPanel { |
|
717 |
public String getAccessibleName() { |
|
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
718 |
String name = Messages.MEMORY_TAB_POOL_CHART_ACCESSIBLE_NAME; |
2 | 719 |
|
720 |
String keyValueList = ""; |
|
721 |
for (PoolPlotter poolPlotter : poolPlotters) { |
|
722 |
String value = (poolPlotter.value * 100 / poolPlotter.max) + "%"; |
|
723 |
// Assume format string ends with newline |
|
724 |
keyValueList += |
|
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
725 |
Resources.format(Messages.PLOTTER_ACCESSIBLE_NAME_KEY_AND_VALUE, |
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
726 |
poolPlotter.toString(), value); |
2 | 727 |
if (poolPlotter.threshold > 0L) { |
728 |
String threshold = |
|
729 |
(poolPlotter.threshold * 100 / poolPlotter.max) + "%"; |
|
730 |
if (poolPlotter.value > poolPlotter.threshold) { |
|
731 |
keyValueList += |
|
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
732 |
Resources.format(Messages.MEMORY_TAB_POOL_CHART_ABOVE_THRESHOLD, |
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
733 |
threshold); |
2 | 734 |
} else { |
735 |
keyValueList += |
|
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
736 |
Resources.format(Messages.MEMORY_TAB_POOL_CHART_BELOW_THRESHOLD, |
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
737 |
threshold); |
2 | 738 |
} |
739 |
} |
|
740 |
} |
|
741 |
||
742 |
return name + "\n" + keyValueList + "."; |
|
743 |
} |
|
744 |
} |
|
745 |
} |
|
746 |
||
747 |
||
748 |
OverviewPanel[] getOverviewPanels() { |
|
749 |
if (overviewPanel == null) { |
|
750 |
overviewPanel = new MemoryOverviewPanel(); |
|
751 |
} |
|
752 |
return new OverviewPanel[] { overviewPanel }; |
|
753 |
} |
|
754 |
||
755 |
private static class MemoryOverviewPanel extends OverviewPanel { |
|
756 |
MemoryOverviewPanel() { |
|
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
757 |
super(Messages.HEAP_MEMORY_USAGE, usedKey, Messages.USED, Plotter.Unit.BYTES); |
2 | 758 |
} |
759 |
||
760 |
private void updateMemoryInfo(long used, long committed, long max) { |
|
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
761 |
getInfoLabel().setText(Resources.format(Messages.MEMORY_TAB_INFO_LABEL_FORMAT, |
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
762 |
formatBytes(used, true), |
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
763 |
formatBytes(committed, true), |
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
764 |
formatBytes(max, true))); |
2 | 765 |
} |
766 |
} |
|
767 |
} |