use of java.lang.management.GarbageCollectorMXBean in project gradle by gradle.
the class GarbageCollectionCheck method run.
@Override
public void run() {
List<GarbageCollectorMXBean> garbageCollectorMXBeans = ManagementFactory.getGarbageCollectorMXBeans();
GarbageCollectorMXBean garbageCollectorMXBean = CollectionUtils.findFirst(garbageCollectorMXBeans, new Spec<GarbageCollectorMXBean>() {
@Override
public boolean isSatisfiedBy(GarbageCollectorMXBean mbean) {
return mbean.getName().equals(garbageCollector);
}
});
List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) {
String pool = memoryPoolMXBean.getName();
if (memoryPools.contains(pool)) {
GarbageCollectionEvent event = new GarbageCollectionEvent(System.currentTimeMillis(), memoryPoolMXBean.getCollectionUsage(), garbageCollectorMXBean.getCollectionCount());
events.get(pool).slideAndInsert(event);
}
}
}
use of java.lang.management.GarbageCollectorMXBean in project jdk8u_jdk by JetBrains.
the class MXBeanInteropTest1 method doGarbageCollectorMXBeanTest.
private final int doGarbageCollectorMXBeanTest(MBeanServerConnection mbsc) {
int errorCount = 0;
System.out.println("---- GarbageCollectorMXBean");
try {
ObjectName filterName = new ObjectName(ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE + ",*");
Set<ObjectName> onSet = mbsc.queryNames(filterName, null);
for (Iterator<ObjectName> iter = onSet.iterator(); iter.hasNext(); ) {
ObjectName garbageName = iter.next();
System.out.println("-------- " + garbageName);
MBeanInfo mbInfo = mbsc.getMBeanInfo(garbageName);
errorCount += checkNonEmpty(mbInfo);
System.out.println("getMBeanInfo\t\t" + mbInfo);
GarbageCollectorMXBean garbage = null;
garbage = JMX.newMXBeanProxy(mbsc, garbageName, GarbageCollectorMXBean.class);
System.out.println("getCollectionCount\t\t" + garbage.getCollectionCount());
System.out.println("getCollectionTime\t\t" + garbage.getCollectionTime());
}
System.out.println("---- OK\n");
} catch (Exception e) {
Utils.printThrowable(e, true);
errorCount++;
System.out.println("---- ERROR\n");
}
return errorCount;
}
use of java.lang.management.GarbageCollectorMXBean in project zm-mailbox by Zimbra.
the class MemoryStats method dumpGarbageCollectors.
/**
* Output human-readable information about the garbage collectors in the system
*
* @return
*/
public static String dumpGarbageCollectors() {
StringBuilder sb = new StringBuilder();
List<GarbageCollectorMXBean> gcs = ManagementFactory.getGarbageCollectorMXBeans();
for (GarbageCollectorMXBean gc : gcs) {
long timePerGc = 0;
if (gc.getCollectionCount() > 0) {
timePerGc = gc.getCollectionTime() / gc.getCollectionCount();
}
sb.append(new Formatter().format("GC: %s(%s) count=%d time=%d(%,dms per collection)\n", gc.getName(), gc.isValid() ? "VALID" : "INVALID", gc.getCollectionCount(), gc.getCollectionTime(), timePerGc));
sb.append(new Formatter().format("\tPools: \""));
for (String s : gc.getMemoryPoolNames()) {
sb.append(s).append(", ");
}
sb.append("\"\n");
}
return sb.toString();
}
use of java.lang.management.GarbageCollectorMXBean in project karaf by apache.
the class EnvironmentDumpProvider method dumpGCInformation.
private void dumpGCInformation(final PrintWriter outPW) {
final List<GarbageCollectorMXBean> mxBeans = ManagementFactory.getGarbageCollectorMXBeans();
if (null == mxBeans || mxBeans.isEmpty()) {
return;
}
final MemoryMXBean memoryMxBean = ManagementFactory.getMemoryMXBean();
if (memoryMxBean != null) {
outPW.printf(INDENT_KEY_VALUE_FORMAT, "pending objects", formatLong(memoryMxBean.getObjectPendingFinalizationCount())).println();
}
final String gcFormat = "'%1$s' collections: %2$s\ttime: %3$s";
outPW.println();
for (final GarbageCollectorMXBean mxBean : mxBeans) {
if (null == mxBean) {
continue;
}
outPW.printf(KEY_VALUE_FORMAT, "Garbage Collectors", String.format(gcFormat, mxBean.getName(), formatLong(mxBean.getCollectionCount()), printDuration(mxBean.getCollectionTime()))).println();
}
}
use of java.lang.management.GarbageCollectorMXBean in project logging-log4j2 by apache.
the class SimplePerfTest method main.
public static void main(final String[] args) throws Exception {
System.setProperty("Log4jContextSelector", AsyncLoggerContextSelector.class.getName());
final Logger logger = LogManager.getLogger();
if (!(logger instanceof AsyncLogger)) {
throw new IllegalStateException();
}
// work around a bug in Log4j-2.5
workAroundLog4j2_5Bug();
logger.error("Starting...");
System.out.println("Starting...");
Thread.sleep(100);
final RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
final long testStartNanos = System.nanoTime();
final long[] UPTIMES = new long[1024];
final long[] DURATIONS = new long[1024];
// warmup
final long startMs = System.currentTimeMillis();
final long end = startMs + TimeUnit.SECONDS.toMillis(10);
int warmupCount = 0;
do {
runTest(logger, runtimeMXBean, UPTIMES, DURATIONS, warmupCount);
warmupCount++;
// Thread.sleep(1000);// drain buffer
} while (System.currentTimeMillis() < end);
final int COUNT = 10;
for (int i = 0; i < COUNT; i++) {
final int count = warmupCount + i;
runTest(logger, runtimeMXBean, UPTIMES, DURATIONS, count);
// Thread.sleep(1000);// drain buffer
}
final double testDurationNanos = System.nanoTime() - testStartNanos;
System.out.println("Done. Calculating stats...");
printReport("Warmup", UPTIMES, DURATIONS, 0, warmupCount);
printReport("Test", UPTIMES, DURATIONS, warmupCount, COUNT);
final StringBuilder sb = new StringBuilder(512);
sb.append("Test took: ").append(testDurationNanos / (1000.0 * 1000.0 * 1000.0)).append(" sec");
System.out.println(sb);
final List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans();
for (int i = 0; i < gcBeans.size(); i++) {
final GarbageCollectorMXBean gcBean = gcBeans.get(i);
sb.setLength(0);
sb.append("GC[").append(gcBean.getName()).append("] ");
sb.append(gcBean.getCollectionCount()).append(" collections, collection time=");
sb.append(gcBean.getCollectionTime()).append(" millis.");
System.out.println(sb);
}
}
Aggregations