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 *
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.
24 */
25
26 package sun.tools.jconsole;
27
28 import java.awt.*;
29 import java.io.*;
30 import java.lang.management.*;
31 import java.lang.reflect.*;
32 import java.net.URL;
33 import java.text.*;
34 import java.util.*;
35 import java.util.concurrent.*;
36
37 import javax.swing.*;
38 import javax.swing.event.*;
39 import javax.swing.text.*;
40
41 import static sun.tools.jconsole.Formatter.*;
42 import static sun.tools.jconsole.Resources.*;
43 import static sun.tools.jconsole.Utilities.*;
44
45 @SuppressWarnings("serial")
46 class SummaryTab extends Tab {
47 private static final String cpuUsageKey = "cpu";
48 private static final String cpuUsageName = getText("CPU Usage");
49 private static final String cpuUsageFormat = "CPUUsageFormat";
50
51 private static final String newDivider = "<tr><td colspan=4><font size =-1><hr>";
52 private static final String newTable = "<tr><td colspan=4 align=left><table cellpadding=1>";
53 private static final String newLeftTable = "<tr><td colspan=2 align=left><table cellpadding=1>";
54 private static final String newRightTable = "<td colspan=2 align=left><table cellpadding=1>";
55 private static final String endTable = "</table>";
56
57 private static final int CPU_DECIMALS = 1;
58
59 private CPUOverviewPanel overviewPanel;
60 private DateFormat headerDateTimeFormat;
61 private String pathSeparator = null;
62 HTMLPane info;
63
64 private static class Result {
65 long upTime = -1L;
66 long processCpuTime = -1L;
67 long timeStamp;
68 int nCPUs;
69 String summary;
70 }
71
72 public static String getTabName() {
73 return Resources.getText("SummaryTab.tabName");
74 }
75
76 public SummaryTab(VMPanel vmPanel) {
77 super(vmPanel, getTabName());
78
79 setLayout(new BorderLayout());
80
81 info = new HTMLPane();
82 setAccessibleName(info, getTabName());
83 add(new JScrollPane(info));
84
85 headerDateTimeFormat =
86 getDateTimeFormat("SummaryTab.headerDateTimeFormat");
87 }
88
89 public SwingWorker<?, ?> newSwingWorker() {
90 return new SwingWorker<Result, Object>() {
91 public Result doInBackground() {
92 return formatSummary();
93 }
94
95
96 protected void done() {
97 try {
98 Result result = get();
99 if (result != null) {
100 info.setText(result.summary);
101 if (overviewPanel != null &&
102 result.upTime > 0L &&
103 result.processCpuTime >= 0L) {
104
105 overviewPanel.updateCPUInfo(result);
106 }
121 Result result = new Result();
122 ProxyClient proxyClient = vmPanel.getProxyClient();
123 if (proxyClient.isDead()) {
124 return null;
125 }
126
127 buf = new StringBuilder();
128 append("<table cellpadding=1>");
129
130 try {
131 RuntimeMXBean rmBean = proxyClient.getRuntimeMXBean();
132 CompilationMXBean cmpMBean = proxyClient.getCompilationMXBean();
133 ThreadMXBean tmBean = proxyClient.getThreadMXBean();
134 MemoryMXBean memoryBean = proxyClient.getMemoryMXBean();
135 ClassLoadingMXBean clMBean = proxyClient.getClassLoadingMXBean();
136 OperatingSystemMXBean osMBean = proxyClient.getOperatingSystemMXBean();
137 com.sun.management.OperatingSystemMXBean sunOSMBean =
138 proxyClient.getSunOperatingSystemMXBean();
139
140 append("<tr><td colspan=4>");
141 append("<center><b>" + getText("SummaryTab.tabName") + "</b></center>");
142 String dateTime =
143 headerDateTimeFormat.format(System.currentTimeMillis());
144 append("<center>" + dateTime + "</center>");
145
146 append(newDivider);
147
148 { // VM info
149 append(newLeftTable);
150 append("Connection name", vmPanel.getDisplayName());
151 append("Virtual Machine",
152 getText("SummaryTab.vmVersion",
153 rmBean.getVmName(), rmBean.getVmVersion()));
154 append("Vendor", rmBean.getVmVendor());
155 append("Name", rmBean.getName());
156 append(endTable);
157
158 append(newRightTable);
159 result.upTime = rmBean.getUptime();
160 append("Uptime", formatTime(result.upTime));
161 if (sunOSMBean != null) {
162 result.processCpuTime = sunOSMBean.getProcessCpuTime();
163 append("Process CPU time", formatNanoTime(result.processCpuTime));
164 }
165
166 if (cmpMBean != null) {
167 append("JIT compiler", cmpMBean.getName());
168 append("Total compile time",
169 cmpMBean.isCompilationTimeMonitoringSupported()
170 ? formatTime(cmpMBean.getTotalCompilationTime())
171 : getText("Unavailable"));
172 } else {
173 append("JIT compiler", getText("Unavailable"));
174 }
175 append(endTable);
176 }
177
178 append(newDivider);
179
180 { // Threads and Classes
181 append(newLeftTable);
182 int tlCount = tmBean.getThreadCount();
183 int tdCount = tmBean.getDaemonThreadCount();
184 int tpCount = tmBean.getPeakThreadCount();
185 long ttCount = tmBean.getTotalStartedThreadCount();
186 String[] strings1 = formatLongs(tlCount, tpCount,
187 tdCount, ttCount);
188 append("Live Threads", strings1[0]);
189 append("Peak", strings1[1]);
190 append("Daemon threads", strings1[2]);
191 append("Total threads started", strings1[3]);
192 append(endTable);
193
194 append(newRightTable);
195 long clCount = clMBean.getLoadedClassCount();
196 long cuCount = clMBean.getUnloadedClassCount();
197 long ctCount = clMBean.getTotalLoadedClassCount();
198 String[] strings2 = formatLongs(clCount, cuCount, ctCount);
199 append("Current classes loaded", strings2[0]);
200 append("Total classes loaded", strings2[2]);
201 append("Total classes unloaded", strings2[1]);
202 append(null, "");
203 append(endTable);
204 }
205
206 append(newDivider);
207
208 { // Memory
209 MemoryUsage u = memoryBean.getHeapMemoryUsage();
210
211 append(newLeftTable);
212 String[] strings1 = formatKByteStrings(u.getUsed(), u.getMax());
213 append("Current heap size", strings1[0]);
214 append("Maximum heap size", strings1[1]);
215 append(endTable);
216
217 append(newRightTable);
218 String[] strings2 = formatKByteStrings(u.getCommitted());
219 append("Committed memory", strings2[0]);
220 append("SummaryTab.pendingFinalization.label",
221 getText("SummaryTab.pendingFinalization.value",
222 memoryBean.getObjectPendingFinalizationCount()));
223 append(endTable);
224
225 append(newTable);
226 Collection<GarbageCollectorMXBean> garbageCollectors =
227 proxyClient.getGarbageCollectorMXBeans();
228 for (GarbageCollectorMXBean garbageCollectorMBean : garbageCollectors) {
229 String gcName = garbageCollectorMBean.getName();
230 long gcCount = garbageCollectorMBean.getCollectionCount();
231 long gcTime = garbageCollectorMBean.getCollectionTime();
232
233 append("Garbage collector",
234 getText("GcInfo", gcName, gcCount,
235 (gcTime >= 0) ? formatTime(gcTime)
236 : getText("Unavailable")),
237 4);
238 }
239 append(endTable);
240 }
241
242 append(newDivider);
243
244 { // Operating System info
245 append(newLeftTable);
246 String osName = osMBean.getName();
247 String osVersion = osMBean.getVersion();
248 String osArch = osMBean.getArch();
249 result.nCPUs = osMBean.getAvailableProcessors();
250 append("Operating System", osName + " " + osVersion);
251 append("Architecture", osArch);
252 append("Number of processors", result.nCPUs+"");
253
254 if (pathSeparator == null) {
255 // Must use separator of remote OS, not File.pathSeparator
256 // from this local VM. In the future, consider using
257 // RuntimeMXBean to get the remote system property.
258 pathSeparator = osName.startsWith("Windows ") ? ";" : ":";
259 }
260
261 if (sunOSMBean != null) {
262 String[] kbStrings1 =
263 formatKByteStrings(sunOSMBean.getCommittedVirtualMemorySize());
264
265 String[] kbStrings2 =
266 formatKByteStrings(sunOSMBean.getTotalPhysicalMemorySize(),
267 sunOSMBean.getFreePhysicalMemorySize(),
268 sunOSMBean.getTotalSwapSpaceSize(),
269 sunOSMBean.getFreeSwapSpaceSize());
270
271 append("Committed virtual memory", kbStrings1[0]);
272 append(endTable);
273
274 append(newRightTable);
275 append("Total physical memory", kbStrings2[0]);
276 append("Free physical memory", kbStrings2[1]);
277 append("Total swap space", kbStrings2[2]);
278 append("Free swap space", kbStrings2[3]);
279 }
280
281 append(endTable);
282 }
283
284 append(newDivider);
285
286 { // VM arguments and paths
287 append(newTable);
288 String args = "";
289 java.util.List<String> inputArguments = rmBean.getInputArguments();
290 for (String arg : inputArguments) {
291 args += arg + " ";
292 }
293 append("VM arguments", args, 4);
294 append("Class path", rmBean.getClassPath(), 4);
295 append("Library path", rmBean.getLibraryPath(), 4);
296 append("Boot class path",
297 rmBean.isBootClassPathSupported()
298 ? rmBean.getBootClassPath()
299 : getText("Unavailable"),
300 4);
301 append(endTable);
302 }
303 } catch (IOException e) {
304 if (JConsole.isDebug()) {
305 e.printStackTrace();
306 }
307 proxyClient.markAsDead();
308 return null;
309 } catch (UndeclaredThrowableException e) {
310 if (JConsole.isDebug()) {
311 e.printStackTrace();
312 }
313 proxyClient.markAsDead();
314 return null;
315 }
316
317 append("</table>");
318
319 result.timeStamp = System.currentTimeMillis();
320 result.summary = buf.toString();
321
322 return result;
323 }
324
325 private synchronized void append(String str) {
326 buf.append(str);
327 }
328
329 void append(String label, String value) {
330 append(newRow((label != null) ? getText(label) : label, value));
331 }
332
333 private void append(String label, String value, int columnPerRow) {
334 if (columnPerRow == 4 && pathSeparator != null) {
335 value = value.replace(pathSeparator,
336 "<b></b>" + pathSeparator);
337 }
338 append(newRow(getText(label), value, columnPerRow));
339 }
340
341 void append(String label1, String value1,
342 String label2, String value2) {
343 append(newRow(getText(label1), value1,
344 getText(label2), value2));
345 }
346
347 OverviewPanel[] getOverviewPanels() {
348 if (overviewPanel == null) {
349 overviewPanel = new CPUOverviewPanel();
350 }
351 return new OverviewPanel[] { overviewPanel };
352 }
353
354 private static class CPUOverviewPanel extends OverviewPanel {
355 private long prevUpTime, prevProcessCpuTime;
356
357 CPUOverviewPanel() {
358 super(getText("CPU Usage"), cpuUsageKey, cpuUsageName, Plotter.Unit.PERCENT);
359 getPlotter().setDecimals(CPU_DECIMALS);
360 }
361
362 public void updateCPUInfo(Result result) {
363 if (prevUpTime > 0L && result.upTime > prevUpTime) {
364 // elapsedCpu is in ns and elapsedTime is in ms.
365 long elapsedCpu = result.processCpuTime - prevProcessCpuTime;
366 long elapsedTime = result.upTime - prevUpTime;
367 // cpuUsage could go higher than 100% because elapsedTime
368 // and elapsedCpu are not fetched simultaneously. Limit to
369 // 99% to avoid Plotter showing a scale from 0% to 200%.
370 float cpuUsage =
371 Math.min(99F,
372 elapsedCpu / (elapsedTime * 10000F * result.nCPUs));
373
374 getPlotter().addValues(result.timeStamp,
375 Math.round(cpuUsage * Math.pow(10.0, CPU_DECIMALS)));
376 getInfoLabel().setText(getText(cpuUsageFormat,
377 String.format("%."+CPU_DECIMALS+"f", cpuUsage)));
378 }
379 this.prevUpTime = result.upTime;
380 this.prevProcessCpuTime = result.processCpuTime;
381 }
382 }
383
384
385
386 }
|
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 *
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.
24 */
25
26 package sun.tools.jconsole;
27
28 import java.awt.*;
29 import java.io.*;
30 import java.lang.management.*;
31 import java.lang.reflect.*;
32 import java.text.*;
33 import java.util.*;
34 import java.util.concurrent.*;
35
36 import javax.swing.*;
37
38
39 import static sun.tools.jconsole.Formatter.*;
40 import static sun.tools.jconsole.Utilities.*;
41
42 @SuppressWarnings("serial")
43 class SummaryTab extends Tab {
44 private static final String cpuUsageKey = "cpu";
45
46 private static final String newDivider = "<tr><td colspan=4><font size =-1><hr>";
47 private static final String newTable = "<tr><td colspan=4 align=left><table cellpadding=1>";
48 private static final String newLeftTable = "<tr><td colspan=2 align=left><table cellpadding=1>";
49 private static final String newRightTable = "<td colspan=2 align=left><table cellpadding=1>";
50 private static final String endTable = "</table>";
51
52 private static final int CPU_DECIMALS = 1;
53
54 private CPUOverviewPanel overviewPanel;
55 private DateFormat headerDateTimeFormat;
56 private String pathSeparator = null;
57 HTMLPane info;
58
59 private static class Result {
60 long upTime = -1L;
61 long processCpuTime = -1L;
62 long timeStamp;
63 int nCPUs;
64 String summary;
65 }
66
67 public static String getTabName() {
68 return Messages.SUMMARY_TAB_TAB_NAME;
69 }
70
71 public SummaryTab(VMPanel vmPanel) {
72 super(vmPanel, getTabName());
73
74 setLayout(new BorderLayout());
75
76 info = new HTMLPane();
77 setAccessibleName(info, getTabName());
78 add(new JScrollPane(info));
79
80 headerDateTimeFormat =
81 Formatter.getDateTimeFormat(Messages.SUMMARY_TAB_HEADER_DATE_TIME_FORMAT);
82 }
83
84 public SwingWorker<?, ?> newSwingWorker() {
85 return new SwingWorker<Result, Object>() {
86 public Result doInBackground() {
87 return formatSummary();
88 }
89
90
91 protected void done() {
92 try {
93 Result result = get();
94 if (result != null) {
95 info.setText(result.summary);
96 if (overviewPanel != null &&
97 result.upTime > 0L &&
98 result.processCpuTime >= 0L) {
99
100 overviewPanel.updateCPUInfo(result);
101 }
116 Result result = new Result();
117 ProxyClient proxyClient = vmPanel.getProxyClient();
118 if (proxyClient.isDead()) {
119 return null;
120 }
121
122 buf = new StringBuilder();
123 append("<table cellpadding=1>");
124
125 try {
126 RuntimeMXBean rmBean = proxyClient.getRuntimeMXBean();
127 CompilationMXBean cmpMBean = proxyClient.getCompilationMXBean();
128 ThreadMXBean tmBean = proxyClient.getThreadMXBean();
129 MemoryMXBean memoryBean = proxyClient.getMemoryMXBean();
130 ClassLoadingMXBean clMBean = proxyClient.getClassLoadingMXBean();
131 OperatingSystemMXBean osMBean = proxyClient.getOperatingSystemMXBean();
132 com.sun.management.OperatingSystemMXBean sunOSMBean =
133 proxyClient.getSunOperatingSystemMXBean();
134
135 append("<tr><td colspan=4>");
136 append("<center><b>" + Messages.SUMMARY_TAB_TAB_NAME + "</b></center>");
137 String dateTime =
138 headerDateTimeFormat.format(System.currentTimeMillis());
139 append("<center>" + dateTime + "</center>");
140
141 append(newDivider);
142
143 { // VM info
144 append(newLeftTable);
145 append(Messages.CONNECTION_NAME, vmPanel.getDisplayName());
146 append(Messages.VIRTUAL_MACHINE,
147 Resources.format(Messages.SUMMARY_TAB_VM_VERSION,
148 rmBean.getVmName(), rmBean.getVmVersion()));
149 append(Messages.VENDOR, rmBean.getVmVendor());
150 append(Messages.NAME, rmBean.getName());
151 append(endTable);
152
153 append(newRightTable);
154 result.upTime = rmBean.getUptime();
155 append(Messages.UPTIME, formatTime(result.upTime));
156 if (sunOSMBean != null) {
157 result.processCpuTime = sunOSMBean.getProcessCpuTime();
158 append(Messages.PROCESS_CPU_TIME, formatNanoTime(result.processCpuTime));
159 }
160
161 if (cmpMBean != null) {
162 append(Messages.JIT_COMPILER, cmpMBean.getName());
163 append(Messages.TOTAL_COMPILE_TIME,
164 cmpMBean.isCompilationTimeMonitoringSupported()
165 ? formatTime(cmpMBean.getTotalCompilationTime())
166 : Messages.UNAVAILABLE);
167 } else {
168 append(Messages.JIT_COMPILER, Messages.UNAVAILABLE);
169 }
170 append(endTable);
171 }
172
173 append(newDivider);
174
175 { // Threads and Classes
176 append(newLeftTable);
177 int tlCount = tmBean.getThreadCount();
178 int tdCount = tmBean.getDaemonThreadCount();
179 int tpCount = tmBean.getPeakThreadCount();
180 long ttCount = tmBean.getTotalStartedThreadCount();
181 String[] strings1 = formatLongs(tlCount, tpCount,
182 tdCount, ttCount);
183 append(Messages.LIVE_THREADS, strings1[0]);
184 append(Messages.PEAK, strings1[1]);
185 append(Messages.DAEMON_THREADS, strings1[2]);
186 append(Messages.TOTAL_THREADS_STARTED, strings1[3]);
187 append(endTable);
188
189 append(newRightTable);
190 long clCount = clMBean.getLoadedClassCount();
191 long cuCount = clMBean.getUnloadedClassCount();
192 long ctCount = clMBean.getTotalLoadedClassCount();
193 String[] strings2 = formatLongs(clCount, cuCount, ctCount);
194 append(Messages.CURRENT_CLASSES_LOADED, strings2[0]);
195 append(Messages.TOTAL_CLASSES_LOADED, strings2[2]);
196 append(Messages.TOTAL_CLASSES_UNLOADED, strings2[1]);
197 append(null, "");
198 append(endTable);
199 }
200
201 append(newDivider);
202
203 { // Memory
204 MemoryUsage u = memoryBean.getHeapMemoryUsage();
205
206 append(newLeftTable);
207 String[] strings1 = formatKByteStrings(u.getUsed(), u.getMax());
208 append(Messages.CURRENT_HEAP_SIZE, strings1[0]);
209 append(Messages.MAXIMUM_HEAP_SIZE, strings1[1]);
210 append(endTable);
211
212 append(newRightTable);
213 String[] strings2 = formatKByteStrings(u.getCommitted());
214 append(Messages.COMMITTED_MEMORY, strings2[0]);
215 append(Messages.SUMMARY_TAB_PENDING_FINALIZATION_LABEL,
216 Resources.format(Messages.SUMMARY_TAB_PENDING_FINALIZATION_VALUE,
217 memoryBean.getObjectPendingFinalizationCount()));
218 append(endTable);
219
220 append(newTable);
221 Collection<GarbageCollectorMXBean> garbageCollectors =
222 proxyClient.getGarbageCollectorMXBeans();
223 for (GarbageCollectorMXBean garbageCollectorMBean : garbageCollectors) {
224 String gcName = garbageCollectorMBean.getName();
225 long gcCount = garbageCollectorMBean.getCollectionCount();
226 long gcTime = garbageCollectorMBean.getCollectionTime();
227
228 append(Messages.GARBAGE_COLLECTOR,
229 Resources.format(Messages.GC_INFO, gcName, gcCount,
230 (gcTime >= 0) ? formatTime(gcTime)
231 : Messages.UNAVAILABLE),
232 4);
233 }
234 append(endTable);
235 }
236
237 append(newDivider);
238
239 { // Operating System info
240 append(newLeftTable);
241 String osName = osMBean.getName();
242 String osVersion = osMBean.getVersion();
243 String osArch = osMBean.getArch();
244 result.nCPUs = osMBean.getAvailableProcessors();
245 append(Messages.OPERATING_SYSTEM, osName + " " + osVersion);
246 append(Messages.ARCHITECTURE, osArch);
247 append(Messages.NUMBER_OF_PROCESSORS, result.nCPUs+"");
248
249 if (pathSeparator == null) {
250 // Must use separator of remote OS, not File.pathSeparator
251 // from this local VM. In the future, consider using
252 // RuntimeMXBean to get the remote system property.
253 pathSeparator = osName.startsWith("Windows ") ? ";" : ":";
254 }
255
256 if (sunOSMBean != null) {
257 String[] kbStrings1 =
258 formatKByteStrings(sunOSMBean.getCommittedVirtualMemorySize());
259
260 String[] kbStrings2 =
261 formatKByteStrings(sunOSMBean.getTotalPhysicalMemorySize(),
262 sunOSMBean.getFreePhysicalMemorySize(),
263 sunOSMBean.getTotalSwapSpaceSize(),
264 sunOSMBean.getFreeSwapSpaceSize());
265
266 append(Messages.COMMITTED_VIRTUAL_MEMORY, kbStrings1[0]);
267 append(endTable);
268
269 append(newRightTable);
270 append(Messages.TOTAL_PHYSICAL_MEMORY, kbStrings2[0]);
271 append(Messages.FREE_PHYSICAL_MEMORY, kbStrings2[1]);
272 append(Messages.TOTAL_SWAP_SPACE, kbStrings2[2]);
273 append(Messages.FREE_SWAP_SPACE, kbStrings2[3]);
274 }
275
276 append(endTable);
277 }
278
279 append(newDivider);
280
281 { // VM arguments and paths
282 append(newTable);
283 String args = "";
284 java.util.List<String> inputArguments = rmBean.getInputArguments();
285 for (String arg : inputArguments) {
286 args += arg + " ";
287 }
288 append(Messages.VM_ARGUMENTS, args, 4);
289 append(Messages.CLASS_PATH, rmBean.getClassPath(), 4);
290 append(Messages.LIBRARY_PATH, rmBean.getLibraryPath(), 4);
291 append(Messages.BOOT_CLASS_PATH,
292 rmBean.isBootClassPathSupported()
293 ? rmBean.getBootClassPath()
294 : Messages.UNAVAILABLE,
295 4);
296 append(endTable);
297 }
298 } catch (IOException e) {
299 if (JConsole.isDebug()) {
300 e.printStackTrace();
301 }
302 proxyClient.markAsDead();
303 return null;
304 } catch (UndeclaredThrowableException e) {
305 if (JConsole.isDebug()) {
306 e.printStackTrace();
307 }
308 proxyClient.markAsDead();
309 return null;
310 }
311
312 append("</table>");
313
314 result.timeStamp = System.currentTimeMillis();
315 result.summary = buf.toString();
316
317 return result;
318 }
319
320 private synchronized void append(String str) {
321 buf.append(str);
322 }
323
324 void append(String label, String value) {
325 append(newRow(label, value));
326 }
327
328 private void append(String label, String value, int columnPerRow) {
329 if (columnPerRow == 4 && pathSeparator != null) {
330 value = value.replace(pathSeparator,
331 "<b></b>" + pathSeparator);
332 }
333 append(newRow(label, value, columnPerRow));
334 }
335
336 OverviewPanel[] getOverviewPanels() {
337 if (overviewPanel == null) {
338 overviewPanel = new CPUOverviewPanel();
339 }
340 return new OverviewPanel[] { overviewPanel };
341 }
342
343 private static class CPUOverviewPanel extends OverviewPanel {
344 private long prevUpTime, prevProcessCpuTime;
345
346 CPUOverviewPanel() {
347 super(Messages.CPU_USAGE, cpuUsageKey, Messages.CPU_USAGE, Plotter.Unit.PERCENT);
348 getPlotter().setDecimals(CPU_DECIMALS);
349 }
350
351 public void updateCPUInfo(Result result) {
352 if (prevUpTime > 0L && result.upTime > prevUpTime) {
353 // elapsedCpu is in ns and elapsedTime is in ms.
354 long elapsedCpu = result.processCpuTime - prevProcessCpuTime;
355 long elapsedTime = result.upTime - prevUpTime;
356 // cpuUsage could go higher than 100% because elapsedTime
357 // and elapsedCpu are not fetched simultaneously. Limit to
358 // 99% to avoid Plotter showing a scale from 0% to 200%.
359 float cpuUsage =
360 Math.min(99F,
361 elapsedCpu / (elapsedTime * 10000F * result.nCPUs));
362
363 getPlotter().addValues(result.timeStamp,
364 Math.round(cpuUsage * Math.pow(10.0, CPU_DECIMALS)));
365 getInfoLabel().setText(Resources.format(Messages.CPU_USAGE_FORMAT,
366 String.format("%."+CPU_DECIMALS+"f", cpuUsage)));
367 }
368 this.prevUpTime = result.upTime;
369 this.prevProcessCpuTime = result.processCpuTime;
370 }
371 }
372 }
|