本文整理汇总了Java中com.sun.management.GarbageCollectorMXBean.getLastGcInfo方法的典型用法代码示例。如果您正苦于以下问题:Java GarbageCollectorMXBean.getLastGcInfo方法的具体用法?Java GarbageCollectorMXBean.getLastGcInfo怎么用?Java GarbageCollectorMXBean.getLastGcInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.management.GarbageCollectorMXBean
的用法示例。
在下文中一共展示了GarbageCollectorMXBean.getLastGcInfo方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerGcMetrics
import com.sun.management.GarbageCollectorMXBean; //导入方法依赖的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());
}
示例2: processNotification
import com.sun.management.GarbageCollectorMXBean; //导入方法依赖的package包/类
public static void processNotification(MBeanServerConnection connection, Notification notification) {
echo("\n<notification>");
echo("\t<currentDatetime>" + DATE_FORMAT.format(Calendar.getInstance().getTime()) + "</currentDatetime>");
echo("\t<notificationTime timestamp='" + notification.getTimeStamp() + "'>" + DATE_FORMAT.format(new Date(notification.getTimeStamp())) + "</notificationTime>");
echo("\t<className>" + notification.getClass().getName() + "</className>");
echo("\t<source>" + notification.getSource() + "</source>");
echo("\t<type>" + notification.getType() + "</type>");
echo("\t<message>" + notification.getMessage() + "</message>");
if (notification instanceof AttributeChangeNotification) {
echo("\t<attributeChanges>");
AttributeChangeNotification acn = (AttributeChangeNotification) notification;
echo("\t\t<attributeName>" + acn.getAttributeName() + "</attributeName>");
echo("\t\t<attributeType>" + acn.getAttributeType() + "</attributeType>");
echo("\t\t<newValue>" + acn.getNewValue() + "</newValue>");
echo("\t\t<oldValue>" + acn.getOldValue() + "</oldValue>");
echo("\t</attributeChanges>");
}
if (notification.getSource() instanceof ObjectName) {
GarbageCollectorMXBean gcBean = JMX.newMXBeanProxy(connection, (ObjectName) notification.getSource(), GarbageCollectorMXBean.class);
echo("\t<gcInfo>");
echo("\t\t<collectionTime>" + gcBean.getCollectionTime() + "</collectionTime>");
echo("\t\t<collectionCount>" + gcBean.getCollectionCount() + "</collectionCount>");
GcInfo gcInfo = gcBean.getLastGcInfo();
echo("\t\t<startTime>" + gcInfo.getStartTime() + "</startTime>");
echo("\t\t<endTime>" + gcInfo.getEndTime() + "</endTime>");
echo("\t\t<duration>" + gcInfo.getDuration() + "</duration>");
outputMemoryUsages(gcInfo.getMemoryUsageBeforeGc(), "memoryUsageBeforeGC");
outputMemoryUsages(gcInfo.getMemoryUsageAfterGc(), "memoryUsageAfterGC");
echo("\t</gcInfo>");
}
echo("\n</notification>");
}
开发者ID:breakEval13,项目名称:rocketmq-flink-plugin,代码行数:35,代码来源:JMXGarbageCollectorNotificationClient.java
示例3: getStat
import com.sun.management.GarbageCollectorMXBean; //导入方法依赖的package包/类
public MemoryPoolStat getStat() throws java.io.IOException {
long usageThreshold = (pool.isUsageThresholdSupported()
? pool.getUsageThreshold()
: -1);
long collectThreshold = (pool.isCollectionUsageThresholdSupported()
? pool.getCollectionUsageThreshold()
: -1);
long lastGcStartTime = 0;
long lastGcEndTime = 0;
MemoryUsage beforeGcUsage = null;
MemoryUsage afterGcUsage = null;
long gcId = 0;
if (lastGcInfo != null) {
gcId = lastGcInfo.getId();
lastGcStartTime = lastGcInfo.getStartTime();
lastGcEndTime = lastGcInfo.getEndTime();
beforeGcUsage = lastGcInfo.getMemoryUsageBeforeGc().get(poolName);
afterGcUsage = lastGcInfo.getMemoryUsageAfterGc().get(poolName);
}
Set<Map.Entry<ObjectName,Long>> set = gcMBeans.entrySet();
for (Map.Entry<ObjectName,Long> e : set) {
GarbageCollectorMXBean gc =
client.getMXBean(e.getKey(),
com.sun.management.GarbageCollectorMXBean.class);
Long gcCount = e.getValue();
Long newCount = gc.getCollectionCount();
if (newCount > gcCount) {
gcMBeans.put(e.getKey(), new Long(newCount));
lastGcInfo = gc.getLastGcInfo();
if (lastGcInfo.getEndTime() > lastGcEndTime) {
gcId = lastGcInfo.getId();
lastGcStartTime = lastGcInfo.getStartTime();
lastGcEndTime = lastGcInfo.getEndTime();
beforeGcUsage = lastGcInfo.getMemoryUsageBeforeGc().get(poolName);
afterGcUsage = lastGcInfo.getMemoryUsageAfterGc().get(poolName);
assert(beforeGcUsage != null);
assert(afterGcUsage != null);
}
}
}
MemoryUsage usage = pool.getUsage();
return new MemoryPoolStat(poolName,
usageThreshold,
usage,
gcId,
lastGcStartTime,
lastGcEndTime,
collectThreshold,
beforeGcUsage,
afterGcUsage);
}
示例4: getStat
import com.sun.management.GarbageCollectorMXBean; //导入方法依赖的package包/类
public MemoryPoolStat getStat() throws java.io.IOException {
long usageThreshold = (pool.isUsageThresholdSupported()
? pool.getUsageThreshold()
: -1);
long collectThreshold = (pool.isCollectionUsageThresholdSupported()
? pool.getCollectionUsageThreshold()
: -1);
long lastGcStartTime = 0;
long lastGcEndTime = 0;
MemoryUsage beforeGcUsage = null;
MemoryUsage afterGcUsage = null;
long gcId = 0;
if (lastGcInfo != null) {
gcId = lastGcInfo.getId();
lastGcStartTime = lastGcInfo.getStartTime();
lastGcEndTime = lastGcInfo.getEndTime();
beforeGcUsage = lastGcInfo.getMemoryUsageBeforeGc().get(poolName);
afterGcUsage = lastGcInfo.getMemoryUsageAfterGc().get(poolName);
}
Set<Map.Entry<ObjectName,Long>> set = gcMBeans.entrySet();
for (Map.Entry<ObjectName,Long> e : set) {
GarbageCollectorMXBean gc =
client.getMXBean(e.getKey(),
com.sun.management.GarbageCollectorMXBean.class);
Long gcCount = e.getValue();
Long newCount = gc.getCollectionCount();
if (newCount > gcCount) {
gcMBeans.put(e.getKey(), newCount);
lastGcInfo = gc.getLastGcInfo();
if (lastGcInfo.getEndTime() > lastGcEndTime) {
gcId = lastGcInfo.getId();
lastGcStartTime = lastGcInfo.getStartTime();
lastGcEndTime = lastGcInfo.getEndTime();
beforeGcUsage = lastGcInfo.getMemoryUsageBeforeGc().get(poolName);
afterGcUsage = lastGcInfo.getMemoryUsageAfterGc().get(poolName);
assert(beforeGcUsage != null);
assert(afterGcUsage != null);
}
}
}
MemoryUsage usage = pool.getUsage();
return new MemoryPoolStat(poolName,
usageThreshold,
usage,
gcId,
lastGcStartTime,
lastGcEndTime,
collectThreshold,
beforeGcUsage,
afterGcUsage);
}
示例5: getStat
import com.sun.management.GarbageCollectorMXBean; //导入方法依赖的package包/类
public MemoryPoolStat getStat() throws java.io.IOException {
long usageThreshold = (pool.isUsageThresholdSupported()
? pool.getUsageThreshold()
: -1);
long collectThreshold = (pool.isCollectionUsageThresholdSupported()
? pool.getCollectionUsageThreshold()
: -1);
long lastGcStartTime = 0;
long lastGcEndTime = 0;
MemoryUsage beforeGcUsage = null;
MemoryUsage afterGcUsage = null;
long gcId = 0;
if (lastGcInfo != null) {
gcId = lastGcInfo.getId();
lastGcStartTime = lastGcInfo.getStartTime();
lastGcEndTime = lastGcInfo.getEndTime();
beforeGcUsage = lastGcInfo.getMemoryUsageBeforeGc().get(poolName);
afterGcUsage = lastGcInfo.getMemoryUsageAfterGc().get(poolName);
}
Set<Map.Entry<ObjectName,Long>> set = gcMBeans.entrySet();
for (Map.Entry<ObjectName,Long> e : set) {
GarbageCollectorMXBean gc =
client.getMXBean(e.getKey(),
com.sun.management.GarbageCollectorMXBean.class);
Long gcCount = e.getValue();
Long newCount = gc.getCollectionCount();
if (newCount > gcCount) {
gcMBeans.put(e.getKey(), new Long(newCount));
lastGcInfo = gc.getLastGcInfo();
if (lastGcInfo.getEndTime() > lastGcEndTime) {
gcId = lastGcInfo.getId();
lastGcStartTime = lastGcInfo.getStartTime();
lastGcEndTime = lastGcInfo.getEndTime();
beforeGcUsage = lastGcInfo.getMemoryUsageBeforeGc().get(poolName);
afterGcUsage = lastGcInfo.getMemoryUsageAfterGc().get(poolName);
assert(beforeGcUsage != null);
assert(afterGcUsage != null);
}
}
}
MemoryUsage usage = pool.getUsage();
return new MemoryPoolStat(poolName,
usageThreshold,
usage,
gcId,
lastGcStartTime,
lastGcEndTime,
collectThreshold,
beforeGcUsage,
afterGcUsage);
}