當前位置: 首頁>>代碼示例>>Java>>正文


Java MemoryPoolMXBean.getUsage方法代碼示例

本文整理匯總了Java中java.lang.management.MemoryPoolMXBean.getUsage方法的典型用法代碼示例。如果您正苦於以下問題:Java MemoryPoolMXBean.getUsage方法的具體用法?Java MemoryPoolMXBean.getUsage怎麽用?Java MemoryPoolMXBean.getUsage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.management.MemoryPoolMXBean的用法示例。


在下文中一共展示了MemoryPoolMXBean.getUsage方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: reportUsage

import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
private void reportUsage(MemoryPoolMXBean mxBean, MetricRecorder.Context metricContext)
{
    String name = mxBean.getName();
    Metric usedMetric = Metric.define("MemoryPoolUsed_" + name);
    Metric maxMetric = Metric.define("MemoryPoolMax_" + name);
    Metric percMetric = Metric.define("MemoryPoolUsage_" + name);

    MemoryUsage usage = mxBean.getUsage();
    long used = usage.getUsed();
    long max = usage.getMax();

    metricContext.record(usedMetric, used / M, Unit.MEGABYTE);

    // max can be undefined (-1) https://docs.oracle.com/javase/8/docs/api/java/lang/management/MemoryUsage.html
    if (max >= 0) {
        metricContext.record(maxMetric, max / M, Unit.MEGABYTE);

        double used_percent = 100.0 * ((double)used/(double)max);
        metricContext.record(percMetric, used_percent, Unit.PERCENT);
    }

}
 
開發者ID:awslabs,項目名稱:swage,代碼行數:23,代碼來源:MemoryPoolSensor.java

示例2: poolSummaries

import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
/**
 * Returns a summary information about the memory pools.
 */
