Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Oracle designates this
   * particular file as subject to the "Classpath" exception as provided
   * by Oracle in the LICENSE file that accompanied this code.
  *
  * This code is distributed in the hope that it will be useful, but WITHOUT
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * version 2 for more details (a copy is included in the LICENSE file that
  * accompanied this code).
  *
  * You should have received a copy of the GNU General Public License version
  * 2 along with this work; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 
 package sun.tools.jconsole;
 
 import java.awt.*;
 import java.io.*;
 import java.text.*;
 import java.util.*;
 
 import javax.swing.*;
 
 
 import static sun.tools.jconsole.Formatter.*;
 import static sun.tools.jconsole.Utilities.*;
 
 @SuppressWarnings("serial")
 class SummaryTab extends Tab {
     private static final String cpuUsageKey = "cpu";
 
     private static final String newDivider =   "<tr><td colspan=4><font size =-1><hr>";
     private static final String newTable =     "<tr><td colspan=4 align=left><table cellpadding=1>";
     private static final String newLeftTable = "<tr><td colspan=2 align=left><table cellpadding=1>";
     private static final String newRightTable =  "<td colspan=2 align=left><table cellpadding=1>";
     private static final String endTable = "</table>";
 
     private static final int CPU_DECIMALS = 1;
 
     private CPUOverviewPanel overviewPanel;
     private DateFormat headerDateTimeFormat;
     private String pathSeparator = null;
     HTMLPane info;
 
     private static class Result {
         long upTime = -1L;
         long processCpuTime = -1L;
         long timeStamp;
         int nCPUs;
         String summary;
     }
 
     public static String getTabName() {
         return .;
     }
 
     public SummaryTab(VMPanel vmPanel) {
         super(vmPanelgetTabName());
 
         setLayout(new BorderLayout());
 
          = new HTMLPane();
         setAccessibleName(getTabName());
         add(new JScrollPane());
 
          =
     }
 
     public SwingWorker<?, ?> newSwingWorker() {
         return new SwingWorker<ResultObject>() {
             public Result doInBackground() {
                 return formatSummary();
             }
 
 
             protected void done() {
                 try {
                     Result result = get();
                     if (result != null) {
                         .setText(result.summary);
                         if ( != null &&
                             result.upTime > 0L &&
                             result.processCpuTime >= 0L) {
 
                            .updateCPUInfo(result);
                        }
                    }
                } catch (InterruptedException ex) {
                } catch (ExecutionException ex) {
                    if (JConsole.isDebug()) {
                        ex.printStackTrace();
                    }
                }
            }
        };
    }
    synchronized Result formatSummary() {
        Result result = new Result();
        ProxyClient proxyClient = .getProxyClient();
        if (proxyClient.isDead()) {
            return null;
        }
         = new StringBuilder();
        append("<table cellpadding=1>");
        try {
            RuntimeMXBean         rmBean     = proxyClient.getRuntimeMXBean();
            CompilationMXBean     cmpMBean   = proxyClient.getCompilationMXBean();
            ThreadMXBean          tmBean     = proxyClient.getThreadMXBean();
            MemoryMXBean          memoryBean = proxyClient.getMemoryMXBean();
            ClassLoadingMXBean    clMBean    = proxyClient.getClassLoadingMXBean();
            OperatingSystemMXBean osMBean    = proxyClient.getOperatingSystemMXBean();
            com.sun.management.OperatingSystemMXBean sunOSMBean  =
               proxyClient.getSunOperatingSystemMXBean();
            append("<tr><td colspan=4>");
            append("<center><b>" + . + "</b></center>");
            String dateTime =
                .format(System.currentTimeMillis());
            append("<center>" + dateTime + "</center>");
            append();
            {  // VM info
                append();
                append(..getDisplayName());
                append(.,
                       Resources.format(.,
                                        rmBean.getVmName(), rmBean.getVmVersion()));
                append(.rmBean.getVmVendor());
                append(.rmBean.getName());
                append();
                append();
                result.upTime = rmBean.getUptime();
                append(.formatTime(result.upTime));
                if (sunOSMBean != null) {
                    result.processCpuTime = sunOSMBean.getProcessCpuTime();
                    append(.formatNanoTime(result.processCpuTime));
                }
                if (cmpMBean != null) {
                    append(.cmpMBean.getName());
                    append(.,
                           cmpMBean.isCompilationTimeMonitoringSupported()
                                    ? formatTime(cmpMBean.getTotalCompilationTime())
                                    : .);
                } else {
                    append(..);
                }
                append();
            }
            append();
            {  // Threads and Classes
                append();
                int tlCount = tmBean.getThreadCount();
                int tdCount = tmBean.getDaemonThreadCount();
                int tpCount = tmBean.getPeakThreadCount();
                long ttCount = tmBean.getTotalStartedThreadCount();
                String[] strings1 = formatLongs(tlCounttpCount,
                                                tdCountttCount);
                append(.strings1[0]);
                append(.strings1[1]);
                append(.strings1[2]);
                append(.strings1[3]);
                append();
                append();
                long clCount = clMBean.getLoadedClassCount();
                long cuCount = clMBean.getUnloadedClassCount();
                long ctCount = clMBean.getTotalLoadedClassCount();
                String[] strings2 = formatLongs(clCountcuCountctCount);
                append(.strings2[0]);
                append(.strings2[2]);
                append(.strings2[1]);
                append(null"");
                append();
            }
            append();
            {  // Memory
                MemoryUsage u = memoryBean.getHeapMemoryUsage();
                append();
                String[] strings1 = formatKByteStrings(u.getUsed(), u.getMax());
                append(.strings1[0]);
                append(.strings1[1]);
                append();
                append();
                String[] strings2 = formatKByteStrings(u.getCommitted());
                append(.,  strings2[0]);
                       .,
                       memoryBean.getObjectPendingFinalizationCount());
                append();
                append();
                Collection<GarbageCollectorMXBeangarbageCollectors =
                                            proxyClient.getGarbageCollectorMXBeans();
                for (GarbageCollectorMXBean garbageCollectorMBean : garbageCollectors) {
                    String gcName = garbageCollectorMBean.getName();
                    long gcCount = garbageCollectorMBean.getCollectionCount();
                    long gcTime = garbageCollectorMBean.getCollectionTime();
                    append(.,
                           Resources.format(.gcNamegcCount,
                                            (gcTime >= 0) ? formatTime(gcTime)
                                                 : .),
                           4);
                }
                append();
            }
            append();
            {  // Operating System info
                append();
                String osName = osMBean.getName();
                String osVersion = osMBean.getVersion();
                String osArch = osMBean.getArch();
                result.nCPUs = osMBean.getAvailableProcessors();
                append(.osName + " " + osVersion);
                append(.osArch);
                append(.result.nCPUs+"");
                if ( == null) {
                    // Must use separator of remote OS, not File.pathSeparator
                    // from this local VM. In the future, consider using
                    // RuntimeMXBean to get the remote system property.
                     = osName.startsWith("Windows ") ? ";" : ":";
                }
                if (sunOSMBean != null) {
                    String[] kbStrings1 =
                        formatKByteStrings(sunOSMBean.getCommittedVirtualMemorySize());
                    String[] kbStrings2 =
                        formatKByteStrings(sunOSMBean.getTotalPhysicalMemorySize(),
                                           sunOSMBean.getFreePhysicalMemorySize(),
                                           sunOSMBean.getTotalSwapSpaceSize(),
                                           sunOSMBean.getFreeSwapSpaceSize());
                    append(.kbStrings1[0]);
                    append();
                    append();
                    append(.kbStrings2[0]);
                    append(.,  kbStrings2[1]);
                    append(.,      kbStrings2[2]);
                    append(.,       kbStrings2[3]);
                }
                append();
            }
            append();
            {  // VM arguments and paths
                append();
                String args = "";
                java.util.List<StringinputArguments = rmBean.getInputArguments();
                for (String arg : inputArguments) {
                    args += arg + " ";
                }
                append(.args, 4);
                append(.,   rmBean.getClassPath(), 4);
                append(.rmBean.getLibraryPath(), 4);
                append(.,
                       rmBean.isBootClassPathSupported()
                                    ? rmBean.getBootClassPath()
                                    : .,
                       4);
                append();
            }
        } catch (IOException e) {
            if (JConsole.isDebug()) {
                e.printStackTrace();
            }
            proxyClient.markAsDead();
            return null;
        } catch (UndeclaredThrowableException e) {
            if (JConsole.isDebug()) {
                e.printStackTrace();
            }
            proxyClient.markAsDead();
            return null;
        }
        append("</table>");
        result.timeStamp = System.currentTimeMillis();
        result.summary = .toString();
        return result;
    }
    private synchronized void append(String str) {
        .append(str);
    }
    void append(String labelString value) {
        append(newRow(labelvalue));
    }
    private void append(String labelString valueint columnPerRow) {
        if (columnPerRow == 4 &&  != null) {
            value = value.replace(,
                                  "<b></b>" + );
        }
        append(newRow(labelvaluecolumnPerRow));
    }
        if ( == null) {
             = new CPUOverviewPanel();
        }
        return new OverviewPanel[] {  };
    }
    private static class CPUOverviewPanel extends OverviewPanel {
        private long prevUpTimeprevProcessCpuTime;
        CPUOverviewPanel() {
            super(....);
            getPlotter().setDecimals();
        }
        public void updateCPUInfo(Result result) {
            if ( > 0L && result.upTime > ) {
                // elapsedCpu is in ns and elapsedTime is in ms.
                long elapsedCpu = result.processCpuTime - ;
                long elapsedTime = result.upTime - ;
                // cpuUsage could go higher than 100% because elapsedTime
                // and elapsedCpu are not fetched simultaneously. Limit to
                // 99% to avoid Plotter showing a scale from 0% to 200%.
                float cpuUsage =
                    Math.min(99F,
                             elapsedCpu / (elapsedTime * 10000F * result.nCPUs));
                cpuUsage = Math.max(0F, cpuUsage);
                getPlotter().addValues(result.timeStamp,
                                Math.round(cpuUsage * Math.pow(10.0, )));
                getInfoLabel().setText(Resources.format(.,
                                               String.format("%."++"f"cpuUsage)));
            }
            this. = result.upTime;
            this. = result.processCpuTime;
        }
    }