/** * Create a new instance. * * @param info * The info object from the notification emitter on the * {@link java.lang.management.GarbageCollectorMXBean}. * @param startTime * Start time in milliseconds since the epoch. Note the info object has a start time relative * to the time the jvm process was started. */ public GcEvent(GarbageCollectionNotificationInfo info, long startTime) { this.name = info.getGcName(); this.info = info; this.type = HelperFunctions.getGcType(name); this.startTime = startTime; }
/** Compute the amount of data promoted during a GC event. */ static long getPromotionSize(GcInfo info) { long totalBefore = getTotalUsage(info.getMemoryUsageBeforeGc()); long totalAfter = getTotalUsage(info.getMemoryUsageAfterGc()); return totalAfter - totalBefore; } }
@Override public String toString() { final GcInfo gcInfo = info.getGcInfo(); final long totalBefore = HelperFunctions.getTotalUsage(gcInfo.getMemoryUsageBeforeGc()); final long totalAfter = HelperFunctions.getTotalUsage(gcInfo.getMemoryUsageAfterGc()); final long max = HelperFunctions.getTotalMaxUsage(gcInfo.getMemoryUsageAfterGc()); String unit = "KiB"; double cnv = ONE_KIBIBYTE; if (max > ONE_GIBIBYTE) { unit = "GiB"; cnv = ONE_GIBIBYTE; } else if (max > ONE_MEBIBYTE) { unit = "MiB"; cnv = ONE_MEBIBYTE; } String change = String.format( "%.1f%s => %.1f%s / %.1f%s", totalBefore / cnv, unit, totalAfter / cnv, unit, max / cnv, unit); String percentChange = String.format( "%.1f%% => %.1f%%", 100.0 * totalBefore / max, 100.0 * totalAfter / max); final Date d = new Date(startTime); return type.toString() + ": " + name + ", id=" + gcInfo.getId() + ", at=" + d.toString() + ", duration=" + gcInfo.getDuration() + "ms" + ", cause=[" + info.getGcCause() + "]" + ", " + change + " (" + percentChange + ")"; }
/** Create a new instance. */ public GcLogger() { jvmStartTime = ManagementFactory.getRuntimeMXBean().getStartTime(); for (GarbageCollectorMXBean mbean : ManagementFactory.getGarbageCollectorMXBeans()) { CircularBuffer<GcEvent> buffer = new CircularBuffer<>(BUFFER_SIZE); gcLogs.put(mbean.getName(), buffer); } for (MemoryPoolMXBean mbean : ManagementFactory.getMemoryPoolMXBeans()) { if (HelperFunctions.isYoungGenPool(mbean.getName())) { youngGenPoolName = mbean.getName(); } if (HelperFunctions.isOldGenPool(mbean.getName())) { oldGenPoolName = mbean.getName(); } } }
final long max = HelperFunctions.getTotalMaxUsage(gcInfo.getMemoryUsageAfterGc()); if (max > (1L << 30)) { Assertions.assertTrue(eventStr.contains("GiB"));
@Override public String toString() { final GcInfo gcInfo = info.getGcInfo(); final long totalBefore = HelperFunctions.getTotalUsage(gcInfo.getMemoryUsageBeforeGc()); final long totalAfter = HelperFunctions.getTotalUsage(gcInfo.getMemoryUsageAfterGc()); final long max = HelperFunctions.getTotalMaxUsage(gcInfo.getMemoryUsageAfterGc()); String unit = "KiB"; double cnv = ONE_KIBIBYTE; if (max > ONE_GIBIBYTE) { unit = "GiB"; cnv = ONE_GIBIBYTE; } else if (max > ONE_MEBIBYTE) { unit = "MiB"; cnv = ONE_MEBIBYTE; } String change = String.format( "%.1f%s => %.1f%s / %.1f%s", totalBefore / cnv, unit, totalAfter / cnv, unit, max / cnv, unit); String percentChange = String.format( "%.1f%% => %.1f%%", 100.0 * totalBefore / max, 100.0 * totalAfter / max); final Date d = new Date(startTime); return type.toString() + ": " + name + ", id=" + gcInfo.getId() + ", at=" + d.toString() + ", duration=" + gcInfo.getDuration() + "ms" + ", cause=[" + info.getGcCause() + "]" + ", " + change + " (" + percentChange + ")"; }
/** Create a new instance. */ public GcLogger() { jvmStartTime = ManagementFactory.getRuntimeMXBean().getStartTime(); for (GarbageCollectorMXBean mbean : ManagementFactory.getGarbageCollectorMXBeans()) { CircularBuffer<GcEvent> buffer = new CircularBuffer<>(BUFFER_SIZE); gcLogs.put(mbean.getName(), buffer); } for (MemoryPoolMXBean mbean : ManagementFactory.getMemoryPoolMXBeans()) { if (HelperFunctions.isYoungGenPool(mbean.getName())) { youngGenPoolName = mbean.getName(); } if (HelperFunctions.isOldGenPool(mbean.getName())) { oldGenPoolName = mbean.getName(); } } }
/** * Create a new instance. * * @param info * The info object from the notification emitter on the * {@link java.lang.management.GarbageCollectorMXBean}. * @param startTime * Start time in milliseconds since the epoch. Note the info object has a start time relative * to the time the jvm process was started. */ public GcEvent(GarbageCollectionNotificationInfo info, long startTime) { this.name = info.getGcName(); this.info = info; this.type = HelperFunctions.getGcType(name); this.startTime = startTime; }
/** Compute the amount of data promoted during a GC event. */ static long getPromotionSize(GcInfo info) { long totalBefore = getTotalUsage(info.getMemoryUsageBeforeGc()); long totalAfter = getTotalUsage(info.getMemoryUsageAfterGc()); return totalAfter - totalBefore; } }
private void updateMetrics(String name, GcInfo info) { final Map<String, MemoryUsage> before = info.getMemoryUsageBeforeGc(); final Map<String, MemoryUsage> after = info.getMemoryUsageAfterGc(); if (oldGenPoolName != null) { final long oldBefore = before.get(oldGenPoolName).getUsed(); final long oldAfter = after.get(oldGenPoolName).getUsed(); final long delta = oldAfter - oldBefore; if (delta > 0L) { PROMOTION_RATE.increment(delta); } // Some GCs such as G1 can reduce the old gen size as part of a minor GC. To track the // live data size we record the value if we see a reduction in the old gen heap size or // after a major GC. if (oldAfter < oldBefore || HelperFunctions.getGcType(name) == GcType.OLD) { LIVE_DATA_SIZE.set(oldAfter); final long oldMaxAfter = after.get(oldGenPoolName).getMax(); MAX_DATA_SIZE.set(oldMaxAfter); } } if (youngGenPoolName != null) { final long youngBefore = before.get(youngGenPoolName).getUsed(); final long youngAfter = after.get(youngGenPoolName).getUsed(); final long delta = youngBefore - youngGenSizeAfter; youngGenSizeAfter = youngAfter; if (delta > 0L) { ALLOCATION_RATE.increment(delta); } } }
private void updateMetrics(String name, GcInfo info) { final Map<String, MemoryUsage> before = info.getMemoryUsageBeforeGc(); final Map<String, MemoryUsage> after = info.getMemoryUsageAfterGc(); if (oldGenPoolName != null) { final long oldBefore = before.get(oldGenPoolName).getUsed(); final long oldAfter = after.get(oldGenPoolName).getUsed(); final long delta = oldAfter - oldBefore; if (delta > 0L) { PROMOTION_RATE.increment(delta); } // Some GCs such as G1 can reduce the old gen size as part of a minor GC. To track the // live data size we record the value if we see a reduction in the old gen heap size or // after a major GC. if (oldAfter < oldBefore || HelperFunctions.getGcType(name) == GcType.OLD) { LIVE_DATA_SIZE.set(oldAfter); final long oldMaxAfter = after.get(oldGenPoolName).getMax(); MAX_DATA_SIZE.set(oldMaxAfter); } } if (youngGenPoolName != null) { final long youngBefore = before.get(youngGenPoolName).getUsed(); final long youngAfter = after.get(youngGenPoolName).getUsed(); final long delta = youngBefore - youngGenSizeAfter; youngGenSizeAfter = youngAfter; if (delta > 0L) { ALLOCATION_RATE.increment(delta); } } }