本文整理匯總了Java中java.lang.management.MemoryPoolMXBean.getName方法的典型用法代碼示例。如果您正苦於以下問題:Java MemoryPoolMXBean.getName方法的具體用法?Java MemoryPoolMXBean.getName怎麽用?Java MemoryPoolMXBean.getName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.management.MemoryPoolMXBean
的用法示例。
在下文中一共展示了MemoryPoolMXBean.getName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: run
import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
@Override
public void run() {
List<GarbageCollectorMXBean> garbageCollectorMXBeans = ManagementFactory.getGarbageCollectorMXBeans();
GarbageCollectorMXBean garbageCollectorMXBean = CollectionUtils.findFirst(garbageCollectorMXBeans, new Spec<GarbageCollectorMXBean>() {
@Override
public boolean isSatisfiedBy(GarbageCollectorMXBean mbean) {
return mbean.getName().equals(garbageCollector);
}
});
List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) {
String pool = memoryPoolMXBean.getName();
if (memoryPools.contains(pool)) {
GarbageCollectionEvent event = new GarbageCollectionEvent(System.currentTimeMillis(), memoryPoolMXBean.getCollectionUsage(), garbageCollectorMXBean.getCollectionCount());
events.get(pool).slideAndInsert(event);
}
}
}
示例2: reportUsage
import java.lang.management.MemoryPoolMXBean; //導入方法依賴的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);
}
}
示例3: buildPoolIndexMap
import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
/**
* Builds a map pool-name => pool-index from the SnmpTableHandler
* of the JvmMemPoolTable.
**/
private static Map<String, SnmpOid> buildPoolIndexMap(SnmpTableHandler handler) {
// optimization...
if (handler instanceof SnmpCachedData)
return buildPoolIndexMap((SnmpCachedData)handler);
// not optimizable... too bad.
final Map<String, SnmpOid> m = new HashMap<>();
SnmpOid index=null;
while ((index = handler.getNext(index))!=null) {
final MemoryPoolMXBean mpm =
(MemoryPoolMXBean)handler.getData(index);
if (mpm == null) continue;
final String name = mpm.getName();
if (name == null) continue;
m.put(name,index);
}
return m;
}
示例4: isTenured
import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
/**
* Determines if the name of the memory pool MXBean provided matches a list of known tenured pool
* names.
*
* Package private for testing.
*
* @param memoryPoolMXBean The memory pool MXBean to check.
* @return True if the pool name matches a known tenured pool name, false otherwise.
*/
static boolean isTenured(MemoryPoolMXBean memoryPoolMXBean) {
if (memoryPoolMXBean.getType() != MemoryType.HEAP) {
return false;
}
String name = memoryPoolMXBean.getName();
return name.equals("CMS Old Gen") // Sun Concurrent Mark Sweep GC
|| name.equals("PS Old Gen") // Sun Parallel GC
|| name.equals("G1 Old Gen") // Sun G1 GC
|| name.equals("Old Space") // BEA JRockit 1.5, 1.6 GC
|| name.equals("Tenured Gen") // Hitachi 1.5 GC
|| name.equals("Java heap") // IBM 1.5, 1.6 GC
|| name.equals("GenPauseless Old Gen") // azul C4/GPGC collector
// Allow an unknown pool name to monitor
|| (HEAP_POOL != null && name.equals(HEAP_POOL));
}
示例5: initCodeSizeLimits
import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
public static void initCodeSizeLimits(int nMaxSizeMemPoolCodeCache, int nMaxSizeMemPoolPermGen)
{
// PJD remove ibm JMV
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean p: pools)
{
if(p.getType().compareTo(MemoryType.NON_HEAP) == 0)
{
String cs = p.getName();
if(cs.equalsIgnoreCase("Code Cache"))
p.setUsageThreshold((long)nMaxSizeMemPoolCodeCache * 1024L * 1024L);
else if(cs.equalsIgnoreCase("Perm Gen"))
p.setUsageThreshold((long)nMaxSizeMemPoolPermGen * 1024L * 1024L);
}
}
}
示例6: setMemThreshold
import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
private void setMemThreshold()
{
m_bMaxPermanentHeap_MoSet = false;
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean p: pools)
{
if(p.getType().compareTo(MemoryType.HEAP) == 0)
{
String cs = p.getName();
if(cs.equalsIgnoreCase("Tenured gen"))
{
long l = 1024L * 1024L * (long)m_nMaxPermanentHeap_Mo;
p.setUsageThreshold(l);
m_tenuredPool = p;
}
}
}
}
示例7: poolSummaries
import java.lang.management.MemoryPoolMXBean; //導入方法依賴的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();
}
示例8: main
import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
public static void main(String[] args) {
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
boolean verified = false;
for (MemoryPoolMXBean i : pools) {
if ((i.getUsage().getMax() >= TWO_G)
&& i.isUsageThresholdSupported()) {
i.setUsageThreshold(TWO_G);
if(i.getUsageThreshold() != TWO_G)
throw new RuntimeException("Usage threshold for"
+ " pool '" + i.getName() + "' is " + i.getUsageThreshold()
+ " and not equal to 2GB");
verified = true;
}
}
System.out.println("Ability to use big heap thresholds has "
+ (verified ? "" : "NOT ") + "been verified");
}
示例9: JvmGcMetrics
import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
public JvmGcMetrics(Iterable<Tag> tags) {
for (MemoryPoolMXBean mbean : ManagementFactory.getMemoryPoolMXBeans()) {
if (isYoungGenPool(mbean.getName()))
youngGenPoolName = mbean.getName();
if (isOldGenPool(mbean.getName()))
oldGenPoolName = mbean.getName();
}
this.tags = tags;
}
示例10: getAllPoolNames
import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
synchronized String[] getAllPoolNames() {
if (poolNames == null) {
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
poolNames = new String[pools.size()];
int i = 0;
for (MemoryPoolMXBean m : pools) {
poolNames[i++] = m.getName();
}
}
return poolNames;
}
示例11: checkGcInfo
import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
private static void checkGcInfo(String name, GcInfo info) throws Exception {
System.out.println("GC statistic for : " + name);
System.out.print("GC #" + info.getId());
System.out.print(" start:" + info.getStartTime());
System.out.print(" end:" + info.getEndTime());
System.out.println(" (" + info.getDuration() + "ms)");
Map usage = info.getMemoryUsageBeforeGc();
List pnames = new ArrayList();
for (Iterator iter = usage.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry) iter.next();
String poolname = (String) entry.getKey();
pnames.add(poolname);
MemoryUsage busage = (MemoryUsage) entry.getValue();
MemoryUsage ausage = (MemoryUsage) info.getMemoryUsageAfterGc().get(poolname);
if (ausage == null) {
throw new RuntimeException("After Gc Memory does not exist" +
" for " + poolname);
}
System.out.println("Usage for pool " + poolname);
System.out.println(" Before GC: " + busage);
System.out.println(" After GC: " + ausage);
}
// check if memory usage for all memory pools are returned
List pools = ManagementFactory.getMemoryPoolMXBeans();
for (Iterator iter = pools.iterator(); iter.hasNext(); ) {
MemoryPoolMXBean p = (MemoryPoolMXBean) iter.next();
if (!pnames.contains(p.getName())) {
throw new RuntimeException("GcInfo does not contain " +
"memory usage for pool " + p.getName());
}
}
}
示例12: getAllPoolNames
import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
private synchronized String[] getAllPoolNames() {
if (poolNames == null) {
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
poolNames = new String[pools.size()];
int i = 0;
for (MemoryPoolMXBean m : pools) {
poolNames[i++] = m.getName();
}
}
return poolNames;
}
示例13: format
import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
String format(LogParams logParams, int n)
{
if(n == 0)
{
String csMessage = logParams.toString();
csMessage = logParams.toString();
StackTraceElement stackElem = logParams.m_caller;
String csOut;
if(stackElem != null)
{
String csFile = stackElem.getFileName();
int nLine = stackElem.getLineNumber();
csOut = csFile+"("+nLine+"):"+csMessage;
}
else
{
csOut = "():"+csMessage;
}
csOut += "\r\n******** Mem:";
int nMem = 0;
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean p: pools)
{
if(p.getType().compareTo(MemoryType.HEAP) == 0)
{
String cs = p.getName();
MemoryUsage mem = p.getUsage();
long l = mem.getUsed();
long lOldMem = m_mem[nMem];
long lOffset = l - lOldMem;
csOut += cs+"="+l+"["+lOffset+"];";
m_mem[nMem] = l;
nMem++;
}
}
csOut += "\r\n";
return csOut;
}
return null;
}
示例14: VMInfo
import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
private VMInfo() {
//初始化靜態信息
osMXBean = java.lang.management.ManagementFactory.getOperatingSystemMXBean();
runtimeMXBean = java.lang.management.ManagementFactory.getRuntimeMXBean();
garbageCollectorMXBeanList = java.lang.management.ManagementFactory.getGarbageCollectorMXBeans();
memoryPoolMXBeanList = java.lang.management.ManagementFactory.getMemoryPoolMXBeans();
osInfo = runtimeMXBean.getVmVendor() + " " + runtimeMXBean.getSpecVersion() + " " + runtimeMXBean.getVmVersion();
jvmInfo = osMXBean.getName() + " " + osMXBean.getArch() + " " + osMXBean.getVersion();
totalProcessorCount = osMXBean.getAvailableProcessors();
//構建startPhyOSStatus
startPhyOSStatus = new PhyOSStatus();
LOG.info("VMInfo# operatingSystem class => " + osMXBean.getClass().getName());
if (VMInfo.isSunOsMBean(osMXBean)) {
{
startPhyOSStatus.totalPhysicalMemory = VMInfo.getLongFromOperatingSystem(osMXBean, "getTotalPhysicalMemorySize");
startPhyOSStatus.freePhysicalMemory = VMInfo.getLongFromOperatingSystem(osMXBean, "getFreePhysicalMemorySize");
startPhyOSStatus.maxFileDescriptorCount = VMInfo.getLongFromOperatingSystem(osMXBean, "getMaxFileDescriptorCount");
startPhyOSStatus.currentOpenFileDescriptorCount = VMInfo.getLongFromOperatingSystem(osMXBean, "getOpenFileDescriptorCount");
}
}
//初始化processGCStatus;
for (GarbageCollectorMXBean garbage : garbageCollectorMXBeanList) {
GCStatus gcStatus = new GCStatus();
gcStatus.name = garbage.getName();
processGCStatus.gcStatusMap.put(garbage.getName(), gcStatus);
}
//初始化processMemoryStatus
if (memoryPoolMXBeanList != null && !memoryPoolMXBeanList.isEmpty()) {
for (MemoryPoolMXBean pool : memoryPoolMXBeanList) {
MemoryStatus memoryStatus = new MemoryStatus();
memoryStatus.name = pool.getName();
memoryStatus.initSize = pool.getUsage().getInit();
memoryStatus.maxSize = pool.getUsage().getMax();
processMomoryStatus.memoryStatusMap.put(pool.getName(), memoryStatus);
}
}
}
示例15: getDelta
import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
public synchronized void getDelta(boolean print) {
try {
if (VMInfo.isSunOsMBean(osMXBean)) {
long curUptime = runtimeMXBean.getUptime();
long curProcessTime = getLongFromOperatingSystem(osMXBean, "getProcessCpuTime");
//百分比, uptime是ms,processTime是nano
if ((curUptime > lastUpTime) && (curProcessTime >= lastProcessCpuTime)) {
float curDeltaCpu = (float) (curProcessTime - lastProcessCpuTime) / ((curUptime - lastUpTime) * totalProcessorCount * 10000);
processCpuStatus.setMaxMinCpu(curDeltaCpu);
processCpuStatus.averageCpu = (float) curProcessTime / (curUptime * totalProcessorCount * 10000);
lastUpTime = curUptime;
lastProcessCpuTime = curProcessTime;
}
}
for (GarbageCollectorMXBean garbage : garbageCollectorMXBeanList) {
GCStatus gcStatus = processGCStatus.gcStatusMap.get(garbage.getName());
if (gcStatus == null) {
gcStatus = new GCStatus();
gcStatus.name = garbage.getName();
processGCStatus.gcStatusMap.put(garbage.getName(), gcStatus);
}
long curTotalGcCount = garbage.getCollectionCount();
gcStatus.setCurTotalGcCount(curTotalGcCount);
long curtotalGcTime = garbage.getCollectionTime();
gcStatus.setCurTotalGcTime(curtotalGcTime);
}
if (memoryPoolMXBeanList != null && !memoryPoolMXBeanList.isEmpty()) {
for (MemoryPoolMXBean pool : memoryPoolMXBeanList) {
MemoryStatus memoryStatus = processMomoryStatus.memoryStatusMap.get(pool.getName());
if (memoryStatus == null) {
memoryStatus = new MemoryStatus();
memoryStatus.name = pool.getName();
processMomoryStatus.memoryStatusMap.put(pool.getName(), memoryStatus);
}
memoryStatus.commitedSize = pool.getUsage().getCommitted();
memoryStatus.setMaxMinUsedSize(pool.getUsage().getUsed());
long maxMemory = memoryStatus.commitedSize > 0 ? memoryStatus.commitedSize : memoryStatus.maxSize;
memoryStatus.setMaxMinPercent(maxMemory > 0 ? (float) 100 * memoryStatus.usedSize / maxMemory : -1);
}
}
if (print) {
LOG.info(processCpuStatus.getDeltaString() + processMomoryStatus.getDeltaString() + processGCStatus.getDeltaString());
}
} catch (Exception e) {
LOG.warn("no need care, the fail is ignored : vmInfo getDelta failed " + e.getMessage(), e);
}
}