本文整理汇总了Java中com.sun.management.GcInfo类的典型用法代码示例。如果您正苦于以下问题:Java GcInfo类的具体用法?Java GcInfo怎么用?Java GcInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GcInfo类属于com.sun.management包,在下文中一共展示了GcInfo类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createGCNotification
import com.sun.management.GcInfo; //导入依赖的package包/类
void createGCNotification(long timestamp,
String gcName,
String gcAction,
String gcCause,
GcInfo gcInfo) {
if (!hasListeners()) {
return;
}
Notification notif = new Notification(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION,
getObjectName(),
getNextSeqNumber(),
timestamp,
gcName);
GarbageCollectionNotificationInfo info =
new GarbageCollectionNotificationInfo(gcName,
gcAction,
gcCause,
gcInfo);
CompositeData cd =
GarbageCollectionNotifInfoCompositeData.toCompositeData(info);
notif.setUserData(cd);
sendNotification(notif);
}
示例2: printGcInfo
import com.sun.management.GcInfo; //导入依赖的package包/类
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);
}
}
示例3: printGcInfo
import com.sun.management.GcInfo; //导入依赖的package包/类
private static void printGcInfo(GcInfo info) throws Exception {
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);
}
}
示例4: createGCNotification
import com.sun.management.GcInfo; //导入依赖的package包/类
protected void createGCNotification(long timestamp,
String gcName,
String gcAction,
String gcCause,
GcInfo gcInfo) {
if (!hasListeners()) {
return;
}
Notification notif = new Notification(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION,
getObjectName(),
getNextSeqNumber(),
timestamp,
gcName);
GarbageCollectionNotificationInfo info =
new GarbageCollectionNotificationInfo(gcName,
gcAction,
gcCause,
gcInfo);
CompositeData cd =
GarbageCollectionNotifInfoCompositeData.toCompositeData(info);
notif.setUserData(cd);
sendNotification(notif);
}
示例5: handleNotification
import com.sun.management.GcInfo; //导入依赖的package包/类
@Override
public void handleNotification(Notification notification, Object handback) {
if (notification.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
System.out.println("0XDEADBEAF");
GarbageCollectionNotificationInfo notifInfo = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData());
GcInfo gcInfo = notifInfo.getGcInfo();
System.out.printf("Action: %s, %s, %s\n", notifInfo.getGcAction(), notifInfo.getGcCause(), notifInfo.getGcName());
System.out.printf("Time: %d, %d, %d\n", gcInfo.getStartTime(), gcInfo.getEndTime(), gcInfo.getDuration());
System.out.printf("Memory: %s, %s\n", gcInfo.getMemoryUsageBeforeGc().toString(), gcInfo.getMemoryUsageAfterGc().toString());
Map<String, MemoryUsage> memBefore = notifInfo.getGcInfo().getMemoryUsageBeforeGc();
Map<String, MemoryUsage> memAfter = notifInfo.getGcInfo().getMemoryUsageAfterGc();
StringBuilder sb = new StringBuilder();
sb.append("[").append(notifInfo.getGcAction()).append(" / ").append(notifInfo.getGcCause())
.append(" / ").append(notifInfo.getGcName()).append(" / (");
appendMemUsage(sb, memBefore);
sb.append(") -> (");
appendMemUsage(sb, memAfter);
sb.append("), ").append(notifInfo.getGcInfo().getDuration()).append(" ms]");
System.out.println(sb.toString());
}
}
示例6: handleNotification
import com.sun.management.GcInfo; //导入依赖的package包/类
@Override
public void handleNotification(Notification notification, Object handback) {
try {
// Make sure it's the right notification type
if (!notification.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION))
return;
// Extract the GcInfo as appropriate, working around the OpenJDK
// GcInfo cycles/milliseconds bug
GarbageCollectorMXBean bean = (GarbageCollectorMXBean) handback;
GarbageCollectionNotificationInfo info = getInfo(notification);
GcInfo gc = getGcInfo(info, bean);
// Call the callback
this.callback.onGC(gc);
} catch (Exception e) {
// swallow
}
}
示例7: registerGcMetrics
import com.sun.management.GcInfo; //导入依赖的package包/类
private static void registerGcMetrics(Map<String, Metric> metrics, long jvmStartTime, GarbageCollectorMXBean gcMxBean) {
String gcName = gcMxBean.getName(), gcMetricNamePrefix = buildMetricName(GC_METRIC_NAME_PART, normalizeMetricDisplayName(gcName)),
gcCollMetricNamePrefix = buildMetricName(gcMetricNamePrefix, COLLECTION_METRIC_NAME_PART);
registerGauge(metrics, buildMetricName(gcMetricNamePrefix, NAME_METRIC_NAME_PART), gcName);
registerGauge(metrics, buildMetricName(gcCollMetricNamePrefix, COUNT_METRIC_NAME_PART), gcMxBean.getCollectionCount());
registerGauge(metrics, buildMetricName(gcCollMetricNamePrefix, TIME_METRIC_NAME_PART), gcMxBean.getCollectionTime());
GcInfo gcInfo = gcMxBean.getLastGcInfo();
if (gcInfo == null) {
return;
}
String gcCollLastMetricNamePrefix = buildMetricName(gcCollMetricNamePrefix, LAST_METRIC_NAME_PART);
registerGauge(metrics, buildMetricName(gcCollLastMetricNamePrefix, ID_METRIC_NAME_PART), gcInfo.getId());
registerGauge(metrics, buildMetricName(gcCollLastMetricNamePrefix, TIME_START_METRIC_NAME_PREFIX), new Date((jvmStartTime + gcInfo.getStartTime())));
registerGauge(metrics, buildMetricName(gcCollLastMetricNamePrefix, TIME_END_METRIC_NAME_PREFIX), new Date((jvmStartTime + gcInfo.getEndTime())));
registerGauge(metrics, buildMetricName(gcCollLastMetricNamePrefix, DURATION_METRIC_NAME_PART), gcInfo.getDuration());
registerGcMemoryUsageMetrics(metrics, buildMetricName(gcCollLastMetricNamePrefix, BEFORE_MEMORY_METRIC_NAME_PREFIX), gcInfo.getMemoryUsageBeforeGc());
registerGcMemoryUsageMetrics(metrics, buildMetricName(gcCollLastMetricNamePrefix, AFTER_MEMORY_METRIC_NAME_PREFIX), gcInfo.getMemoryUsageAfterGc());
}