Search in sources :

Example 1 with GcInfo

use of com.sun.management.GcInfo in project jdk8u_jdk by JetBrains.

the class ValidateOpenTypes method printGcInfo.

private static void printGcInfo(CompositeData cd) throws Exception {
    GcInfo info = GcInfo.from(cd);
    System.out.print("GC #" + info.getId());
    System.out.print(" start:" + info.getStartTime());
    System.out.print(" end:" + info.getEndTime());
    System.out.println(" (" + info.getDuration() + "ms)");
    Map<String, MemoryUsage> usage = info.getMemoryUsageBeforeGc();
    for (Map.Entry<String, MemoryUsage> entry : usage.entrySet()) {
        String poolname = entry.getKey();
        MemoryUsage busage = entry.getValue();
        MemoryUsage ausage = info.getMemoryUsageAfterGc().get(poolname);
        if (ausage == null) {
            throw new RuntimeException("After Gc Memory does not exist" + " for " + poolname);
        }
        System.out.println("Usage for pool " + poolname);
        System.out.println("   Before GC: " + busage);
        System.out.println("   After GC: " + ausage);
    }
}
Also used : GcInfo(com.sun.management.GcInfo) Map(java.util.Map)

Example 2 with GcInfo

use of com.sun.management.GcInfo in project jdk8u_jdk by JetBrains.

the class LastGCInfo method main.

public static void main(String[] argv) throws Exception {
    boolean hasGcInfo = false;
    System.gc();
    List mgrs = ManagementFactory.getGarbageCollectorMXBeans();
    for (ListIterator iter = mgrs.listIterator(); iter.hasNext(); ) {
        Object mgr = iter.next();
        if (mgr instanceof GarbageCollectorMXBean) {
            GarbageCollectorMXBean gc = (GarbageCollectorMXBean) mgr;
            GcInfo info = gc.getLastGcInfo();
            if (info != null) {
                checkGcInfo(gc.getName(), info);
                hasGcInfo = true;
            }
        }
    }
    if (!hasGcInfo) {
        throw new RuntimeException("No GcInfo returned");
    }
    System.out.println("Test passed.");
}
Also used : GcInfo(com.sun.management.GcInfo) GarbageCollectorMXBean(com.sun.management.GarbageCollectorMXBean)

Example 3 with GcInfo

use of com.sun.management.GcInfo in project lavaplayer by sedmelluq.

the class GarbageCollectionMonitor method handleNotification.

@Override
public void handleNotification(Notification notification, Object handback) {
    if (GARBAGE_COLLECTION_NOTIFICATION.equals(notification.getType())) {
        GarbageCollectionNotificationInfo notificationInfo = from((CompositeData) notification.getUserData());
        GcInfo info = notificationInfo.getGcInfo();
        if (info != null && !"No GC".equals(notificationInfo.getGcCause())) {
            registerPause(info.getDuration());
        }
    }
}
Also used : GarbageCollectionNotificationInfo(com.sun.management.GarbageCollectionNotificationInfo) GcInfo(com.sun.management.GcInfo)

Example 4 with GcInfo

use of com.sun.management.GcInfo in project openj9 by eclipse.

the class GarbageCollectionNotificationTest method beforeTest.

