Java Code Examples for com.sun.management.GcInfo#getMemoryUsageBeforeGc()

The following examples show how to use com.sun.management.GcInfo#getMemoryUsageBeforeGc() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProxyTypeMapping.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 2
Source File: ProxyTypeMapping.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 3
Source File: ValidateOpenTypes.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 4
Source File: ProxyTypeMapping.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 5
Source File: ProxyTypeMapping.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 6
Source File: ProxyTypeMapping.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 7
Source File: ValidateOpenTypes.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 8
Source File: ValidateOpenTypes.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 9
Source File: ValidateOpenTypes.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 10
Source File: LastGCInfo.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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());
        }
    }
}
 
Example 11
Source File: LogGCNotifications.java    From garmadon with Apache License 2.0 5 votes vote down vote up
static void handleHSNotification(Notification notification, Object handback) {
    BiConsumer<Long, String> printer = (BiConsumer<Long, String>) handback;
    GarbageCollectionNotificationInfo gcNotifInfo = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData());
    GcInfo gcInfo = gcNotifInfo.getGcInfo();
    long start = gcInfo.getStartTime();
    long end = gcInfo.getEndTime();
    StringBuilder sb = new StringBuilder();
    sb.append(gcNotifInfo.getGcName());
    sb.append(" occurred at ");
    long serverStartTime = ManagementFactory.getRuntimeMXBean().getStartTime();
    sb.append(GC_TIME_FORMAT.get().format(new Date(start + serverStartTime)));
    sb.append(", took ");
    sb.append(end - start);
    sb.append("ms");
    String cause = gcNotifInfo.getGcCause();
    if (cause != null) {
        sb.append(" (");
        sb.append(cause);
        sb.append(") ");
    }
    Map<String, MemoryUsage> memoryUsageBeforeGc = gcInfo.getMemoryUsageBeforeGc();
    Map<String, MemoryUsage> memoryUsageAfterGc = gcInfo.getMemoryUsageAfterGc();
    for (Map.Entry<String, MemoryUsage> entry : memoryUsageAfterGc.entrySet()) {
        MemoryUsage before = memoryUsageBeforeGc.get(entry.getKey());
        MemoryUsage after = entry.getValue();
        long usedDelta = (before != null) ? (after.getUsed() - before.getUsed()) / 1024 : 0;
        if (usedDelta != 0) {
            sb.append(" ");
            sb.append(MXBeanHelper.normalizeName(entry.getKey()));
            sb.append("[").append(usedDelta > 0 ? "+" : "").append(usedDelta).append("]");
            sb.append("(").append(before.getUsed() / 1024).append("->").append(after.getUsed() / 1024).append(")");
        }
    }
    printer.accept(start, sb.toString());
}
 
Example 12
Source File: LastGCInfo.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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());
        }
    }
}
 
Example 13
Source File: GarbageCollectionNotificationContentTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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());
        }
    }
}
 
Example 14
Source File: LastGCInfo.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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());
        }
    }
}
 
Example 15
Source File: GarbageCollectionNotificationContentTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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());
        }
    }
}
 
Example 16
Source File: GarbageCollectionNotificationContentTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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());
        }
    }
}
 
Example 17
Source File: LastGCInfo.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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());
        }
    }
}
 
Example 18
Source File: LastGCInfo.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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());
        }
    }
}
 
