use of com.sun.management.GcInfo in project jdk8u_jdk by JetBrains.
the class ValidateOpenTypes method printGcInfo.
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);
}
}
use of com.sun.management.GcInfo in project jdk8u_jdk by JetBrains.
the class LastGCInfo method main.
public static void main(String[] argv) throws Exception {
boolean hasGcInfo = false;
System.gc();
List mgrs = ManagementFactory.getGarbageCollectorMXBeans();
for (ListIterator iter = mgrs.listIterator(); iter.hasNext(); ) {
Object mgr = iter.next();
if (mgr instanceof GarbageCollectorMXBean) {
GarbageCollectorMXBean gc = (GarbageCollectorMXBean) mgr;
GcInfo info = gc.getLastGcInfo();
if (info != null) {
checkGcInfo(gc.getName(), info);
hasGcInfo = true;
}
}
}
if (!hasGcInfo) {
throw new RuntimeException("No GcInfo returned");
}
System.out.println("Test passed.");
}
use of com.sun.management.GcInfo in project lavaplayer by sedmelluq.
the class GarbageCollectionMonitor method handleNotification.
@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());
}
}
}
use of com.sun.management.GcInfo in project openj9 by eclipse.
the class GarbageCollectionNotificationTest method beforeTest.
@BeforeTest
public void beforeTest() {
// get all GarbageCollectorMXBeans
List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans();
// register every GarbageCollectorMXBean
for (GarbageCollectorMXBean gcBean : gcBeans) {
gcStates.put(gcBean.getName(), new GCState(gcBean, assumeGCIsPartiallyConcurrent(gcBean), assumeGCIsOldGen(gcBean)));
NotificationEmitter emitter = (NotificationEmitter) gcBean;
// new listener
NotificationListener listener = new NotificationListener() {
// record total gc time spend
long totalGcTimeSpend = 0;
@Override
public void handleNotification(Notification notification, Object handback) {
HandBack handBack = (HandBack) handback;
// get gc info
GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData());
// output
// get a glance of gc
StringBuilder gcGlance = new StringBuilder();
String gcName = info.getGcName();
GCState gcState = gcStates.get(gcName);
GcInfo gcInfo = info.getGcInfo();
long gcId = gcInfo.getId();
gcGlance.append(info.getGcAction()).append(" (").append(gcName).append(") : - ").append(gcId);
gcGlance.append(" (").append(info.getGcCause()).append(") ");
gcGlance.append("start: ").append(dateFormat.format(new Date(JVM_START_TIME + gcInfo.getStartTime())));
gcGlance.append(", end: ").append(dateFormat.format(new Date(JVM_START_TIME + gcInfo.getEndTime())));
logger.debug(gcGlance.toString());
AssertJUnit.assertTrue("startTime(" + gcInfo.getStartTime() + ") should be smaller than endTime(" + gcInfo.getEndTime() + ").", gcInfo.getStartTime() <= gcInfo.getEndTime());
if (0 != gcState.lastCollectionID) {
AssertJUnit.assertTrue("lastCollectionID+1(" + (gcState.lastCollectionID + 1) + ") should match gcId(" + gcId + ")", gcId == (gcState.lastCollectionID + 1));
}
gcState.lastCollectionID = gcId;
gcState.totalCollectionCount += 1;
gcState.totalCollectionDuration += gcInfo.getDuration();
// memory info
Map<String, MemoryUsage> beforeUsageMap = gcInfo.getMemoryUsageBeforeGc();
Map<String, MemoryUsage> afterUsageMap = gcInfo.getMemoryUsageAfterGc();
for (Map.Entry<String, MemoryUsage> entry : afterUsageMap.entrySet()) {
String name = entry.getKey();
MemoryUsage afterUsage = entry.getValue();
MemoryUsage beforeUsage = beforeUsageMap.get(name);
StringBuilder usage = new StringBuilder();
// $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
usage.append("\t[").append(String.format("%32s", name)).append("] \t");
// $NON-NLS-1$ //$NON-NLS-2$
usage.append("init:").append(afterUsage.getInit() / ONE_KBYTE).append("K;\t");
usage.append("used:").append(// $NON-NLS-1$
handBack.handUsage(beforeUsage.getUsed(), afterUsage.getUsed(), beforeUsage.getMax())).append(// $NON-NLS-1$
";\t");
usage.append("committed: ").append(// $NON-NLS-1$
handBack.handUsage(beforeUsage.getCommitted(), afterUsage.getCommitted(), beforeUsage.getMax()));
logger.debug(usage.toString());
}
totalGcTimeSpend += gcInfo.getDuration();
// summary
long percent = (gcInfo.getEndTime() - totalGcTimeSpend) * 1000L / gcInfo.getEndTime();
StringBuilder summary = new StringBuilder();
summary.append("duration:").append(gcInfo.getDuration()).append("ms");
// $NON-NLS-1$//$NON-NLS-2$
summary.append(", throughput:").append((percent / 10)).append(".").append(percent % 10).append('%');
logger.debug(summary.toString());
logger.debug("\n");
}
};
// add the listener
emitter.addNotificationListener(listener, new NotificationFilter() {
private static final long serialVersionUID = 3763793138186359389L;
@Override
public boolean isNotificationEnabled(Notification notification) {
// filter GC notification
return notification.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION);
}
}, HandBack.getInstance());
}
}
use of com.sun.management.GcInfo in project jdk8u_jdk by JetBrains.
the class ProxyTypeMapping method checkSunGC.
private static void checkSunGC() throws Exception {
// Test com.sun.management proxy
List<GarbageCollectorMXBean> gcs = getGarbageCollectorMXBeans();
for (GarbageCollectorMXBean gc : gcs) {
com.sun.management.GarbageCollectorMXBean sunGc = newPlatformMXBeanProxy(server, GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE + ",name=" + gc.getName(), com.sun.management.GarbageCollectorMXBean.class);
GcInfo info = sunGc.getLastGcInfo();
if (info != null) {
System.out.println("GC statistic for : " + gc.getName());
printGcInfo(info);
}
}
}
Aggregations