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


Java GcInfo.getMemoryUsageBeforeGc方法代码示例

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


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

示例1: printGcInfo

import com.sun.management.GcInfo; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:ValidateOpenTypes.java

示例2: printGcInfo

import com.sun.management.GcInfo; //导入方法依赖的package包/类
private static void printGcInfo(GcInfo info) throws Exception {
    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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:ProxyTypeMapping.java

示例3: handleNotification

import com.sun.management.GcInfo; //导入方法依赖的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

示例4: checkGarbageCollectionNotificationInfoContent

import com.sun.management.GcInfo; //导入方法依赖的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

示例5: checkGcInfo

import com.sun.management.GcInfo; //导入方法依赖的package包/类
private static void checkGcInfo(String name, GcInfo info) throws Exception {
    System.out.println("GC statistic for : " + name);
    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 usage = info.getMemoryUsageBeforeGc();

    List pnames = new ArrayList();
    for (Iterator iter = usage.entrySet().iterator(); iter.hasNext(); ) {
        Map.Entry entry = (Map.Entry) iter.next();
        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 pools = ManagementFactory.getMemoryPoolMXBeans();
    for (Iterator iter = pools.iterator(); iter.hasNext(); ) {
        MemoryPoolMXBean p = (MemoryPoolMXBean) iter.next();
        if (!pnames.contains(p.getName())) {
            throw new RuntimeException("GcInfo does not contain " +
                "memory usage for pool " + p.getName());
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:35,代码来源:LastGCInfo.java


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