Example usage for java.lang.management MemoryPoolMXBean getPeakUsage

List of usage examples for java.lang.management MemoryPoolMXBean getPeakUsage

Introduction

In this page you can find the example usage for java.lang.management MemoryPoolMXBean getPeakUsage.

Prototype

public MemoryUsage getPeakUsage();

Source Link

Document

Returns the peak memory usage of this memory pool since the Java virtual machine was started or since the peak was reset.

Usage

From source file:MainClass.java

public static void premain(final Instrumentation inst) {
    Runtime.getRuntime().addShutdownHook(new Thread() {
        public void run() {
            try {
                PrintWriter out = new PrintWriter(System.err);

                ThreadMXBean tb = ManagementFactory.getThreadMXBean();
                out.printf("Current thread count: %d%n", tb.getThreadCount());
                out.printf("Peak thread count: %d%n", tb.getPeakThreadCount());

                List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
                for (MemoryPoolMXBean pool : pools) {
                    MemoryUsage peak = pool.getPeakUsage();
                    out.printf("Peak %s memory used: %,d%n", pool.getName(), peak.getUsed());
                    out.printf("Peak %s memory reserved: %,d%n", pool.getName(), peak.getCommitted());
                }//from w ww  .j a va 2 s . c o  m

                Class[] loaded = inst.getAllLoadedClasses();
                out.println("Loaded classes:");
                for (Class c : loaded)
                    out.println(c.getName());
                out.close();
            } catch (Throwable t) {
                System.err.println("Exception in agent: " + t);
            }
        }
    });
}

From source file:com.datumbox.common.utilities.ProcessStatistics.java

public long peakMemoryBytes() {
    long maxBytes = Long.MIN_VALUE;

    List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
    for (MemoryPoolMXBean pool : pools) {
        MemoryUsage peak = pool.getPeakUsage();

        long peakUsed = peak.getUsed();
        if (maxBytes < peakUsed) {
            maxBytes = peakUsed;/*from   w ww . j av a 2 s.c o  m*/
        }
    }

    return maxBytes;
}

From source file:org.carrot2.core.benchmarks.memtime.MemTimeBenchmark.java

/**
 * Return the peak number of bytes used (all memory pools) and reset the peak usage.
 */// ww w . j a va 2s.  c o m
private static long memPeak() {
    long peak = 0;
    for (MemoryPoolMXBean b : ManagementFactory.getMemoryPoolMXBeans()) {
        peak += b.getPeakUsage().getUsed();
        b.resetPeakUsage();
    }

    return peak;
}

From source file:org.mifos.framework.ApplicationInitializer.java

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("+++++++++++++++++++");
    }/* ww  w .jav  a 2  s  . com*/
}