/** * Returns a list of {@link MemoryPoolMXBean} objects in the Java virtual machine. The Java virtual machine can have one or more memory pools. It may add or remove memory pools during execution. * * @return a list of <tt>MemoryPoolMXBean</tt> objects. * */ public static List<MemoryPoolMXBean> getMemoryPoolMXBeans() { return ManagementFactory.getMemoryPoolMXBeans(); }
/** * Returns a list of {@link MemoryPoolMXBean} objects in the Java virtual machine. The Java virtual machine can have one or more memory pools. It may add or remove memory pools during execution. * * @return a list of <tt>MemoryPoolMXBean</tt> objects. * */ public static List<MemoryPoolMXBean> getMemoryPoolMXBeans() { return ManagementFactory.getMemoryPoolMXBeans(); }
@Override public List<MemoryPoolMXBean> run() throws Exception { return ManagementFactory.getMemoryPoolMXBeans(); } });
public static List<MemoryPoolMXBean> getMemoryPools() { List<MemoryPoolMXBean> mPools = ManagementFactory.getMemoryPoolMXBeans(); return mPools; }
private static MemoryPoolMXBean getPermGenMemoryPool() { for (final MemoryPoolMXBean memoryPool : ManagementFactory.getMemoryPoolMXBeans()) { // name est "Perm Gen" ou "PS Perm Gen" (32 vs 64 bits ?) if (memoryPool.getName().endsWith("Perm Gen")) { return memoryPool; } } return null; }
public MemoryUsageMonitor() { List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans(); heap = new MemoryGroup(pools, MemoryType.HEAP); nonHeap = new MemoryGroup(pools, MemoryType.NON_HEAP); }
public JVMMemory() { memoryMXBean = ManagementFactory.getMemoryMXBean(); List<MemoryPoolMXBean> list = ManagementFactory.getMemoryPoolMXBeans(); for (MemoryPoolMXBean item : list) { String name = item.getName(); if (permGenName.contains(name)) { permGenMxBean = item; } else if (oldGenName.contains(name)) { oldGenMxBean = item; } else if (edenSpaceName.contains(name)) { edenSpaceMxBean = item; } else if (psSurvivorName.contains(name)) { pSSurvivorSpaceMxBean = item; } } }
public MultiDetailsHandler memoryPool() { return new MultiDetailsHandler("Memory pool", ManagementFactory.getMemoryPoolMXBeans(), "name", "type", "memoryManagerNames", "usage", "peakUsage", "collectionUsage"); }
@Override public Map<String, Object> asJson() { LinkedHashMap<String, Object> json = new LinkedHashMap<>(); List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans(); for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) { Map<String, Object> params = formatInJson(memoryPoolMXBean.getUsage()); params.put("Type", memoryPoolMXBean.getType()); json.put(memoryPoolMXBean.getName(), params); } return json; }
public static void memDetails() { List<MemoryPoolMXBean> mems = ManagementFactory.getMemoryPoolMXBeans(); for (final MemoryPoolMXBean mx : mems) { Metrics.measure(mx.getName() + " (MB)", (Callable<Double>) () -> mx.getUsage().getUsed() / 1024.0 / 1024.0); } }
/** * Returns the names of all available memory pools as a single string. */ private static String getAllMemoryPoolNames() { StringBuilder builder = new StringBuilder("["); for (MemoryPoolMXBean memoryPoolBean : ManagementFactory.getMemoryPoolMXBeans()) { builder.append("(Name=").append(memoryPoolBean.getName()).append(";Type=") .append(memoryPoolBean.getType()).append(";UsageThresholdSupported=") .append(memoryPoolBean.isUsageThresholdSupported()).append("), "); } if (builder.length() > 1) { builder.setLength(builder.length() - 2); } builder.append("]"); return builder.toString(); }
private static MemoryPoolMXBean findPool() { MemoryPoolMXBean ret = null; for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) { if (pool.getType() == MemoryType.HEAP && pool.isUsageThresholdSupported()) { ret = pool; } } // we do something when we reached 99.9% of memory usage // when we get to this point gc was unable to recover memory. ret.setCollectionUsageThreshold((long) Math.floor(ret.getUsage().getMax() * 0.999)); return (ret); }
/** * 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(); } }
public static long getTotalHeapSize() { // runtime.getMax() gives a very different number from the actual Xmx sizing. // you can iterate through the // http://docs.oracle.com/javase/7/docs/api/java/lang/management/MemoryPoolMXBean.html // from java.lang.management to figure this out, but the hard-coded params in the llap run.sh // result in 89% usable heap (-XX:NewRatio=8) + a survivor region which is technically not // in the usable space. long total = 0; for (MemoryPoolMXBean mp : ManagementFactory.getMemoryPoolMXBeans()) { long sz = mp.getUsage().getMax(); if (mp.getName().contains("Survivor")) { sz *= 2; // there are 2 survivor spaces } if (mp.getType().equals(MemoryType.HEAP)) { total += sz; } } // round up to the next MB total += (total % (1024*1024)); return total; }
private void initMemoryPools() { List<MemoryPoolMXBean> l = ManagementFactory.getMemoryPoolMXBeans(); for (MemoryPoolMXBean item : l) { if (item.isValid() && !mpMap.containsKey(item)) { mpMap.put(item, this.f.createStatistics(mpType, item.getName() + '-' + item.getType(), this.id)); } } }
@Override void dump( Logger logger ) { logger.log( "Free memory: " + bytes( Runtime.getRuntime().freeMemory() ) ); logger.log( "Total memory: " + bytes( Runtime.getRuntime().totalMemory() ) ); logger.log( "Max memory: " + bytes( Runtime.getRuntime().maxMemory() ) ); for ( GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans() ) { logger.log( "Garbage Collector: " + gc.getName() + ": " + Arrays.toString( gc.getMemoryPoolNames() ) ); } for ( MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans() ) { MemoryUsage usage = pool.getUsage(); logger.log( String.format( "Memory Pool: %s (%s): committed=%s, used=%s, max=%s, threshold=%s", pool.getName(), pool.getType(), usage == null ? "?" : bytes( usage.getCommitted() ), usage == null ? "?" : bytes( usage.getUsed() ), usage == null ? "?" : bytes( usage.getMax() ), pool.isUsageThresholdSupported() ? bytes( pool.getUsageThreshold() ) : "?" ) ); } } },
private void setupTenuredGenPoolThreshold(final MemoryPoolMXBean tenuredGenPool) { if (tenuredGenPool == null) { return; } for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) { final long memoryThreshold = (int) Math.floor(pool.getUsage().getMax() * threshold); final boolean isTenured = isTenured(pool); if (!isTenured) { continue; } // set memory threshold on memory used after GC final boolean isCollectionUsageThresholdSupported = pool.isCollectionUsageThresholdSupported(); if (isCollectionUsageThresholdSupported) { LOG.info("Setting collection usage threshold to {}", memoryThreshold); pool.setCollectionUsageThreshold(memoryThreshold); return; } else { // if collection usage threshold is not support, worst case set memory threshold on memory usage (before GC) final boolean isUsageThresholdSupported = pool.isUsageThresholdSupported(); if (isUsageThresholdSupported) { LOG.info("Setting usage threshold to {}", memoryThreshold); pool.setUsageThreshold(memoryThreshold); return; } } } }
private static MemoryPoolMXBean getTenuredGenPool() { for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) { final String vendor = System.getProperty("java.vendor"); final boolean isTenured = isTenured(pool); if (!isTenured) { continue; } final boolean isCollectionUsageThresholdSupported = pool.isCollectionUsageThresholdSupported(); if (isCollectionUsageThresholdSupported) { return pool; } else { final boolean isUsageThresholdSupported = pool.isUsageThresholdSupported(); if (isUsageThresholdSupported) { return pool; } else { LOG.error("{} vendor does not support isCollectionUsageThresholdSupported() and isUsageThresholdSupported()" + " for tenured memory pool '{}'.", vendor, pool.getName()); } } } return null; }
private void addMemoryPoolMetrics(long timestamp, MetricList metrics) { final List<MemoryPoolMXBean> beans = ManagementFactory.getMemoryPoolMXBeans(); for (MemoryPoolMXBean bean : beans) { final TagList tags = BasicTagList.of("id", bean.getName(), "memtype", bean.getType().name()); addMemoryUsageMetrics(tags, timestamp, bean.getUsage(), metrics); } }
for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) { final String kind = pool.getType() == MemoryType.HEAP ? "heap" : "nonheap"; final MemoryUsage usage = pool.getUsage();