当前位置: 首页>>代码示例>>Java>>正文


Java GarbageCollectionNotificationInfo.getGcInfo方法代码示例

本文整理汇总了Java中com.sun.management.GarbageCollectionNotificationInfo.getGcInfo方法的典型用法代码示例。如果您正苦于以下问题:Java GarbageCollectionNotificationInfo.getGcInfo方法的具体用法?Java GarbageCollectionNotificationInfo.getGcInfo怎么用?Java GarbageCollectionNotificationInfo.getGcInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.management.GarbageCollectionNotificationInfo的用法示例。


在下文中一共展示了GarbageCollectionNotificationInfo.getGcInfo方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleNotification

import com.sun.management.GarbageCollectionNotificationInfo; //导入方法依赖的package包/类
@Override
public void handleNotification(Notification notification, Object handback) {
    if (notification.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
        System.out.println("0XDEADBEAF");
        GarbageCollectionNotificationInfo notifInfo = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData());

        GcInfo gcInfo = notifInfo.getGcInfo();
        System.out.printf("Action: %s, %s, %s\n", notifInfo.getGcAction(), notifInfo.getGcCause(), notifInfo.getGcName());
        System.out.printf("Time: %d, %d, %d\n", gcInfo.getStartTime(), gcInfo.getEndTime(), gcInfo.getDuration());
        System.out.printf("Memory: %s, %s\n", gcInfo.getMemoryUsageBeforeGc().toString(), gcInfo.getMemoryUsageAfterGc().toString());



        Map<String, MemoryUsage> memBefore = notifInfo.getGcInfo().getMemoryUsageBeforeGc();
        Map<String, MemoryUsage> memAfter = notifInfo.getGcInfo().getMemoryUsageAfterGc();
        StringBuilder sb = new StringBuilder();
        sb.append("[").append(notifInfo.getGcAction()).append(" / ").append(notifInfo.getGcCause())
                .append(" / ").append(notifInfo.getGcName()).append(" / (");
        appendMemUsage(sb, memBefore);
        sb.append(") -> (");
        appendMemUsage(sb, memAfter);
        sb.append("), ").append(notifInfo.getGcInfo().getDuration()).append(" ms]");
        System.out.println(sb.toString());
    }
}
 
开发者ID:vitaly-chibrikov,项目名称:otus_java_2017_10,代码行数:26,代码来源:MemoryUtil.java

示例2: checkGarbageCollectionNotificationInfoContent

import com.sun.management.GarbageCollectionNotificationInfo; //导入方法依赖的package包/类
private static void checkGarbageCollectionNotificationInfoContent(GarbageCollectionNotificationInfo notif) throws Exception {
    System.out.println("GC notification for "+notif.getGcName());
    System.out.print("Action: "+notif.getGcAction());
    System.out.println(" Cause: "+notif.getGcCause());
    GcInfo info = notif.getGcInfo();
    System.out.print("GC Info #" + 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();

    List<String> pnames = new ArrayList<String>();
    for (Map.Entry entry : usage.entrySet() ) {
        String poolname = (String) entry.getKey();
        pnames.add(poolname);
        MemoryUsage busage = (MemoryUsage) entry.getValue();
        MemoryUsage ausage = (MemoryUsage) 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);
    }

    // check if memory usage for all memory pools are returned
    List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
    for (MemoryPoolMXBean p : pools ) {
        if (!pnames.contains(p.getName())) {
            throw new RuntimeException("GcInfo does not contain " +
                "memory usage for pool " + p.getName());
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:36,代码来源:GarbageCollectionNotificationContentTest.java

示例3: handleNotification

import com.sun.management.GarbageCollectionNotificationInfo; //导入方法依赖的package包/类
@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());
    }
  }
}
 
开发者ID:sedmelluq,项目名称:lavaplayer,代码行数:12,代码来源:GarbageCollectionMonitor.java

示例4: getGcInfo

