Search in sources :

Example 21 with GarbageCollectorMXBean

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);
        }
    }
}
Also used : GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean)

Example 22 with GarbageCollectorMXBean

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;
}
Also used : MBeanInfo(javax.management.MBeanInfo) GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) ObjectName(javax.management.ObjectName)

Example 23 with GarbageCollectorMXBean

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();
}
Also used : Formatter(java.util.Formatter) GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean)

Example 24 with GarbageCollectorMXBean

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();
    }
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean) GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean)

Example 25 with GarbageCollectorMXBean

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);
    }
}
Also used : AsyncLogger(org.apache.logging.log4j.core.async.AsyncLogger) GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) RuntimeMXBean(java.lang.management.RuntimeMXBean) AsyncLoggerContextSelector(org.apache.logging.log4j.core.async.AsyncLoggerContextSelector) Logger(org.apache.logging.log4j.Logger) AsyncLogger(org.apache.logging.log4j.core.async.AsyncLogger)

Aggregations

GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)53 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)9 RuntimeMXBean (java.lang.management.RuntimeMXBean)9 MemoryMXBean (java.lang.management.MemoryMXBean)7 HashMap (java.util.HashMap)7 MemoryUsage (java.lang.management.MemoryUsage)6 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)6 ArrayList (java.util.ArrayList)6 Map (java.util.Map)5 ThreadMXBean (java.lang.management.ThreadMXBean)4 ClassLoadingMXBean (java.lang.management.ClassLoadingMXBean)3 Date (java.util.Date)2 LinkedHashMap (java.util.LinkedHashMap)2 NotificationEmitter (javax.management.NotificationEmitter)2 ObjectName (javax.management.ObjectName)2 MetricGroup (org.apache.flink.metrics.MetricGroup)2 Metric (com.codahale.metrics.Metric)1 Checkpoint (com.datatorrent.stram.api.Checkpoint)1 ContainerStatsEvent (com.datatorrent.stram.api.ContainerEvent.ContainerStatsEvent)1 ContainerHeartbeat (com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol.ContainerHeartbeat)1