Search in sources :

Example 61 with MemoryPoolMXBean

use of java.lang.management.MemoryPoolMXBean in project head by mifos.

the class ApplicationInitializer method printMemoryPool.

private void printMemoryPool() {
    logger.info("Memory MXBean");
    logger.info("Heap Memory Usage: " + ManagementFactory.getMemoryMXBean().getHeapMemoryUsage());
    logger.info("Non-Heap Memory Usage: " + ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage());
    logger.info("-----Memory Pool MXBeans------");
    Iterator<MemoryPoolMXBean> iter = ManagementFactory.getMemoryPoolMXBeans().iterator();
    while (iter.hasNext()) {
        MemoryPoolMXBean item = iter.next();
        logger.info("Name: " + item.getName());
        logger.info("Type: " + item.getType());
        logger.info("Usage: " + item.getUsage());
        logger.info("Peak Usage: " + item.getPeakUsage());
        logger.info("Collection Usage: " + item.getCollectionUsage());
        logger.info("+++++++++++++++++++");
    }
}
Also used : MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean)

Example 62 with MemoryPoolMXBean

use of java.lang.management.MemoryPoolMXBean in project geode by apache.

the class VMStats50 method refreshMemoryPools.

private void refreshMemoryPools() {
    boolean reInitPools = false;
    Iterator<Map.Entry<MemoryPoolMXBean, Statistics>> it = mpMap.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<MemoryPoolMXBean, Statistics> me = it.next();
        MemoryPoolMXBean mp = me.getKey();
        Statistics s = me.getValue();
        if (!mp.isValid()) {
            s.close();
            it.remove();
            reInitPools = true;
        } else {
            MemoryUsage mu = null;
            try {
                mu = mp.getUsage();
            } catch (IllegalArgumentException ex) {
                // to workaround JRockit bug 36348 just ignore this and try the next pool
                continue;
            } catch (InternalError ie) {
                // Somebody saw an InternalError once but I have no idea how to reproduce it. Was this a
                // race between
                // mp.isValid() and mp.getUsage()? Perhaps.
                s.close();
                it.remove();
                reInitPools = true;
                logger.warn("Accessing MemoryPool '{}' threw an Internal Error: {}", mp.getName(), ie.getMessage());
                continue;
            }
            s.setLong(mp_l_initMemoryId, mu.getInit());
            s.setLong(mp_l_usedMemoryId, mu.getUsed());
            s.setLong(mp_l_committedMemoryId, mu.getCommitted());
            s.setLong(mp_l_maxMemoryId, mu.getMax());
            if (mp.isUsageThresholdSupported()) {
                s.setLong(mp_usageThresholdId, mp.getUsageThreshold());
                s.setLong(mp_usageExceededId, mp.getUsageThresholdCount());
            }
            mu = null;
            if (!this.isCollectionUsageUnsupported(mp)) {
                try {
                    mu = mp.getCollectionUsage();
                } catch (UnsupportedOperationException ex) {
                    // JRockit throws this exception instead of returning null
                    // as the javadocs say it should. See bug 36348
                    this.setCollectionUsageUnsupported(mp);
                } catch (IllegalArgumentException ex) {
                    // Yet another JRockit bug in which its code catches an assertion
                    // about the state of their bean stat values being inconsistent.
                    // See bug 36348.
                    this.setCollectionUsageUnsupported(mp);
                }
            }
            if (mu != null) {
                // s.setLong(mp_gc_initMemoryId, mu.getInit());
                s.setLong(mp_gc_usedMemoryId, mu.getUsed());
                // s.setLong(mp_gc_maxMemoryId, mu.getMax());
                if (mp.isCollectionUsageThresholdSupported()) {
                    s.setLong(mp_collectionUsageThresholdId, mp.getCollectionUsageThreshold());
                    s.setLong(mp_collectionUsageExceededId, mp.getCollectionUsageThresholdCount());
                }
            }
        }
    }
    if (reInitPools) {
        initMemoryPools();
    }
}
Also used : MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) HashMap(java.util.HashMap) Map(java.util.Map) Statistics(org.apache.geode.Statistics) MemoryUsage(java.lang.management.MemoryUsage)

Example 63 with MemoryPoolMXBean

use of java.lang.management.MemoryPoolMXBean in project geode by apache.

the class MXMemoryPoolListenerExample method main.

