Java Code Examples for com.sun.management.GarbageCollectionNotificationInfo#getGcInfo()

The following examples show how to use com.sun.management.GarbageCollectionNotificationInfo#getGcInfo() . 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: GCNotificationEventEmitter.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Handles a JMX {@link Notification} emitted by one of the GC beans that we're listening to. This
 * function is called on a special runtime thread that is not visible to debuggers, so if you're
 * trying to break in this method and it's not working, that's why.
 *
 * <p>Since this is called on a special thread, it's important that it 1) not block and 2)
 * terminate as quickly as possible.
 *
 * @param notification The notification that we've just received from JMX
 * @param handback An instance of the {@link GarbageCollectorMXBean} that triggered the event,
 *     which we passed explicitly as the third parameter of {@link
 *     NotificationEmitter#addNotificationListener(NotificationListener, NotificationFilter,
 *     Object)} in the class constructor.
 */
@Override
public void handleNotification(Notification notification, Object handback) {
  // It's unlikely that the GC bean emits anything other than GC notifications, but the docs say
  // to check, so we do.
  if (notification
      .getType()
      .equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
    GarbageCollectionNotificationInfo notificationInfo =
        GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData());
    GcInfo info = notificationInfo.getGcInfo();
    if (isMinorGCBean((GarbageCollectorMXBean) handback)) {
      eventBus.post(new GCMinorCollectionEvent(info));
    } else {
      eventBus.post(new GCMajorCollectionEvent(info));
    }
  }
}
 
Example 2
Source File: GarbageCollectionNotificationContentTest.java    From jdk8u-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 3
Source File: GarbageCollectionNotificationContentTest.java    From jdk8u-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 4
Source File: GarbageCollectionMonitor.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
@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());
    }
  }
}
 
Example 5
Source File: GarbageCollectionNotificationContentTest.java    From openjdk-8 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 6
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 7
Source File: GarbageCollectionNotificationContentTest.java    From hottub 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 8
Source File: GcNotificationListener.java    From Lavalink with MIT License 5 votes vote down vote up
@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())) {
            gcPauses.observe(info.getDuration() / Collector.MILLISECONDS_PER_SECOND);
        }
    }
}
 
Example 9
Source File: GarbageCollectionNotificationContentTest.java    From openjdk-jdk9 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 10
Source File: GarbageCollectionNotificationContentTest.java    From jdk8u-dev-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 11
Source File: JvmHeapPressureMetrics.java    From micrometer with Apache License 2.0 5 votes vote down vote up
private void monitor() {
    double maxOldGen = JvmMemory.getOldGen().map(mem -> JvmMemory.getUsageValue(mem, MemoryUsage::getMax)).orElse(0.0);

    for (GarbageCollectorMXBean mbean : ManagementFactory.getGarbageCollectorMXBeans()) {
        if (!(mbean instanceof NotificationEmitter)) {
            continue;
        }
        NotificationListener notificationListener = (notification, ref) -> {
            if (!notification.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
                return;
            }

            CompositeData cd = (CompositeData) notification.getUserData();
            GarbageCollectionNotificationInfo notificationInfo = GarbageCollectionNotificationInfo.from(cd);

            String gcCause = notificationInfo.getGcCause();
            GcInfo gcInfo = notificationInfo.getGcInfo();
            long duration = gcInfo.getDuration();

            if (!JvmMemory.isConcurrentPhase(gcCause)) {
                gcPauseSum.record(duration);
            }

            Map<String, MemoryUsage> after = gcInfo.getMemoryUsageAfterGc();

            if (oldGenPoolName != null) {
                final long oldAfter = after.get(oldGenPoolName).getUsed();
                lastOldGenUsageAfterGc.set(oldAfter / maxOldGen);
            }
        };
        NotificationEmitter notificationEmitter = (NotificationEmitter) mbean;
        notificationEmitter.addNotificationListener(notificationListener, null, null);
        notificationListenerCleanUpRunnables.add(() -> {
            try {
                notificationEmitter.removeNotificationListener(notificationListener);
            } catch (ListenerNotFoundException ignore) {
            }
        });
    }
}
 
Example 12
Source File: GarbageCollectionNotificationContentTest.java    From openjdk-jdk8u 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 13
Source File: GCListener.java    From andesite-node with MIT License 5 votes vote down vote up
@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())) {
            GC_PAUSES.labels(
                    notificationInfo.getGcAction(),
                    notificationInfo.getGcCause(),
                    notificationInfo.getGcName()
            ).observe(info.getDuration() / Collector.MILLISECONDS_PER_SECOND);
        }
    }
}
 
Example 14
Source File: MemoryAllocationExports.java    From client_java with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void handleNotification(Notification notification, Object handback) {
  GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData());
  GcInfo gcInfo = info.getGcInfo();
  Map<String, MemoryUsage> memoryUsageBeforeGc = gcInfo.getMemoryUsageBeforeGc();
  Map<String, MemoryUsage> memoryUsageAfterGc = gcInfo.getMemoryUsageAfterGc();
  for (Map.Entry<String, MemoryUsage> entry : memoryUsageBeforeGc.entrySet()) {
    String memoryPool = entry.getKey();
    long before = entry.getValue().getUsed();
    long after = memoryUsageAfterGc.get(memoryPool).getUsed();
    handleMemoryPool(memoryPool, before, after);
  }
}
 
Example 15
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 16
Source File: GarbageCollectionNotificationContentTest.java    From TencentKona-8 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: 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 18
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;
        }
    }
}
 
Example 19
Source File: GarbageCollection.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private GcInfo getGcInfo(GarbageCollectionNotificationInfo info, GarbageCollectorMXBean bean) {
    if (bean instanceof com.sun.management.GarbageCollectorMXBean) {
        return ((com.sun.management.GarbageCollectorMXBean) bean).getLastGcInfo();
    }
    return info.getGcInfo();
}
 
Example 20
Source File: XTraceGCUtils.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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();
}