Example 19
Source File: ProtobufGCNotifications.java    From garmadon with Apache License 2.0 4 votes vote down vote up
static void handleHSNotification(Notification notification, Object handback) {
    BiConsumer<Long, JVMStatisticsEventsProtos.GCStatisticsData> printer = (BiConsumer<Long, JVMStatisticsEventsProtos.GCStatisticsData>) handback;
    GarbageCollectionNotificationInfo gcNotifInfo = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData());
    GcInfo gcInfo = gcNotifInfo.getGcInfo();
    GcEvent gcEvent = new GcEvent(gcInfo.getStartTime(), gcInfo.getEndTime());
    long pauseTime = gcEvent.getPauseDuration();
    String collectorName = gcNotifInfo.getGcName();
    long serverStartTime = ManagementFactory.getRuntimeMXBean().getStartTime();
    long timestamp = gcInfo.getStartTime() + serverStartTime;
    String cause = gcNotifInfo.getGcCause();
    JVMStatisticsEventsProtos.GCStatisticsData.Builder builder = JVMStatisticsEventsProtos.GCStatisticsData.newBuilder();
    builder.setPauseTime(pauseTime);

    builder.setGcPauseRatio1Min((float) computeTotalPauseTime(gcEvents, gcEvent) / MILLIS_MINUTE * 100);
    gcEvents.add(gcEvent);

    builder.setCollectorName(collectorName);
    builder.setCause(cause);
    Map<String, MemoryUsage> memoryUsageBeforeGc = gcInfo.getMemoryUsageBeforeGc();
    Map<String, MemoryUsage> memoryUsageAfterGc = gcInfo.getMemoryUsageAfterGc();
    for (Map.Entry<String, MemoryUsage> entry : memoryUsageAfterGc.entrySet()) {
        MemoryUsage before = memoryUsageBeforeGc.get(entry.getKey());
        MemoryUsage after = entry.getValue();
        switch (MXBeanHelper.normalizeName(entry.getKey())) {
            case MXBeanHelper.MEMORY_POOL_CODE_HEADER:
                builder.setCodeBefore(before.getUsed());
                builder.setCodeAfter(after.getUsed());
                break;
            case MXBeanHelper.MEMORY_POOL_PERM_HEADER:
            case MXBeanHelper.MEMORY_POOL_METASPACE_HEADER:
                builder.setMetaspaceBefore(before.getUsed());
                builder.setMetaspaceAfter(after.getUsed());
                break;
            case MXBeanHelper.MEMORY_POOL_EDEN_HEADER:
                builder.setEdenBefore(before.getUsed());
                builder.setEdenAfter(after.getUsed());
                break;
            case MXBeanHelper.MEMORY_POOL_SURVIVOR_HEADER:
                builder.setSurvivorBefore(before.getUsed());
                builder.setSurvivorAfter(after.getUsed());
                break;
            case MXBeanHelper.MEMORY_POOL_OLD_HEADER:
                builder.setOldBefore(before.getUsed());
                builder.setOldAfter(after.getUsed());
                break;
            case MXBeanHelper.MEMORY_POOL_COMPRESSEDCLASSPACE_HEADER:
                // ignore
                break;
            default:
                throw new UnsupportedOperationException(entry.getKey() + " not supported");
        }
    }
    printer.accept(timestamp, builder.build());
}
 
Example 20
Source File: RingBufferGarbageCollectionLog.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public void handleNotification(final Notification notification, final Object handback) {
    if (!notification.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
        return;
    }

    final CompositeData compositeData = (CompositeData) notification.getUserData();
    final GarbageCollectionNotificationInfo gcNotification = GarbageCollectionNotificationInfo.from(compositeData);
    final GcInfo gcInfo = gcNotification.getGcInfo();

    final String gcName = gcNotification.getGcName();
    final String action = gcNotification.getGcAction();
    final String cause = gcNotification.getGcCause();

    final long startTime = jvmStartTime + gcInfo.getStartTime();
    final long endTime = jvmStartTime + gcInfo.getEndTime();

    final Map<String, MemoryUsage> usageAfter = gcInfo.getMemoryUsageAfterGc();
    final Map<String, MemoryUsage> usageBefore = gcInfo.getMemoryUsageBeforeGc();

    final List<GarbageCollectionEvent.GarbageCollectionHeapSize> heapSizes = new ArrayList<>();
    for (final Map.Entry<String, MemoryUsage> entry : usageAfter.entrySet()) {
        final MemoryUsage before = usageBefore.get(entry.getKey());
        if (before == null) {
            continue;
        }

        final MemoryUsage after = entry.getValue();
        if (after.getUsed() == before.getUsed()) {
            continue;
        }

        heapSizes.add(new StandardGarbageCollectionEvent.StandardGarbageCollectionHeapSize(entry.getKey(), before.getUsed(), after.getUsed()));
    }

    final GarbageCollectionEvent event = new StandardGarbageCollectionEvent(gcName, action, cause, startTime, endTime, heapSizes);

    if (gcInfo.getDuration() >= minDurationThreshold) {
        events.add(event);
    }

    synchronized (this) {
        final Tuple<Long, Long> previousTuple = timeAndCountPerAction.get(action);
        if (previousTuple == null){
            timeAndCountPerAction.put(action, new Tuple<>(gcInfo.getDuration(), 1L));
        } else {
            timeAndCountPerAction.put(action, new Tuple<>(gcInfo.getDuration() + previousTuple.getKey(), 1L + previousTuple.getValue()));
        }

        if (maxDurationEvent == null || event.getDuration() > maxDurationEvent.getDuration()) {
            maxDurationEvent = event;
        }
    }
}