public static void main(String[] args) {
    final MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
    final double threshold;
    {
        double t = 0.8;
        if (args.length > 0) {
            try {
                t = Integer.parseInt(args[0]) / 100;
            } catch (NumberFormatException useDefault) {
            }
        }
        if (t < 0.0 || t > 1.0) {
            throw new IllegalArgumentException("Theshold must be >= 0 and <= 100");
        }
        threshold = t;
    }
    final int percentTenured;
    {
        int p = 100;
        if (args.length > 1) {
            try {
                p = Integer.parseInt(args[1]);
            } catch (NumberFormatException useDefault) {
            }
        }
        if (p > 100 || p < 0) {
            throw new IllegalArgumentException("Percent Tenured must be >= 0 and <= 100");
        }
        percentTenured = p;
    }
    Properties dsProps = new Properties();
    // Loner
    dsProps.setProperty(MCAST_PORT, "0");
    dsProps.setProperty(ConfigurationProperties.LOG_LEVEL, "info");
    dsProps.setProperty(ConfigurationProperties.STATISTIC_SAMPLE_RATE, "200");
    dsProps.setProperty(ConfigurationProperties.ENABLE_TIME_STATISTICS, "true");
    dsProps.setProperty(ConfigurationProperties.STATISTIC_SAMPLING_ENABLED, "true");
    DistributedSystem ds = DistributedSystem.connect(dsProps);
    final LogWriter logger = ds.getLogWriter();
    logger.info("Usage threshold: " + threshold + "; percent tenured: " + percentTenured + "; Runtime Maximum memory: " + (Runtime.getRuntime().maxMemory() / (1024 * 1024)) + "Mb" + "; Heap Maximum memory: " + (mbean.getHeapMemoryUsage().getMax() / (1024 * 1024)) + "Mb");
    MXMemoryPoolListenerExample me = new MXMemoryPoolListenerExample(ds);
    // Register this listener to NotificationEmitter
    NotificationEmitter emitter = (NotificationEmitter) mbean;
    emitter.addNotificationListener(me, null, null);
    List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
    for (MemoryPoolMXBean p : pools) {
        if (p.isCollectionUsageThresholdSupported()) {
            // p.setCollectionUsageThreshold(0);
            logger.info("Pool which supports collection usage threshold: " + p.getName() + "; " + p.getCollectionUsage());
        }
        // On JRockit do not set the usage threshold on the Nursery pool
        if (p.getType().equals(MemoryType.HEAP) && p.isUsageThresholdSupported() && !p.getName().startsWith("Nursery")) {
            int byteThreshold = (int) Math.ceil(threshold * p.getUsage().getMax());
            logger.info("Setting threshold " + (byteThreshold / (1024 * 1024)) + "Mb on: " + p.getName() + "; " + p.getCollectionUsage());
            p.setUsageThreshold(byteThreshold);
        }
    }
    final Cache c = CacheFactory.create(ds);
    new MemoryHog("hog_1", c, me.critical).consumeMemory(percentTenured).printTenuredSize();
    ds.disconnect();
}
Also used : ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) MemoryMXBean(java.lang.management.MemoryMXBean) NotificationEmitter(javax.management.NotificationEmitter) LogWriter(org.apache.geode.LogWriter) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean)

Example 64 with MemoryPoolMXBean

use of java.lang.management.MemoryPoolMXBean in project jackrabbit-oak by apache.

the class GCMemoryBarrier method getMemoryPool.

private static MemoryPoolMXBean getMemoryPool() {
    long maxSize = 0;
    MemoryPoolMXBean maxPool = null;
    for (MemoryPoolMXBean pool : getMemoryPoolMXBeans()) {
        if (HEAP == pool.getType() && pool.isCollectionUsageThresholdSupported()) {
            // Get usage after a GC, which is more stable, if available
            long poolSize = pool.getCollectionUsage().getMax();
            // Keep the pool with biggest size, by default it should be Old Gen Space
            if (poolSize > maxSize) {
                maxPool = pool;
            }
        }
    }
    return maxPool;
}
Also used : MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean)

Example 65 with MemoryPoolMXBean

use of java.lang.management.MemoryPoolMXBean in project jdk8u_jdk by JetBrains.

the class GarbageCollectorImpl method getAllPoolNames.

synchronized String[] getAllPoolNames() {
    if (poolNames == null) {
        List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
        poolNames = new String[pools.size()];
        int i = 0;
        for (MemoryPoolMXBean m : pools) {
            poolNames[i++] = m.getName();
        }
    }
    return poolNames;
}
Also used : MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean)

Aggregations

MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)112 MemoryUsage (java.lang.management.MemoryUsage)46 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)16 ArrayList (java.util.ArrayList)15 MemoryMXBean (java.lang.management.MemoryMXBean)12 Test (org.testng.annotations.Test)11 InstanceNotFoundException (javax.management.InstanceNotFoundException)9 ReflectionException (javax.management.ReflectionException)9 NotificationEmitter (javax.management.NotificationEmitter)8 MemoryType (java.lang.management.MemoryType)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 AttributeNotFoundException (javax.management.AttributeNotFoundException)7 IntrospectionException (javax.management.IntrospectionException)7 MBeanException (javax.management.MBeanException)7 VisibleForTesting (com.google.common.annotations.VisibleForTesting)6 Attribute (javax.management.Attribute)6 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)6 BufferPoolMXBean (java.lang.management.BufferPoolMXBean)5 ThreadMXBean (java.lang.management.ThreadMXBean)5