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