Example usage for java.lang.management MemoryUsage getCommitted

List of usage examples for java.lang.management MemoryUsage getCommitted

Introduction

In this page you can find the example usage for java.lang.management MemoryUsage getCommitted.

Prototype

public long getCommitted() 

Source Link

Document

Returns the amount of memory in bytes that is committed for the Java virtual machine to use.

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 w w  .ja v a  2  s . c om*/

                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:jef.testbase.JefTester.java

private static void printMem(MemoryUsage m) {
    System.out.println("??:" + StringUtils.formatSize(m.getMax()));
    System.out.println("?:" + StringUtils.formatSize(m.getCommitted()));
    System.out.println("?:" + StringUtils.formatSize(m.getInit()));
    System.out.println(":" + StringUtils.formatSize(m.getUsed()));
}

From source file:com.android.tools.idea.diagnostics.crash.GoogleCrash.java

@NotNull
private static Map<String, String> getDefaultParameters() {
    Map<String, String> map = new HashMap<>();
    ApplicationInfo applicationInfo = getApplicationInfo();

    if (ANONYMIZED_UID != null) {
        map.put("guid", ANONYMIZED_UID);
    }/*from  w ww  .j av a  2 s.c  o  m*/
    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
    map.put("ptime", Long.toString(runtimeMXBean.getUptime()));

    // product specific key value pairs
    map.put(KEY_VERSION, applicationInfo == null ? "0.0.0.0" : applicationInfo.getStrictVersion());
    map.put(KEY_PRODUCT_ID, CrashReport.PRODUCT_ANDROID_STUDIO); // must match registration with Crash
    map.put("fullVersion", applicationInfo == null ? "0.0.0.0" : applicationInfo.getFullVersion());

    map.put("osName", StringUtil.notNullize(SystemInfo.OS_NAME));
    map.put("osVersion", StringUtil.notNullize(SystemInfo.OS_VERSION));
    map.put("osArch", StringUtil.notNullize(SystemInfo.OS_ARCH));
    map.put("locale", StringUtil.notNullize(LOCALE));

    map.put("vmName", StringUtil.notNullize(runtimeMXBean.getVmName()));
    map.put("vmVendor", StringUtil.notNullize(runtimeMXBean.getVmVendor()));
    map.put("vmVersion", StringUtil.notNullize(runtimeMXBean.getVmVersion()));

    MemoryUsage usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
    map.put("heapUsed", Long.toString(usage.getUsed()));
    map.put("heapCommitted", Long.toString(usage.getCommitted()));
    map.put("heapMax", Long.toString(usage.getMax()));

    return map;
}

From source file:org.commoncrawl.util.JVMStats.java

public static void dumpMemoryStats() {

    MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
    MemoryUsage memHeap = memoryMXBean.getHeapMemoryUsage();

    List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans();

    long gcTime = 0;
    for (GarbageCollectorMXBean gcBean : gcBeans) {
        gcTime += gcBean.getCollectionTime();
    }// www. j  a v a2  s  .  com

    float utilizationRatio = ((float) memHeap.getUsed()) / ((float) memHeap.getMax());

    LOG.info("Heap Size:" + memHeap.getUsed() / MBytes + " (MB) CommitSize:" + memHeap.getCommitted() / MBytes
            + " (MB) Max:" + memHeap.getMax() + " Ratio:" + utilizationRatio + " GCTime:"
            + (gcTime - lastGCTime) + "PendingFinalCnt:" + memoryMXBean.getObjectPendingFinalizationCount());

    lastGCTime = gcTime;
}

From source file:org.soitoolkit.commons.mule.util.MiscUtil.java

private static void printMemUsage() {
    int mb = 1024 * 1024;

    MemoryMXBean mxb = ManagementFactory.getMemoryMXBean();
    MemoryUsage hm = mxb.getHeapMemoryUsage();
    MemoryUsage nhm = mxb.getNonHeapMemoryUsage();
    //      int finalizable = mxb.getObjectPendingFinalizationCount();

    logger.trace("Heap Memory:  init/used/committed/max=" + hm.getInit() / mb + "/" + hm.getUsed() / mb + "/"
            + hm.getCommitted() / mb + "/" + hm.getMax() / mb);
    logger.trace("Non-Heap Mem: init/used/committed/max=" + nhm.getInit() / mb + "/" + nhm.getUsed() / mb + "/"
            + nhm.getCommitted() / mb + "/" + nhm.getMax() / mb);
    //                 logger.trace("finalizable: " + finalizable);

    //Getting the runtime reference from system
    Runtime runtime = Runtime.getRuntime();

    logger.trace("Used/Free/Total/Max:"
            //Print used memory
            + (runtime.totalMemory() - runtime.freeMemory()) / mb + "/"

            //Print free memory
            + runtime.freeMemory() / mb + "/"

            //Print total available memory
            + runtime.totalMemory() / mb + "/"

            //Print Maximum available memory
            + runtime.maxMemory() / mb);
}

From source file:com.appeligo.captions.CaptionListener.java