import com.sun.management.GarbageCollectionNotificationInfo; //导入方法依赖的package包/类
private GcInfo getGcInfo(GarbageCollectionNotificationInfo info, GarbageCollectorMXBean bean) {
    if (bean instanceof com.sun.management.GarbageCollectorMXBean) {
        return ((com.sun.management.GarbageCollectorMXBean) bean).getLastGcInfo();
    }
    return info.getGcInfo();
}
 
开发者ID:brownsys,项目名称:tracing-framework,代码行数:7,代码来源:GarbageCollection.java

示例5: getGcInfo

import com.sun.management.GarbageCollectionNotificationInfo; //导入方法依赖的package包/类
private static GcInfo getGcInfo(GarbageCollectionNotificationInfo info, GarbageCollectorMXBean bean) {
    if (bean instanceof com.sun.management.GarbageCollectorMXBean) {
        return ((com.sun.management.GarbageCollectorMXBean) bean).getLastGcInfo();
    }
    return info.getGcInfo();
}
 
开发者ID:brownsys,项目名称:tracing-framework,代码行数:7,代码来源:XTraceGCUtils.java

示例6: handleNotification

import com.sun.management.GarbageCollectionNotificationInfo; //导入方法依赖的package包/类
public void handleNotification(final Notification notification, final Object handback)
{
    String type = notification.getType();
    if (type.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION))
    {
        // retrieve the garbage collection notification information
        CompositeData cd = (CompositeData) notification.getUserData();
        GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from(cd);
        String gcName = info.getGcName();
        GcInfo gcInfo = info.getGcInfo();

        long duration = gcInfo.getDuration();

        /*
         * The duration supplied in the notification info includes more than just
         * application stopped time for concurrent GCs. Try and do a better job coming up with a good stopped time
         * value by asking for and tracking cumulative time spent blocked in GC.
         */
        GCState gcState = gcStates.get(gcName);
        if (gcState.assumeGCIsPartiallyConcurrent)
        {
            long previousTotal = gcState.lastGcTotalDuration;
            long total = gcState.gcBean.getCollectionTime();
            gcState.lastGcTotalDuration = total;
            duration = total - previousTotal; // may be zero for a really fast collection
        }

        StringBuilder sb = new StringBuilder();
        sb.append(info.getGcName()).append(" GC in ").append(duration).append("ms.  ");
        long bytes = 0;
        Map<String, MemoryUsage> beforeMemoryUsage = gcInfo.getMemoryUsageBeforeGc();
        Map<String, MemoryUsage> afterMemoryUsage = gcInfo.getMemoryUsageAfterGc();
        for (String key : gcState.keys(info))
        {
            MemoryUsage before = beforeMemoryUsage.get(key);
            MemoryUsage after = afterMemoryUsage.get(key);
            if (after != null && after.getUsed() != before.getUsed())
            {
                sb.append(key).append(": ").append(before.getUsed());
                sb.append(" -> ");
                sb.append(after.getUsed());
                if (!key.equals(gcState.keys[gcState.keys.length - 1]))
                    sb.append("; ");
                bytes += before.getUsed() - after.getUsed();
            }
        }

        while (true)
        {
            State prev = state.get();
            if (state.compareAndSet(prev, new State(duration, bytes, prev)))
                break;
        }

        String st = sb.toString();
        if (GC_WARN_THRESHOLD_IN_MS != 0 && duration > GC_WARN_THRESHOLD_IN_MS)
            logger.warn(st);
        else if (duration > MIN_LOG_DURATION)
            logger.info(st);
        else if (logger.isTraceEnabled())
            logger.trace(st);

        if (duration > STAT_THRESHOLD)
            StatusLogger.log();

        // if we just finished an old gen collection and we're still using a lot of memory, try to reduce the pressure
        if (gcState.assumeGCIsOldGen)
            LifecycleTransaction.rescheduleFailedDeletions();
    }
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:71,代码来源:GCInspector.java


注:本文中的com.sun.management.GarbageCollectionNotificationInfo.getGcInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。