Search in sources :

Example 1 with MemoryUsage

use of java.lang.management.MemoryUsage in project flink by apache.

the class MemoryLogger method getMemoryPoolStatsAsString.

/**
	 * Gets the memory pool statistics from the JVM.
	 *
	 * @param poolBeans The collection of memory pool beans.
	 * @return A string denoting the names and sizes of the memory pools.
	 */
public static String getMemoryPoolStatsAsString(List<MemoryPoolMXBean> poolBeans) {
    StringBuilder bld = new StringBuilder("Off-heap pool stats: ");
    int count = 0;
    for (MemoryPoolMXBean bean : poolBeans) {
        if (bean.getType() == MemoryType.NON_HEAP) {
            if (count > 0) {
                bld.append(", ");
            }
            count++;
            MemoryUsage usage = bean.getUsage();
            long used = usage.getUsed() >> 20;
            long committed = usage.getCommitted() >> 20;
            long max = usage.getMax() >> 20;
            bld.append('[').append(bean.getName()).append(": ");
            bld.append(used).append('/').append(committed).append('/').append(max);
            bld.append(" MB (used/committed/max)]");
        }
    }
    return bld.toString();
}
Also used : MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) MemoryUsage(java.lang.management.MemoryUsage)

Example 2 with MemoryUsage

use of java.lang.management.MemoryUsage in project flink by apache.

the class MemoryLogger method getMemoryUsageStatsAsString.

// ------------------------------------------------------------------------
/**
	 * Gets the memory footprint of the JVM in a string representation.
	 *
	 * @return A string describing how much heap memory and direct memory are allocated and used.
	 */
public static String getMemoryUsageStatsAsString(MemoryMXBean memoryMXBean) {
    MemoryUsage heap = memoryMXBean.getHeapMemoryUsage();
    MemoryUsage nonHeap = memoryMXBean.getNonHeapMemoryUsage();
    long heapUsed = heap.getUsed() >> 20;
    long heapCommitted = heap.getCommitted() >> 20;
    long heapMax = heap.getMax() >> 20;
    long nonHeapUsed = nonHeap.getUsed() >> 20;
    long nonHeapCommitted = nonHeap.getCommitted() >> 20;
    long nonHeapMax = nonHeap.getMax() >> 20;
    return String.format("Memory usage stats: [HEAP: %d/%d/%d MB, " + "NON HEAP: %d/%d/%d MB (used/committed/max)]", heapUsed, heapCommitted, heapMax, nonHeapUsed, nonHeapCommitted, nonHeapMax);
}
Also used : MemoryUsage(java.lang.management.MemoryUsage)

Example 3 with MemoryUsage

use of java.lang.management.MemoryUsage in project hadoop by apache.

the class JvmMetrics method getMemoryUsage.

private void getMemoryUsage(MetricsRecordBuilder rb) {
    MemoryUsage memNonHeap = memoryMXBean.getNonHeapMemoryUsage();
    MemoryUsage memHeap = memoryMXBean.getHeapMemoryUsage();
    Runtime runtime = Runtime.getRuntime();
    rb.addGauge(MemNonHeapUsedM, memNonHeap.getUsed() / M).addGauge(MemNonHeapCommittedM, memNonHeap.getCommitted() / M).addGauge(MemNonHeapMaxM, calculateMaxMemoryUsage(memNonHeap)).addGauge(MemHeapUsedM, memHeap.getUsed() / M).addGauge(MemHeapCommittedM, memHeap.getCommitted() / M).addGauge(MemHeapMaxM, calculateMaxMemoryUsage(memHeap)).addGauge(MemMaxM, runtime.maxMemory() / M);
}
Also used : MemoryUsage(java.lang.management.MemoryUsage)

Example 4 with MemoryUsage

use of java.lang.management.MemoryUsage in project hbase by apache.

the class MemorySizeUtil method getOnheapGlobalMemstoreSize.

/**
   * Returns the onheap global memstore limit based on the config
   * 'hbase.regionserver.global.memstore.size'.
   * @param conf
   * @return the onheap global memstore limt
   */
public static long getOnheapGlobalMemstoreSize(Configuration conf) {
    long max = -1L;
    final MemoryUsage usage = safeGetHeapMemoryUsage();
    if (usage != null) {
        max = usage.getMax();
    }
    float globalMemStorePercent = getGlobalMemStoreHeapPercent(conf, true);
    return ((long) (max * globalMemStorePercent));
}
Also used : MemoryUsage(java.lang.management.MemoryUsage)

Example 5 with MemoryUsage

use of java.lang.management.MemoryUsage in project hbase by apache.

the class MemorySizeUtil method getL2BlockCacheHeapPercent.

/**
   * @param conf
   * @return The on heap size for L2 block cache.
   */
public static float getL2BlockCacheHeapPercent(Configuration conf) {
    float l2CachePercent = 0.0F;
    String bucketCacheIOEngineName = conf.get(HConstants.BUCKET_CACHE_IOENGINE_KEY, null);
    // L2 block cache can be on heap when IOEngine is "heap"
    if (bucketCacheIOEngineName != null && bucketCacheIOEngineName.startsWith("heap")) {
        float bucketCachePercentage = conf.getFloat(HConstants.BUCKET_CACHE_SIZE_KEY, 0F);
        long max = -1L;
        final MemoryUsage usage = safeGetHeapMemoryUsage();
        if (usage != null) {
            max = usage.getMax();
        }
        l2CachePercent = bucketCachePercentage < 1 ? bucketCachePercentage : (bucketCachePercentage * 1024 * 1024) / max;
    }
    return l2CachePercent;
}
Also used : MemoryUsage(java.lang.management.MemoryUsage)

Aggregations

MemoryUsage (java.lang.management.MemoryUsage)63 MemoryMXBean (java.lang.management.MemoryMXBean)13 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)11 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)6 RuntimeMXBean (java.lang.management.RuntimeMXBean)6 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)4 ThreadMXBean (java.lang.management.ThreadMXBean)4 HashMap (java.util.HashMap)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 NotNull (org.jetbrains.annotations.NotNull)3 ApplicationInfo (com.intellij.openapi.application.ApplicationInfo)2 GarbageCollectionNotificationInfo (com.sun.management.GarbageCollectionNotificationInfo)2 BufferPoolMXBean (java.lang.management.BufferPoolMXBean)2 ClassLoadingMXBean (java.lang.management.ClassLoadingMXBean)2 Date (java.util.Date)2 CacheServiceMBean (org.apache.cassandra.service.CacheServiceMBean)2 Metric (com.codahale.metrics.Metric)1 RatioGauge (com.codahale.metrics.RatioGauge)1