import javax.management.*; import javax.management.openmbean.CompositeData; import com.sun.management.GcInfo; import com.sun.management.GarbageCollectionNotificationInfo; sclass GCPause { long start, duration; S name, cause, action; toString { ret "GCPause duration=" + duration + " ms, start=" + start + " (VM time). " + renderStructs(+name, +cause, +action); } } static new Flag collectGCPauses_started; static L collectGCPauses_list; static void collectGCPauses() { collectGCPauses(1000); } static void collectGCPauses(int bufferSize) { if (!collectGCPauses_started.raise()) ret; collectGCPauses_list = synchroList(LatestList(bufferSize)); onGCNotification(voidfunc(GarbageCollectionNotificationInfo info) { GcInfo gcInfo = info.getGcInfo(); GCPause pause = nu(GCPause, start := gcInfo.getStartTime(), duration := gcInfo.getDuration(), name := info.getGcName(), cause := info.getGcCause(), action := info.getGcAction()); collectGCPauses_list.add(pause); }); }