Created
June 6, 2018 03:54
-
-
Save qsLI/bd80dc3b2abb82ac778a9403bde62bf5 to your computer and use it in GitHub Desktop.
get directmemory usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ page import="java.lang.management.BufferPoolMXBean" %> | |
<%@ page import="java.util.List" %> | |
<%@ page import="java.lang.management.ManagementFactory" %><%-- | |
Created by IntelliJ IDEA. | |
User: qishengli | |
Date: 18-6-6 | |
Time: 上午11:40 | |
To change this template use File | Settings | File Templates. | |
--%> | |
<% | |
List<BufferPoolMXBean> pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class); | |
for (BufferPoolMXBean pool : pools) { | |
out.write("<BR>name: " + pool.getName()); | |
out.write("<BR>count: " + pool.getCount()); | |
out.write("<BR>memory used: " + toMB(pool.getMemoryUsed())); | |
out.write("<BR>total capacity: " + toMB(pool.getTotalCapacity())); | |
out.write("<BR><BR><BR><BR>"); | |
} | |
%> | |
<%! | |
private static String toMB(long init) { | |
return (Long.valueOf(init).doubleValue() / (1024 * 1024)) + " MB"; | |
} | |
%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
see: https://stackoverflow.com/questions/20058489/is-there-a-way-to-measure-direct-memory-usage-in-java