Java Code Examples for com.sun.management.GcInfo#getEndTime()
The following examples show how to use
com.sun.management.GcInfo#getEndTime() .
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: LogGCNotifications.java From garmadon with Apache License 2.0 | 5 votes |
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 2
Source File: ProtobufGCNotifications.java From garmadon with Apache License 2.0 | 4 votes |
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 3
Source File: RingBufferGarbageCollectionLog.java From nifi with Apache License 2.0 | 4 votes |
@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; } } }