private synchronized static void checkStats() {
    int interval = 5; // minutes
    long timestamp = new Date().getTime();
    if ((timestamp - lastWrite) > (interval * 60 * 1000)) {
        lastWrite = timestamp;/*from  w  ww.j ava  2s  .  c  om*/
        String day = Utils.getDatePath(timestamp);
        if (!day.equals(currentDay)) {
            if (statsFile != null) {
                statsFile.println("</table></body></html>");
                statsFile.close();
                statsFile = null;
            }
            currentDay = day;
        }
        if (hostname == null) {
            try {
                hostname = InetAddress.getLocalHost().getHostName();
            } catch (UnknownHostException e) {
                hostname = "UnknownHost";
            }
        }
        String dirname = documentRoot + "/stats/" + currentDay + "/" + hostname;
        String statsFileName = dirname + "/searchprocstats.html";
        try {
            if (statsFile == null) {
                File dir = new File(dirname);
                if ((!dir.exists()) && (!dir.mkdirs())) {
                    throw new IOException("Error creating directory " + dirname);
                }
                File file = new File(statsFileName);
                if (file.exists()) {
                    statsFile = new PrintStream(new FileOutputStream(statsFileName, true));
                    statsFile.println("<tr><td colspan='5'>Restart</td></tr>");
                } else {
                    statsFile = new PrintStream(new FileOutputStream(statsFileName));
                    String title = "Search Process (tomcat) status for " + currentDay;
                    statsFile.println("<html><head><title>" + title + "</title></head>");
                    statsFile.println("<body><h1>" + title + "</h1>");
                    statsFile.println("<table border='1'>");
                    statsFile.println("<tr>");
                    statsFile.println("<th colspan='2'>" + interval + " Minute Intervals</th>"
                            + "<th colspan='3'>Mem Pre GC</th>" + "<th>GC</th>"
                            + "<th colspan='3'>Mem Post GC</th>");
                    statsFile.println("</tr>");
                    statsFile.println("<tr>");
                    statsFile.println("<th>Timestamp</th>");
                    statsFile.println("<th>Time</th>");
                    statsFile.println("<th>Used</th>");
                    statsFile.println("<th>Committed</th>");
                    statsFile.println("<th>Max</th>");
                    statsFile.println("<th>Millis</th>");
                    statsFile.println("<th>Used</th>");
                    statsFile.println("<th>Committed</th>");
                    statsFile.println("<th>Max</th>");
                    statsFile.println("</tr>");
                }
            }
            Calendar cal = Calendar.getInstance();
            cal.setTimeZone(TimeZone.getTimeZone("GMT"));
            cal.setTimeInMillis(timestamp);
            String time = String.format("%1$tH:%1$tM:%1$tS", cal);
            MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
            MemoryUsage memory = memoryBean.getHeapMemoryUsage();
            statsFile.print("<tr>");
            statsFile.print("<td>" + timestamp + "</td>");
            statsFile.print("<td>" + time + "</td>");
            statsFile.format("<td>%,d</td>", memory.getUsed());
            statsFile.format("<td>%,d</td>", memory.getCommitted());
            statsFile.format("<td>%,d</td>", memory.getMax());
            long beforeGC = System.currentTimeMillis();
            System.gc();
            long elapsed = System.currentTimeMillis() - beforeGC;
            statsFile.format("<td>%,d</td>", (int) elapsed);
            memoryBean = ManagementFactory.getMemoryMXBean();
            memory = memoryBean.getHeapMemoryUsage();
            statsFile.format("<td>%,d</td>", memory.getUsed());
            statsFile.format("<td>%,d</td>", memory.getCommitted());
            statsFile.format("<td>%,d</td>", memory.getMax());
            statsFile.println("</tr>");
        } catch (IOException e) {
            log.error("Error opening or writing to " + statsFileName, e);
        }
    }
}

From source file:org.jahia.bin.errors.ErrorFileDumper.java

private static void printMemoryUsage(String type, MemoryUsage usage, PrintWriter strOut) {
    strOut.println();// ww  w .ja v  a 2 s . c  o m
    strOut.print(type);
    strOut.print(" : ");
    strOut.print(Math.round((float) usage.getUsed() / (float) usage.getMax() * 100f));
    strOut.println("% used");
    strOut.println("---------------");
    strOut.print("Used      : ");
    strOut.println(org.jahia.utils.FileUtils.humanReadableByteCount(usage.getUsed(), true));
    strOut.print("Committed : ");
    strOut.println(org.jahia.utils.FileUtils.humanReadableByteCount(usage.getCommitted(), true));
    strOut.print("Max       : ");
    strOut.println(org.jahia.utils.FileUtils.humanReadableByteCount(usage.getMax(), true));
}

From source file:com.chinamobile.bcbsp.comm.io.util.MemoryAllocator.java

/** Refresh memory status with current JVM status. */
private void refreshMemoryStatus() {
    MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
    MemoryUsage memoryUsage = memoryMXBean.getHeapMemoryUsage();
    used = memoryUsage.getUsed();//w  w w . j av a 2s .c  o  m
    committed = memoryUsage.getCommitted();
    maxHeapSize = memoryUsage.getMax();
    remain = maxHeapSize - used;
}

From source file:org.jahia.modules.serversettings.memoryThread.MemoryThreadInformationManagement.java

public MemoryThreadInformationManagement refresh() {
    MemoryUsage usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
    committedMemory = FileUtils.humanReadableByteCount(usage.getCommitted(), true);
    maxMemory = FileUtils.humanReadableByteCount(usage.getMax(), true);
    usedMemory = FileUtils.humanReadableByteCount(usage.getUsed(), true);
    memoryUsage = Math.round((double) usage.getUsed() / (double) usage.getMax() * 100d);
    return this;
}

From source file:com.snowstore.mercury.core.metric.SystemPublicMetrics.java

/**
 * Add JVM heap metrics./*from   ww w. j a  v  a  2 s.  co  m*/
 * 
 * @param result
 *            the result
 */
protected void addHeapMetrics(Collection<Metric<?>> result) {
    MemoryUsage memoryUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
    result.add(new Metric<Long>("heap.committed", memoryUsage.getCommitted() / 1024));
    result.add(new Metric<Long>("heap.init", memoryUsage.getInit() / 1024));
    result.add(new Metric<Long>("heap.used", memoryUsage.getUsed() / 1024));
    result.add(new Metric<Long>("heap", memoryUsage.getMax() / 1024));
}