当前位置: 首页>>代码示例>>Java>>正文


Java MemoryUsage.getUsed方法代码示例

本文整理汇总了Java中java.lang.management.MemoryUsage.getUsed方法的典型用法代码示例。如果您正苦于以下问题:Java MemoryUsage.getUsed方法的具体用法?Java MemoryUsage.getUsed怎么用?Java MemoryUsage.getUsed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.management.MemoryUsage的用法示例。


在下文中一共展示了MemoryUsage.getUsed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: reportUsage

import java.lang.management.MemoryUsage; //导入方法依赖的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: next

import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
@Override
public Object next() {
  if (!beforeFirst) {
    throw new IllegalStateException();
  }
  beforeFirst = false;
  final MemoryInfo memoryInfo = new MemoryInfo();

  final DrillbitEndpoint endpoint = context.getIdentity();
  memoryInfo.hostname = endpoint.getAddress();
  memoryInfo.user_port = endpoint.getUserPort();

  final MemoryUsage heapMemoryUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
  memoryInfo.heap_current = heapMemoryUsage.getUsed();
  memoryInfo.heap_max = heapMemoryUsage.getMax();

  BufferPoolMXBean directBean = getDirectBean();
  memoryInfo.jvm_direct_current = directBean.getMemoryUsed();


  memoryInfo.direct_current = context.getDrillbitContext().getAllocator().getAllocatedMemory();
  memoryInfo.direct_max = TopLevelAllocator.MAXIMUM_DIRECT_MEMORY;
  return memoryInfo;
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:25,代码来源:MemoryIterator.java

示例3: eatMetaspace

import java.lang.management.MemoryUsage; //导入方法依赖的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: chore

import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
@Override
protected void chore() {
  // Sample heap occupancy
  MemoryUsage memUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
  heapOccupancyPercent = (float)memUsage.getUsed() / (float)memUsage.getCommitted();
  // If we are above the heap occupancy alarm low watermark, switch to short
  // sleeps for close monitoring. Stop autotuning, we are in a danger zone.
  if (heapOccupancyPercent >= heapOccupancyLowWatermark) {
    if (!alarming) {
      LOG.warn("heapOccupancyPercent " + heapOccupancyPercent +
        " is above heap occupancy alarm watermark (" + heapOccupancyLowWatermark + ")");
      alarming = true;
    }

    triggerNow();
    try {
      // Need to sleep ourselves since we've told the chore's sleeper
      // to skip the next sleep cycle.
      Thread.sleep(1000);
    } catch (InterruptedException e) {
      // Interrupted, propagate
      Thread.currentThread().interrupt();
    }
  } else {
    if (alarming) {
      LOG.info("heapOccupancyPercent " + heapOccupancyPercent +
        " is now below the heap occupancy alarm watermark (" +
        heapOccupancyLowWatermark + ")");
      alarming = false;
    }
  }
  // Autotune if tuning is enabled and allowed
  if (tunerOn && !alarming) {
    tune();
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:37,代码来源:HeapMemoryManager.java

示例5: reportHeapUsage

import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
private void reportHeapUsage(MemoryMXBean memoryMxBean, MetricRecorder.Context metricContext) {
    MemoryUsage usage = memoryMxBean.getHeapMemoryUsage();

    long used = usage.getUsed();
    metricContext.record(HEAP, used / M, Unit.MEGABYTE);

    long max = usage.getMax();
    if (max >= 0) {
        metricContext.record(HEAP_MAX, max / M, Unit.MEGABYTE);

        double used_percent = 100.0 * ((double)used/(double)max);
        metricContext.record(HEAP_USED, used_percent, Unit.PERCENT);
    }
}
 
开发者ID:awslabs,项目名称:swage,代码行数:15,代码来源:MemorySensor.java

示例6: reportNonHeapUsage

import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
private void reportNonHeapUsage(MemoryMXBean memoryMxBean, MetricRecorder.Context metricContext) {
    MemoryUsage usage = memoryMxBean.getNonHeapMemoryUsage();

    long used = usage.getUsed();
    metricContext.record(NON_HEAP, used / M, Unit.MEGABYTE);

    long max = usage.getMax();
    if (max >= 0) {
        metricContext.record(NON_HEAP_MAX, max / M, Unit.MEGABYTE);

        double used_percent = 100.0 * ((double)used/(double)max);
        metricContext.record(NON_HEAP_USED, used_percent, Unit.PERCENT);
    }
}
 
开发者ID:awslabs,项目名称:swage,代码行数:15,代码来源:MemorySensor.java

示例7: call

import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
@Override
public Boolean call() throws Exception {
    if (this.memBean != null) {
        final MemoryUsage usage = this.memBean.getHeapMemoryUsage();
        if (usage != null) {
            long used = usage.getUsed();
            long max = usage.getMax();
            final boolean res = used > max * heapLimit;
            if (LOG.isLoggable(Level.FINEST)) {
                final long now = System.currentTimeMillis();
                if (now - lastTime > LOGGER_RATE) {
                    LOG.log(
                        Level.FINEST,
                        "Max memory: {0}, Used memory: {1}, Low memory condition: {2}", //NOI18N
                        new Object[]{
                            max,
                            used,
                            res
                        });
                    lastTime = now;
                }
            }
            return res;
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:LowMemoryWatcher.java

示例8: testXDMModelSize

import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
public void testXDMModelSize() throws Exception {
    System.out.println("XDM Mem usage");
    MemoryUsage usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
    long mem0 = usage.getUsed();
    javax.swing.text.Document swdoc = Util.getResourceAsDocument("resources/fields.xsd");
    usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();                                                              
    long mem1 = usage.getUsed();
    
    long memuse = mem1-mem0;
    
    System.out.println("Document creation = " + memuse + " bytes");

    Lookup lookup = Lookups.singleton(swdoc);
    usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
    long mem2 = usage.getUsed();
    ModelSource ms = new ModelSource(lookup, true);
    usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
    long mem3 = usage.getUsed();
    memuse = mem3-mem2;
    
    System.out.println("Model source creation = " + memuse + " bytes"); 

    XDMModel m = new XDMModel(ms);
    m.sync();
    usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
    long mem4 = usage.getUsed();
    memuse = mem4-mem3;
    System.out.println("XDM creation = " + memuse + " bytes");
    //System.out.println("Time taken to create XDM model: " + (endTime - startTime));
    
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:XDMModelTest.java

示例9: Datum

import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
/**
 * Constructor accepts some system values and generates some Java values.
 *
 * @param rss Resident set size.
 */
Datum(long rss) {
    MemoryMXBean mmxb = ManagementFactory.getMemoryMXBean();
    MemoryUsage muheap = mmxb.getHeapMemoryUsage();
    MemoryUsage musys = mmxb.getNonHeapMemoryUsage();

    timestamp = System.currentTimeMillis();
    this.rss = rss;
    javatotalheapmem = muheap.getCommitted();
    javausedheapmem = muheap.getUsed();
    javatotalsysmem = musys.getCommitted();
    javausedsysmem = musys.getUsed();
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:18,代码来源:SystemStatsCollector.java

示例10: isUsageThresholdExceeded

import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
public boolean isUsageThresholdExceeded() {
    if (!isUsageThresholdSupported()) {
        throw new UnsupportedOperationException(
            "Usage threshold is not supported");
    }

    // return false if usage threshold crossing checking is disabled
    if (usageThreshold == 0) {
        return false;
    }

    MemoryUsage u = getUsage0();
    return (u.getUsed() >= usageThreshold ||
            usageSensor.isOn());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:MemoryPoolImpl.java

示例11: isCollectionUsageThresholdExceeded

import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
public boolean isCollectionUsageThresholdExceeded() {
    if (!isCollectionUsageThresholdSupported()) {
        throw new UnsupportedOperationException(
            "CollectionUsage threshold is not supported");
    }

    // return false if usage threshold crossing checking is disabled
    if (collectionThreshold == 0) {
        return false;
    }

    MemoryUsage u = getCollectionUsage0();
    return (gcSensor.isOn() ||
            (u != null && u.getUsed() >= collectionThreshold));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:MemoryPoolImpl.java

示例12: printMemoryUsage

import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
void printMemoryUsage() {
    if (options.verbose) {
        MemoryUsage memusage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
        float freeratio = 1f - (float) memusage.getUsed() / memusage.getCommitted();
        log.format(" [used: %-7s, comm: %-7s, freeRatio ~= %.1f%%]",
                        humanReadableByteCount(memusage.getUsed()),
                        humanReadableByteCount(memusage.getCommitted()),
                        freeratio * 100);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:LogPrinter.java

示例13: printMemoryUsage

import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
public static void printMemoryUsage(String label) {
    MemoryUsage memusage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
    float freeratio = 1f - (float) memusage.getUsed() / memusage.getCommitted();
    System.out.format("[%-24s] init: %-7s, used: %-7s, comm: %-7s, freeRatio ~= %.1f%%%n",
            label,
            NF.format(memusage.getInit()),
            NF.format(memusage.getUsed()),
            NF.format(memusage.getCommitted()),
            freeratio * 100
    );
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:TestShrinkDefragmentedHeap.java

示例14: jvmStats

import java.lang.management.MemoryUsage; //导入方法依赖的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

示例15: getCurrentUsageRatio

import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
private double getCurrentUsageRatio() {
  final MemoryUsage memoryUsage = memoryPool.getMemoryUsage();
  return memoryUsage.getUsed() * 100d / memoryUsage.getMax();
}
 
开发者ID:SAP,项目名称:java-memory-assistant,代码行数:5,代码来源:PercentageUsageThresholdCondition.java


注:本文中的java.lang.management.MemoryUsage.getUsed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。