@BeforeTest
public void beforeTest() {
    // get all GarbageCollectorMXBeans
    List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans();
    // register every GarbageCollectorMXBean
    for (GarbageCollectorMXBean gcBean : gcBeans) {
        gcStates.put(gcBean.getName(), new GCState(gcBean, assumeGCIsPartiallyConcurrent(gcBean), assumeGCIsOldGen(gcBean)));
        NotificationEmitter emitter = (NotificationEmitter) gcBean;
        // new listener
        NotificationListener listener = new NotificationListener() {

            // record total gc time spend
            long totalGcTimeSpend = 0;

            @Override
            public void handleNotification(Notification notification, Object handback) {
                HandBack handBack = (HandBack) handback;
                // get gc info
                GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData());
                // output
                // get a glance of gc
                StringBuilder gcGlance = new StringBuilder();
                String gcName = info.getGcName();
                GCState gcState = gcStates.get(gcName);
                GcInfo gcInfo = info.getGcInfo();
                long gcId = gcInfo.getId();
                gcGlance.append(info.getGcAction()).append(" (").append(gcName).append(") : - ").append(gcId);
                gcGlance.append(" (").append(info.getGcCause()).append(") ");
                gcGlance.append("start: ").append(dateFormat.format(new Date(JVM_START_TIME + gcInfo.getStartTime())));
                gcGlance.append(", end: ").append(dateFormat.format(new Date(JVM_START_TIME + gcInfo.getEndTime())));
                logger.debug(gcGlance.toString());
                AssertJUnit.assertTrue("startTime(" + gcInfo.getStartTime() + ") should be smaller than endTime(" + gcInfo.getEndTime() + ").", gcInfo.getStartTime() <= gcInfo.getEndTime());
                if (0 != gcState.lastCollectionID) {
                    AssertJUnit.assertTrue("lastCollectionID+1(" + (gcState.lastCollectionID + 1) + ") should match gcId(" + gcId + ")", gcId == (gcState.lastCollectionID + 1));
                }
                gcState.lastCollectionID = gcId;
                gcState.totalCollectionCount += 1;
                gcState.totalCollectionDuration += gcInfo.getDuration();
                // memory info
                Map<String, MemoryUsage> beforeUsageMap = gcInfo.getMemoryUsageBeforeGc();
                Map<String, MemoryUsage> afterUsageMap = gcInfo.getMemoryUsageAfterGc();
                for (Map.Entry<String, MemoryUsage> entry : afterUsageMap.entrySet()) {
                    String name = entry.getKey();
                    MemoryUsage afterUsage = entry.getValue();
                    MemoryUsage beforeUsage = beforeUsageMap.get(name);
                    StringBuilder usage = new StringBuilder();
                    // $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
                    usage.append("\t[").append(String.format("%32s", name)).append("] \t");
                    // $NON-NLS-1$ //$NON-NLS-2$
                    usage.append("init:").append(afterUsage.getInit() / ONE_KBYTE).append("K;\t");
                    usage.append("used:").append(// $NON-NLS-1$
                    handBack.handUsage(beforeUsage.getUsed(), afterUsage.getUsed(), beforeUsage.getMax())).append(// $NON-NLS-1$
                    ";\t");
                    usage.append("committed: ").append(// $NON-NLS-1$
                    handBack.handUsage(beforeUsage.getCommitted(), afterUsage.getCommitted(), beforeUsage.getMax()));
                    logger.debug(usage.toString());
                }
                totalGcTimeSpend += gcInfo.getDuration();
                // summary
                long percent = (gcInfo.getEndTime() - totalGcTimeSpend) * 1000L / gcInfo.getEndTime();
                StringBuilder summary = new StringBuilder();
                summary.append("duration:").append(gcInfo.getDuration()).append("ms");
                // $NON-NLS-1$//$NON-NLS-2$
                summary.append(", throughput:").append((percent / 10)).append(".").append(percent % 10).append('%');
                logger.debug(summary.toString());
                logger.debug("\n");
            }
        };
        // add the listener
        emitter.addNotificationListener(listener, new NotificationFilter() {

            private static final long serialVersionUID = 3763793138186359389L;

            @Override
            public boolean isNotificationEnabled(Notification notification) {
                // filter GC notification
                return notification.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION);
            }
        }, HandBack.getInstance());
    }
}
Also used : GarbageCollectionNotificationInfo(com.sun.management.GarbageCollectionNotificationInfo) GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) MemoryUsage(java.lang.management.MemoryUsage) Notification(javax.management.Notification) Date(java.util.Date) NotificationEmitter(javax.management.NotificationEmitter) GcInfo(com.sun.management.GcInfo) HashMap(java.util.HashMap) Map(java.util.Map) NotificationFilter(javax.management.NotificationFilter) NotificationListener(javax.management.NotificationListener) BeforeTest(org.testng.annotations.BeforeTest)

Example 5 with GcInfo

use of com.sun.management.GcInfo in project jdk8u_jdk by JetBrains.

the class ProxyTypeMapping method checkSunGC.

private static void checkSunGC() throws Exception {
    // Test com.sun.management proxy
    List<GarbageCollectorMXBean> gcs = getGarbageCollectorMXBeans();
    for (GarbageCollectorMXBean gc : gcs) {
        com.sun.management.GarbageCollectorMXBean sunGc = newPlatformMXBeanProxy(server, GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE + ",name=" + gc.getName(), com.sun.management.GarbageCollectorMXBean.class);
        GcInfo info = sunGc.getLastGcInfo();
        if (info != null) {
            System.out.println("GC statistic for : " + gc.getName());
            printGcInfo(info);
        }
    }
}
Also used : GcInfo(com.sun.management.GcInfo) java.lang.management(java.lang.management) javax.management(javax.management)

Aggregations

GcInfo (com.sun.management.GcInfo)12 GarbageCollectionNotificationInfo (com.sun.management.GarbageCollectionNotificationInfo)5 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)3 MemoryUsage (java.lang.management.MemoryUsage)3 NotificationEmitter (javax.management.NotificationEmitter)3 CompositeData (javax.management.openmbean.CompositeData)3 Map (java.util.Map)2 Notification (javax.management.Notification)2 NotificationListener (javax.management.NotificationListener)2 Duration (com.github.joschi.jadconfig.util.Duration)1 GarbageCollectorMXBeanImpl (com.ibm.java.lang.management.internal.GarbageCollectorMXBeanImpl)1 GarbageCollectorMXBean (com.sun.management.GarbageCollectorMXBean)1 IOException (java.io.IOException)1 java.lang.management (java.lang.management)1 MemoryManagerMXBean (java.lang.management.MemoryManagerMXBean)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 javax.management (javax.management)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1