jdk/src/share/classes/sun/tools/jconsole/SummaryTab.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2 90ce3da70b43
child 12851 3334e1c781d0
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2004, 2007, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.tools.jconsole;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.lang.management.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.lang.reflect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.concurrent.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.swing.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import static sun.tools.jconsole.Formatter.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import static sun.tools.jconsole.Resources.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import static sun.tools.jconsole.Utilities.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
@SuppressWarnings("serial")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
class SummaryTab extends Tab {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private static final String cpuUsageKey = "cpu";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static final String cpuUsageName = getText("CPU Usage");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private static final String cpuUsageFormat = "CPUUsageFormat";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static final String newDivider =   "<tr><td colspan=4><font size =-1><hr>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private static final String newTable =     "<tr><td colspan=4 align=left><table cellpadding=1>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private static final String newLeftTable = "<tr><td colspan=2 align=left><table cellpadding=1>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private static final String newRightTable =  "<td colspan=2 align=left><table cellpadding=1>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private static final String endTable = "</table>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private static final int CPU_DECIMALS = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private CPUOverviewPanel overviewPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private DateFormat headerDateTimeFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private String pathSeparator = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    HTMLPane info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private static class Result {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        long upTime = -1L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        long processCpuTime = -1L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        long timeStamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        int nCPUs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        String summary;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public static String getTabName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        return Resources.getText("SummaryTab.tabName");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public SummaryTab(VMPanel vmPanel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        super(vmPanel, getTabName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        info = new HTMLPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        setAccessibleName(info, getTabName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        add(new JScrollPane(info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        headerDateTimeFormat =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            getDateTimeFormat("SummaryTab.headerDateTimeFormat");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public SwingWorker<?, ?> newSwingWorker() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        return new SwingWorker<Result, Object>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            public Result doInBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                return formatSummary();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            protected void done() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                    Result result = get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                    if (result != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                        info.setText(result.summary);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                        if (overviewPanel != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                            result.upTime > 0L &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                            result.processCpuTime >= 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                            overviewPanel.updateCPUInfo(result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                } catch (InterruptedException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                } catch (ExecutionException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                    if (JConsole.isDebug()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                        ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    StringBuilder buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    synchronized Result formatSummary() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        Result result = new Result();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        ProxyClient proxyClient = vmPanel.getProxyClient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        if (proxyClient.isDead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        buf = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        append("<table cellpadding=1>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            RuntimeMXBean         rmBean     = proxyClient.getRuntimeMXBean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            CompilationMXBean     cmpMBean   = proxyClient.getCompilationMXBean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            ThreadMXBean          tmBean     = proxyClient.getThreadMXBean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            MemoryMXBean          memoryBean = proxyClient.getMemoryMXBean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            ClassLoadingMXBean    clMBean    = proxyClient.getClassLoadingMXBean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            OperatingSystemMXBean osMBean    = proxyClient.getOperatingSystemMXBean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            com.sun.management.OperatingSystemMXBean sunOSMBean  =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
               proxyClient.getSunOperatingSystemMXBean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            append("<tr><td colspan=4>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            append("<center><b>" + getText("SummaryTab.tabName") + "</b></center>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            String dateTime =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                headerDateTimeFormat.format(System.currentTimeMillis());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            append("<center>" + dateTime + "</center>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            append(newDivider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            {  // VM info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                append(newLeftTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                append("Connection name", vmPanel.getDisplayName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                append("Virtual Machine",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                       getText("SummaryTab.vmVersion",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                               rmBean.getVmName(), rmBean.getVmVersion()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                append("Vendor", rmBean.getVmVendor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                append("Name", rmBean.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                append(endTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                append(newRightTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                result.upTime = rmBean.getUptime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                append("Uptime", formatTime(result.upTime));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                if (sunOSMBean != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                    result.processCpuTime = sunOSMBean.getProcessCpuTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                    append("Process CPU time", formatNanoTime(result.processCpuTime));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                if (cmpMBean != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                    append("JIT compiler", cmpMBean.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                    append("Total compile time",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                           cmpMBean.isCompilationTimeMonitoringSupported()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                                    ? formatTime(cmpMBean.getTotalCompilationTime())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                                    : getText("Unavailable"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    append("JIT compiler", getText("Unavailable"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                append(endTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            append(newDivider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            {  // Threads and Classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                append(newLeftTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                int tlCount = tmBean.getThreadCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                int tdCount = tmBean.getDaemonThreadCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                int tpCount = tmBean.getPeakThreadCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                long ttCount = tmBean.getTotalStartedThreadCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                String[] strings1 = formatLongs(tlCount, tpCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                                                tdCount, ttCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                append("Live Threads",          strings1[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                append("Peak",                  strings1[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                append("Daemon threads",        strings1[2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                append("Total threads started", strings1[3]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                append(endTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                append(newRightTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                long clCount = clMBean.getLoadedClassCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                long cuCount = clMBean.getUnloadedClassCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                long ctCount = clMBean.getTotalLoadedClassCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                String[] strings2 = formatLongs(clCount, cuCount, ctCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                append("Current classes loaded", strings2[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                append("Total classes loaded",   strings2[2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                append("Total classes unloaded", strings2[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                append(null, "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                append(endTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            append(newDivider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            {  // Memory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                MemoryUsage u = memoryBean.getHeapMemoryUsage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                append(newLeftTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                String[] strings1 = formatKByteStrings(u.getUsed(), u.getMax());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                append("Current heap size", strings1[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                append("Maximum heap size", strings1[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                append(endTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                append(newRightTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                String[] strings2 = formatKByteStrings(u.getCommitted());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                append("Committed memory",  strings2[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                append("SummaryTab.pendingFinalization.label",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                       getText("SummaryTab.pendingFinalization.value",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                               memoryBean.getObjectPendingFinalizationCount()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                append(endTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                append(newTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                Collection<GarbageCollectorMXBean> garbageCollectors =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                                            proxyClient.getGarbageCollectorMXBeans();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                for (GarbageCollectorMXBean garbageCollectorMBean : garbageCollectors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                    String gcName = garbageCollectorMBean.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                    long gcCount = garbageCollectorMBean.getCollectionCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                    long gcTime = garbageCollectorMBean.getCollectionTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                    append("Garbage collector",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                           getText("GcInfo", gcName, gcCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                                   (gcTime >= 0) ? formatTime(gcTime)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                                                 : getText("Unavailable")),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                           4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                append(endTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            append(newDivider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            {  // Operating System info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                append(newLeftTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                String osName = osMBean.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                String osVersion = osMBean.getVersion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                String osArch = osMBean.getArch();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                result.nCPUs = osMBean.getAvailableProcessors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                append("Operating System", osName + " " + osVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                append("Architecture", osArch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                append("Number of processors", result.nCPUs+"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                if (pathSeparator == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                    // Must use separator of remote OS, not File.pathSeparator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                    // from this local VM. In the future, consider using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                    // RuntimeMXBean to get the remote system property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                    pathSeparator = osName.startsWith("Windows ") ? ";" : ":";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                if (sunOSMBean != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    String[] kbStrings1 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                        formatKByteStrings(sunOSMBean.getCommittedVirtualMemorySize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                    String[] kbStrings2 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                        formatKByteStrings(sunOSMBean.getTotalPhysicalMemorySize(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                                           sunOSMBean.getFreePhysicalMemorySize(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                                           sunOSMBean.getTotalSwapSpaceSize(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                                           sunOSMBean.getFreeSwapSpaceSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                    append("Committed virtual memory", kbStrings1[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                    append(endTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                    append(newRightTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                    append("Total physical memory", kbStrings2[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                    append("Free physical memory",  kbStrings2[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                    append("Total swap space",      kbStrings2[2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                    append("Free swap space",       kbStrings2[3]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                append(endTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            append(newDivider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            {  // VM arguments and paths
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                append(newTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                String args = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                java.util.List<String> inputArguments = rmBean.getInputArguments();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                for (String arg : inputArguments) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                    args += arg + " ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                append("VM arguments", args, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                append("Class path",   rmBean.getClassPath(), 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                append("Library path", rmBean.getLibraryPath(), 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                append("Boot class path",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                       rmBean.isBootClassPathSupported()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                                    ? rmBean.getBootClassPath()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                                    : getText("Unavailable"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                       4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                append(endTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            if (JConsole.isDebug()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            proxyClient.markAsDead();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        } catch (UndeclaredThrowableException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            if (JConsole.isDebug()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            proxyClient.markAsDead();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        append("</table>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        result.timeStamp = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        result.summary = buf.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    private synchronized void append(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        buf.append(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    void append(String label, String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        append(newRow((label != null) ? getText(label) : label, value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    private void append(String label, String value, int columnPerRow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        if (columnPerRow == 4 && pathSeparator != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            value = value.replace(pathSeparator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                                  "<b></b>" + pathSeparator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        append(newRow(getText(label), value, columnPerRow));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    void append(String label1, String value1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                String label2, String value2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        append(newRow(getText(label1), value1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                      getText(label2), value2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    OverviewPanel[] getOverviewPanels() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        if (overviewPanel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            overviewPanel = new CPUOverviewPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        return new OverviewPanel[] { overviewPanel };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    private static class CPUOverviewPanel extends OverviewPanel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        private long prevUpTime, prevProcessCpuTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        CPUOverviewPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            super(getText("CPU Usage"), cpuUsageKey, cpuUsageName, Plotter.Unit.PERCENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            getPlotter().setDecimals(CPU_DECIMALS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        public void updateCPUInfo(Result result) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            if (prevUpTime > 0L && result.upTime > prevUpTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                // elapsedCpu is in ns and elapsedTime is in ms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                long elapsedCpu = result.processCpuTime - prevProcessCpuTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                long elapsedTime = result.upTime - prevUpTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                // cpuUsage could go higher than 100% because elapsedTime
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                // and elapsedCpu are not fetched simultaneously. Limit to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                // 99% to avoid Plotter showing a scale from 0% to 200%.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                float cpuUsage =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                    Math.min(99F,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                             elapsedCpu / (elapsedTime * 10000F * result.nCPUs));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                getPlotter().addValues(result.timeStamp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                                Math.round(cpuUsage * Math.pow(10.0, CPU_DECIMALS)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                getInfoLabel().setText(getText(cpuUsageFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                                               String.format("%."+CPU_DECIMALS+"f", cpuUsage)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            this.prevUpTime = result.upTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            this.prevProcessCpuTime = result.processCpuTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
}