public static String poolSummaries() {
    // Why ? list-archive?4273859
    // How ? http://stackoverflow.com/questions/697336/how-do-i-programmatically-find-out-my-permgen-space-usage
    //       http://stackoverflow.com/questions/8356416/xxmaxpermsize-with-or-without-xxpermsize
    StringBuilder sb = new StringBuilder();
    Iterator<MemoryPoolMXBean> iter =
            ManagementFactory.getMemoryPoolMXBeans().iterator();
    while (iter.hasNext()) {
        MemoryPoolMXBean item = iter.next();
        String name = item.getName();
        MemoryType type = item.getType();
        MemoryUsage usage = item.getUsage();
        MemoryUsage peak = item.getPeakUsage();
        MemoryUsage collections = item.getCollectionUsage();
        sb.append(String.format("Memory pool name: " + name
                                + ", type: " + type
                                + ", usage: " + usage
                                + ", peak: " + peak
                                + ", collections: " + collections
                                + "\n"));
    }
    return sb.toString();
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:27,代碼來源:Memory.java

示例3: eatMetaspace

import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
private List<Object> eatMetaspace(float targetUsage) {
    List<Object> list = new ArrayList<>();
    MemoryPoolMXBean metaspacePool = getMatchedMemoryPool(".*Metaspace.*");
    float currentUsage;
    GeneratedClassProducer gp = new GeneratedClassProducer();
    do {
        try {
            list.add(gp.create(0));
        } catch (OutOfMemoryError oome) {
            list = null;
            throw new RuntimeException("Unexpected OOME '" + oome.getMessage() + "' while eating " + targetUsage + " of Metaspace.");
        }
        MemoryUsage memoryUsage = metaspacePool.getUsage();
        currentUsage = (((float) memoryUsage.getUsed()) / memoryUsage.getMax());
    } while (currentUsage < targetUsage);
    return list;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:GarbageProducer.java

示例4: getMemoryPool

import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
@Override
public MemoryPool getMemoryPool(final MemoryPoolMXBean memoryPoolBean) {
  final MemoryPool.Type type = MemoryPool.Type.from(memoryPoolBean);

  boolean found = false;
  for (final MemoryPool.Type supportedType : getSupportedMemoryPoolTypes()) {
    if (type == supportedType) {
      found = true;
      break;
    }
  }

  if (!found) {
    throw new IllegalStateException(
        String.format("The memory pool type '%s' is not supported on the JVM type '%s'",
            type, this));
  }

  return new MemoryPoolImpl(type, new Supplier<MemoryUsage>() {
    @Override
    public MemoryUsage get() {
      return memoryPoolBean.getUsage();
    }
  });
}
 
開發者ID:SAP,項目名稱:java-memory-assistant,代碼行數:26,代碼來源:JavaVirtualMachine.java

示例5: verifyMemoryPool

import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
private static void verifyMemoryPool(MemoryPoolMXBean pool, boolean isMaxDefined) {
    MemoryUsage mu = pool.getUsage();
    assertDefined(mu.getInit(), "init");
    assertDefined(mu.getUsed(), "used");
    assertDefined(mu.getCommitted(), "committed");

    if (isMaxDefined) {
        assertDefined(mu.getMax(), "max");
    } else {
        assertUndefined(mu.getMax(), "max");
    }
}
 
開發者ID:arodchen,項目名稱:MaxSim,代碼行數:13,代碼來源:TestMetaspaceMemoryPool.java

示例6: getUsage

import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
/**
 * Get MemoryUsage from MemoryPoolMXBean which name matches passed string.
 *
 * @param name
 * @return MemoryUsage
 */
private static MemoryUsage getUsage(String name){
    for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
        if (pool.getName().matches(name)) {
            return pool.getUsage();
        }
    }
    return null;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:HeapRegionUsageTool.java

示例7: getOldGenAllocationRatio

import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
/**
 * Returns allocation rate for old gen based on appropriate MemoryPoolMXBean
 * memory usage.
 *
 * @return allocation rate
 */
public float getOldGenAllocationRatio() {
    MemoryPoolMXBean oldGenBean = getMatchedMemoryPool(".*Old.*|.*Tenured.*");
    MemoryUsage usage = oldGenBean.getUsage();
    System.out.format("Memory usage for %1s.\n", oldGenBean.getName());
    System.out.format("Used: %1d\n", usage.getUsed());
    System.out.format("Commited: %1d\n", usage.getCommitted());
    System.out.format("Max: %1d\n", usage.getMax());
    return ((float) usage.getUsed()) / usage.getCommitted();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:GarbageProducer.java

示例8: jvmStats

import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
public static JvmStats jvmStats() {
    MemoryUsage memUsage = memoryMXBean.getHeapMemoryUsage();
    long heapUsed = memUsage.getUsed() < 0 ? 0 : memUsage.getUsed();
    long heapCommitted = memUsage.getCommitted() < 0 ? 0 : memUsage.getCommitted();
    long heapMax = memUsage.getMax() < 0 ? 0 : memUsage.getMax();
    memUsage = memoryMXBean.getNonHeapMemoryUsage();
    long nonHeapUsed = memUsage.getUsed() < 0 ? 0 : memUsage.getUsed();
    long nonHeapCommitted = memUsage.getCommitted() < 0 ? 0 : memUsage.getCommitted();
    List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
    List<MemoryPool> pools = new ArrayList<>();
    for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) {
        try {
            MemoryUsage usage = memoryPoolMXBean.getUsage();
            MemoryUsage peakUsage = memoryPoolMXBean.getPeakUsage();
            String name = GcNames.getByMemoryPoolName(memoryPoolMXBean.getName(), null);
            if (name == null) { // if we can't resolve it, its not interesting.... (Per Gen, Code Cache)
                continue;
            }
            pools.add(new MemoryPool(name,
                    usage.getUsed() < 0 ? 0 : usage.getUsed(),
                    usage.getMax() < 0 ? 0 : usage.getMax(),
                    peakUsage.getUsed() < 0 ? 0 : peakUsage.getUsed(),
                    peakUsage.getMax() < 0 ? 0 : peakUsage.getMax()
            ));
        } catch (Exception ex) {
            /* ignore some JVMs might barf here with:
             * java.lang.InternalError: Memory Pool not found
             * we just omit the pool in that case!*/
        }
    }
    Mem mem = new Mem(heapCommitted, heapUsed, heapMax, nonHeapCommitted, nonHeapUsed, Collections.unmodifiableList(pools));
    Threads threads = new Threads(threadMXBean.getThreadCount(), threadMXBean.getPeakThreadCount());

    List<GarbageCollectorMXBean> gcMxBeans = ManagementFactory.getGarbageCollectorMXBeans();
    GarbageCollector[] collectors = new GarbageCollector[gcMxBeans.size()];
    for (int i = 0; i < collectors.length; i++) {
        GarbageCollectorMXBean gcMxBean = gcMxBeans.get(i);
        collectors[i] = new GarbageCollector(GcNames.getByGcName(gcMxBean.getName(), gcMxBean.getName()),
                gcMxBean.getCollectionCount(), gcMxBean.getCollectionTime());
    }
    GarbageCollectors garbageCollectors = new GarbageCollectors(collectors);
    List<BufferPool> bufferPoolsList = Collections.emptyList();
    try {
        List<BufferPoolMXBean> bufferPools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
        bufferPoolsList = new ArrayList<>(bufferPools.size());
        for (BufferPoolMXBean bufferPool : bufferPools) {
            bufferPoolsList.add(new BufferPool(bufferPool.getName(), bufferPool.getCount(),
                    bufferPool.getTotalCapacity(), bufferPool.getMemoryUsed()));
        }
    } catch (Exception e) {
        // buffer pools are not available
    }

    Classes classes = new Classes(classLoadingMXBean.getLoadedClassCount(), classLoadingMXBean.getTotalLoadedClassCount(),
            classLoadingMXBean.getUnloadedClassCount());

    return new JvmStats(System.currentTimeMillis(), runtimeMXBean.getUptime(), mem, threads,
            garbageCollectors, bufferPoolsList, classes);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:60,代碼來源:JvmStats.java

示例9: format

import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
String format(LogParams logParams, int n)
{
	 
	if(n == 0)
	{
		String csMessage = logParams.toString();
		csMessage = logParams.toString();
		StackTraceElement stackElem = logParams.m_caller;
		String csOut;
		if(stackElem != null)
		{
			String csFile = stackElem.getFileName();
			int nLine = stackElem.getLineNumber();
			csOut = csFile+"("+nLine+"):"+csMessage;
		}
		else
		{
			csOut = "():"+csMessage;
		}
		csOut += "\r\n******** Mem:";
		int nMem = 0;
		List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
		for (MemoryPoolMXBean p: pools)
		{
			if(p.getType().compareTo(MemoryType.HEAP) == 0)
			{
				String cs = p.getName();
				MemoryUsage mem = p.getUsage();
				long l = mem.getUsed();
				long lOldMem = m_mem[nMem];
				long lOffset = l - lOldMem; 
				csOut += cs+"="+l+"["+lOffset+"];";
				m_mem[nMem] = l;
				nMem++;
			}
		}
		csOut += "\r\n";
		return csOut;
	}
	return null;
}
 
開發者ID:costea7,項目名稱:ChronoBike,代碼行數:42,代碼來源:PatternLayoutSTCheck.java

示例10: readHeapPoolUsage

import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
public static Map<String, Long> readHeapPoolUsage(List<MemoryPoolMXBean> pmbList) {

        Map<String, Long> m = new LinkedHashMap<String, Long>();

        for (MemoryPoolMXBean mpmb : pmbList) {

            String jvmMemPoolName = getHeapPoolName(mpmb.getName().trim());

            MemoryUsage mu = mpmb.getUsage();

            m.put(jvmMemPoolName + "_use", mu.getUsed());
            m.put(jvmMemPoolName + "_commit", mu.getCommitted());
            m.put(jvmMemPoolName + "_max", mu.getMax());
            m.put(jvmMemPoolName + "_init", mu.getInit());
        }

        return m;
    }
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:19,代碼來源:JVMToolHelper.java

示例11: readHeapPoolUsage

import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
private void readHeapPoolUsage(MonitorElementInstance instance) {

        List<MemoryPoolMXBean> pmbList = ManagementFactory.getMemoryPoolMXBeans();

        for (MemoryPoolMXBean mpmb : pmbList) {

            String jvmMemPoolName = getHeapPoolName(mpmb.getName().trim());

            MemoryUsage mu = mpmb.getUsage();

            instance.setValue(jvmMemPoolName + "_use", mu.getUsed());
            instance.setValue(jvmMemPoolName + "_commit", mu.getCommitted());
            instance.setValue(jvmMemPoolName + "_max", mu.getMax());
            instance.setValue(jvmMemPoolName + "_init", mu.getInit());
        }
    }
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:17,代碼來源:JVMStateCapHandler.java


注:本文中的java.lang.management.MemoryPoolMXBean.getUsage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。