本文整理汇总了Java中com.sun.management.GarbageCollectorMXBean类的典型用法代码示例。如果您正苦于以下问题:Java GarbageCollectorMXBean类的具体用法?Java GarbageCollectorMXBean怎么用?Java GarbageCollectorMXBean使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GarbageCollectorMXBean类属于com.sun.management包,在下文中一共展示了GarbageCollectorMXBean类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateStampsAndStoreDifference
import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
public void updateStampsAndStoreDifference( /*out*/ final SingleIterationResult iterationResult ) {
long totalGcCollectionCount = 0;
long totalGcCollectionTime = 0;
for( final GarbageCollectorMXBean gcBean : gcMXBeans ) {
totalGcCollectionCount += gcBean.getCollectionCount();
totalGcCollectionTime += gcBean.getCollectionTime();
}
final long bytesAllocatedByThread = threadMXBean.getThreadAllocatedBytes( benchmarkThreadId );
iterationResult.fill(
totalGcCollectionTime - gcCollectionTime,
totalGcCollectionCount - gcCollectionCount,
bytesAllocatedByThread - memoryAllocatedByThreadBytes
);
this.gcCollectionCount = totalGcCollectionCount;
this.gcCollectionTime = totalGcCollectionTime;
this.memoryAllocatedByThreadBytes = bytesAllocatedByThread;
}
示例2: 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());
}
示例3: 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
示例4: main
import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException {
System.out.println(">>>>> Memory");
MemoryMXBean memoryMBean = ManagementFactory.getMemoryMXBean();
System.out.println("Heap memory usage: " + memoryMBean.getHeapMemoryUsage());
System.out.println("Non-Heap memory usage: " + memoryMBean.getNonHeapMemoryUsage());
System.out.println("Objects pending finalization: " + memoryMBean.getObjectPendingFinalizationCount());
System.out.println(">>>>> GC");
ManagementFactory.getGarbageCollectorMXBeans().stream().forEach(bean -> {
GarbageCollectorMXBean gcBean = (GarbageCollectorMXBean) bean;
((NotificationEmitter) gcBean).addNotificationListener(new GCLogger(), null, null);
System.out.println(">> " + gcBean.getName());
System.out.println("Collection count: " + gcBean.getCollectionCount());
System.out.println("Collection time: " + gcBean.getCollectionTime());
System.out.println("Last GC: " + gcBean.getLastGcInfo());
});
System.out.println(">>>>> Memory pool mbeans");
ManagementFactory.getMemoryPoolMXBeans().stream().forEach(bean -> {
System.out.println(">> " + bean.getName() + " " + bean.getType());
System.out.println("Collection usage: " + bean.getCollectionUsage());
System.out.println("Peak usage: " + bean.getPeakUsage());
System.out.println("Usage: " + bean.getUsage());
System.out.println("Memory manager names: " + Arrays.toString(bean.getMemoryManagerNames()));
});
while (true) {
System.out.println("Allocating 1Mb");
byte[] allocation = new byte[1024 * 1024];
Thread.sleep(100);
}
}
示例5: AllocationMonitor
import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
public AllocationMonitor( final Thread benchmarkThread ) {
//noinspection SuspiciousToArrayCall
gcMXBeans = ManagementFactory.getGarbageCollectorMXBeans().toArray( new GarbageCollectorMXBean[0] );
threadMXBean = ( ThreadMXBean ) ManagementFactory.getThreadMXBean();
this.benchmarkThreadId = benchmarkThread.getId();
}
示例6: storeCurrentStamps
import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
public void storeCurrentStamps() {
long collectionCounts = 0;
long collectionTimes = 0;
for( final GarbageCollectorMXBean gcBean : gcMXBeans ) {
collectionCounts += gcBean.getCollectionCount();
collectionTimes += gcBean.getCollectionTime();
}
this.gcCollectionCount = collectionCounts;
this.gcCollectionTime = collectionTimes;
this.memoryAllocatedByThreadBytes = threadMXBean.getThreadAllocatedBytes( benchmarkThreadId );
}
示例7: TestWriteSpeed2
import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
public TestWriteSpeed2(int count, int repeat, int phases) {
this.count = count;
this.repeat = repeat;
this.phases = phases;
osManagement = (OperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean();
for (Object bean : ManagementFactory.getGarbageCollectorMXBeans())
gcManagement.add((GarbageCollectorMXBean)bean);
}
示例8: getMetrics
import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
@Override
public Map<String, Metric> getMetrics() {
Map<String, Metric> metrics = super.getMetrics();
long jvmStartTime = ManagementFactory.getRuntimeMXBean().getStartTime();
ManagementFactory.getGarbageCollectorMXBeans().forEach(gcMxBean -> registerGcMetrics(metrics, jvmStartTime, ((GarbageCollectorMXBean) gcMxBean)));
return metrics;
}
示例9: getGarbageCollectorMXBean
import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
@Override
public GarbageCollectorMXBean getGarbageCollectorMXBean() {
return new SemiSpaceGarbageCollectorMXBean();
}
示例10: getGarbageCollectorMXBean
import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
@Override
public GarbageCollectorMXBean getGarbageCollectorMXBean() {
return new GenSSGarbageCollectorMXBean();
}
示例11: setNotificationEnabled
import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
native void setNotificationEnabled(GarbageCollectorMXBean gc,
boolean enabled);
示例12: 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);
}
示例13: setNotificationEnabled
import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
private native void setNotificationEnabled(GarbageCollectorMXBean gc,
boolean enabled);
示例14: createGarbageCollector
import com.sun.management.GarbageCollectorMXBean; //导入依赖的package包/类
private static java.lang.management.GarbageCollectorMXBean
createGarbageCollector(String name, String type) {
return new GarbageCollectorExtImpl(name);
}
示例15: 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);
}