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


Java MemoryUsage类代码示例

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


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

示例1: MemoryPoolStat

import java.lang.management.MemoryUsage; //导入依赖的package包/类
MemoryPoolStat(String name,
               long usageThreshold,
               MemoryUsage usage,
               long lastGcId,
               long lastGcStartTime,
               long lastGcEndTime,
               long collectThreshold,
               MemoryUsage beforeGcUsage,
               MemoryUsage afterGcUsage) {
    this.poolName = name;
    this.usageThreshold = usageThreshold;
    this.usage = usage;
    this.lastGcId = lastGcId;
    this.lastGcStartTime = lastGcStartTime;
    this.lastGcEndTime = lastGcEndTime;
    this.collectThreshold = collectThreshold;
    this.beforeGcUsage = beforeGcUsage;
    this.afterGcUsage = afterGcUsage;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:MemoryPoolStat.java

示例2: getYoungGenUsage

import java.lang.management.MemoryUsage; //导入依赖的package包/类
/**
 *  Get young gen memory usage.
 *
 *  For G1 it is EdenUsage + SurvivorUsage,
 *  for other GCs it is EdenUsage + 2 * SurvivorUsage.
 *  For G1 max value is just LONG_MAX.
 *  For all GCs used value is 0.
 */
private static MemoryUsage getYoungGenUsage() {
    MemoryUsage edenUsage = HeapRegionUsageTool.getEdenUsage();
    MemoryUsage survivorUsage = HeapRegionUsageTool.getSurvivorUsage();
    long edenUsageInit = edenUsage.getInit();
    long edenUsageCommited = edenUsage.getCommitted();
    long survivorUsageInit = survivorUsage.getInit();
    long survivorUsageCommited = survivorUsage.getCommitted();

    if (YOUNG_GC_TYPE == GCTypes.YoungGCType.G1) {
        return new MemoryUsage(edenUsageInit + survivorUsageInit, 0,
                edenUsageCommited + survivorUsageCommited, Long.MAX_VALUE);
    } else {
        return new MemoryUsage(edenUsageInit + survivorUsageInit * 2, 0,
                edenUsageCommited + survivorUsageCommited * 2,
                edenUsage.getMax() + survivorUsage.getMax() * 2);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:TestNewSizeFlags.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: status

import java.lang.management.MemoryUsage; //导入依赖的package包/类
public static void status(Scanner scanner, Message message) {
    StringBuffer buffer = new StringBuffer();
    buffer.append("My Memory:\n\n");
    buffer.append("\n\n");
    for (MemPool pool : getPools()) {
        MemoryUsage usage = pool.getUsage();
        buffer.append(pool.getName()).append("\n");
        buffer.append("\tINIT:     ").append(FileUtils.byteCountToDisplaySize(usage.getInit()))
                .append("\n");
        buffer.append("\tUSED:     ").append(FileUtils.byteCountToDisplaySize(usage.getUsed()))
                .append("\n");
        buffer.append("\tCOMMITED: ")
                .append(FileUtils.byteCountToDisplaySize(usage.getCommitted())).append("\n");
        buffer.append("\tMAX:      ").append(FileUtils.byteCountToDisplaySize(usage.getMax()))
                .append("\n");
    }
    Speaker.sayCode(message.getChannel(), buffer.toString());
}
 
开发者ID:BlackCraze,项目名称:GameResourceBot,代码行数:19,代码来源:Commands.java

示例5: 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

示例6: GcInfo

import java.lang.management.MemoryUsage; //导入依赖的package包/类
private GcInfo(GcInfoBuilder builder,
               long index, long startTime, long endTime,
               MemoryUsage[] muBeforeGc,
               MemoryUsage[] muAfterGc,
               Object[] extAttributes) {
    this.builder       = builder;
    this.index         = index;
    this.startTime     = startTime;
    this.endTime       = endTime;
    String[] poolNames = builder.getPoolNames();
    this.usageBeforeGc = new HashMap<String, MemoryUsage>(poolNames.length);
    this.usageAfterGc = new HashMap<String, MemoryUsage>(poolNames.length);
    for (int i = 0; i < poolNames.length; i++) {
        this.usageBeforeGc.put(poolNames[i],  muBeforeGc[i]);
        this.usageAfterGc.put(poolNames[i],  muAfterGc[i]);
    }
    this.extAttributes = extAttributes;
    this.cdata = new GcInfoCompositeData(this, builder, extAttributes);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:GcInfo.java

示例7: poolSummaries

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

示例8: next

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

  final NodeEndpoint endpoint = dbContext.getEndpoint();
  memoryInfo.hostname = endpoint.getAddress();
  memoryInfo.fabric_port = endpoint.getFabricPort();

  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 = dbContext.getAllocator().getAllocatedMemory();
  memoryInfo.direct_max = SabotConfig.getMaxDirectMemory();
  return memoryInfo;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:25,代码来源:MemoryIterator.java

示例9: createNotification

import java.lang.management.MemoryUsage; //导入依赖的package包/类
static void createNotification(String notifType,
                               String poolName,
                               MemoryUsage usage,
                               long count) {
    MemoryImpl mbean = (MemoryImpl) ManagementFactory.getMemoryMXBean();
    if (!mbean.hasListeners()) {
        // if no listener is registered.
        return;
    }
    long timestamp = System.currentTimeMillis();
    String msg = getNotifMsg(notifType);
    Notification notif = new Notification(notifType,
                                          mbean.getObjectName(),
                                          getNextSeqNumber(),
                                          timestamp,
                                          msg);
    MemoryNotificationInfo info =
        new MemoryNotificationInfo(poolName,
                                   usage,
                                   count);
    CompositeData cd =
        MemoryNotifInfoCompositeData.toCompositeData(info);
    notif.setUserData(cd);
    mbean.sendNotification(notif);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:MemoryImpl.java

示例10: test

import java.lang.management.MemoryUsage; //导入依赖的package包/类
private final void test() {
    System.gc();
    MemoryUsagePrinter.printMemoryUsage("init");

    eat();
    MemoryUsagePrinter.printMemoryUsage("eaten");
    MemoryUsage muFull = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();

    free();
    MemoryUsagePrinter.printMemoryUsage("free");
    MemoryUsage muFree = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();

    assertLessThan(muFree.getCommitted(), muFull.getCommitted(), String.format(
            "committed free heap size is not less than committed full heap size, heap hasn't been shrunk?%n"
            + "%s = %s%n%s = %s",
            MIN_FREE_RATIO_FLAG_NAME,
            ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class)
                .getVMOption(MIN_FREE_RATIO_FLAG_NAME).getValue(),
            MAX_FREE_RATIO_FLAG_NAME,
            ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class)
                .getVMOption(MAX_FREE_RATIO_FLAG_NAME).getValue()
    ));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:TestDynShrinkHeap.java

示例11: getL2

import java.lang.management.MemoryUsage; //导入依赖的package包/类
/**
 * @param c Configuration to use.
 * @param mu JMX Memory Bean
 * @return Returns L2 block cache instance (for now it is BucketCache BlockCache all the time)
 * or null if not supposed to be a L2.
 */
private static BlockCache getL2(final Configuration c, final MemoryUsage mu) {
  final boolean useExternal = c.getBoolean(EXTERNAL_BLOCKCACHE_KEY, EXTERNAL_BLOCKCACHE_DEFAULT);
  if (LOG.isDebugEnabled()) {
    LOG.debug("Trying to use " + (useExternal?" External":" Internal") + " l2 cache");
  }

  // If we want to use an external block cache then create that.
  if (useExternal) {
    return getExternalBlockcache(c);
  }

  // otherwise use the bucket cache.
  return getBucketCache(c, mu);

}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:22,代码来源:CacheConfig.java

示例12: envi

import java.lang.management.MemoryUsage; //导入依赖的package包/类
@Override
public String envi() {
    Map<String, String> result = new HashMap<String, String>();
    // 系统信息
    result.put(RegistryMonitorConstants.OSNAME, System.getProperty(RegistryMonitorConstants.OSNAME, "not specified"));
    result.put(RegistryMonitorConstants.JAVA_VERSION, System.getProperty(RegistryMonitorConstants.JAVA_VERSION, "not specified"));
    result.put(RegistryMonitorConstants.JDK_PATH, System.getProperty(RegistryMonitorConstants.JDK_PATH, "not specified"));
    result.put(RegistryMonitorConstants.APP_PATH, System.getProperty(RegistryMonitorConstants.APP_PATH, "not specified"));

    // jvm信息
    MemoryMXBean memorymbean = ManagementFactory.getMemoryMXBean();
    MemoryUsage usage = memorymbean.getHeapMemoryUsage();
    result.put(RegistryMonitorConstants.JVM_INIT, String.valueOf(usage.getInit()));
    result.put(RegistryMonitorConstants.JVM_MAX, String.valueOf(usage.getMax()));
    result.put(RegistryMonitorConstants.JVM_USED, String.valueOf(usage.getUsed()));
    
    //线程信息
    ThreadMXBean tm = (ThreadMXBean) ManagementFactory.getThreadMXBean();
    result.put(RegistryMonitorConstants.JVM_THREAD_COUNT, String.valueOf(tm.getThreadCount()));
    result.put(RegistryMonitorConstants.JVM_PEAKTHREAD_COUNT, String.valueOf(tm.getPeakThreadCount()));
    result.put(RegistryMonitorConstants.JVM_CURRENTTHREAD_CPUTIME, String.valueOf(tm.getCurrentThreadCpuTime()));
    result.put(RegistryMonitorConstants.JVM_CURRENTTHREAD_USERTIME, String.valueOf(tm.getCurrentThreadUserTime()));
    return JSON.toJSONString(result);
}
 
开发者ID:tiglabs,项目名称:jsf-core,代码行数:25,代码来源:RegistryStatusServiceImpl.java

示例13: test

import java.lang.management.MemoryUsage; //导入依赖的package包/类
private final void test() {
    System.gc();
    MemoryUsagePrinter.printMemoryUsage("init");

    allocate();
    MemoryUsagePrinter.printMemoryUsage("allocated");
    MemoryUsage muFull = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();

    free();
    MemoryUsagePrinter.printMemoryUsage("free");
    MemoryUsage muFree = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();

    assertLessThan(muFree.getCommitted(), muFull.getCommitted(), String.format(
            "committed free heap size is not less than committed full heap size, heap hasn't been shrunk?%n"
            + "%s = %s%n%s = %s",
            MIN_FREE_RATIO_FLAG_NAME,
            ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class)
                .getVMOption(MIN_FREE_RATIO_FLAG_NAME).getValue(),
            MAX_FREE_RATIO_FLAG_NAME,
            ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class)
                .getVMOption(MAX_FREE_RATIO_FLAG_NAME).getValue()
    ));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:TestHumongousShrinkHeap.java

示例14: getMemoryUsageAfterGc

import java.lang.management.MemoryUsage; //导入依赖的package包/类
public static Map<String, MemoryUsage>
        getMemoryUsageAfterGc(CompositeData cd) {
    try {
        TabularData td = (TabularData) cd.get(MEMORY_USAGE_AFTER_GC);
        //return (Map<String,MemoryUsage>)
        return cast(memoryUsageMapType.toJavaTypeData(td));
    } catch (InvalidObjectException | OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:GcInfoCompositeData.java

示例15: calculateMaxSize

import java.lang.management.MemoryUsage; //导入依赖的package包/类
static long calculateMaxSize(Set<GarbageCollectionEvent> events) {
    if (events.size() < 1) {
        return -1;
    }

    // Maximum pool size is fixed, so we should only need to get it from the first event
    MemoryUsage usage = events.iterator().next().getUsage();
    return usage.getMax();
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:10,代码来源:GarbageCollectionStats.java


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