Java Code Examples for java.lang.management.GarbageCollectorMXBean#getMemoryPoolNames()
The following examples show how to use
java.lang.management.GarbageCollectorMXBean#getMemoryPoolNames() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ManagementFactoryTest.java From banyan with MIT License | 6 votes |
public static void main(String[] args) { ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); List<GarbageCollectorMXBean> garbageCollectorMXBeanList = ManagementFactory.getGarbageCollectorMXBeans(); for (GarbageCollectorMXBean gcMXBean : garbageCollectorMXBeanList) { String gcName = gcMXBean.getName(); String memoryPoolNames[] = gcMXBean.getMemoryPoolNames(); for (String memoryPoolName : memoryPoolNames) { System.out.println(memoryPoolName); } ObjectName objectName = gcMXBean.getObjectName(); String domainName = objectName.getDomain(); System.out.println(domainName+"__"+objectName.getCanonicalName()); System.out.println(gcName); } //不需要获取同步的monitor 和 synchronize信息,仅获取线程和线程堆栈信息。 ThreadInfo[] allThreads = threadMXBean.dumpAllThreads(true, true); for (ThreadInfo threadInfo : allThreads) { String threadName = threadInfo.getThreadName(); long threadId = threadInfo.getThreadId(); System.out.println(threadName + "," + threadId + "," + threadInfo.getLockOwnerName()); } }
Example 2
Source File: RetainedHeapLimiter.java From bazel with Apache License 2.0 | 5 votes |
@VisibleForTesting static ImmutableList<NotificationEmitter> findTenuredCollectorBeans( List<GarbageCollectorMXBean> gcBeans) { ImmutableList.Builder<NotificationEmitter> builder = ImmutableList.builder(); // Examine all collectors and register for notifications from those which collect the tenured // space. Normally there is one such collector. for (GarbageCollectorMXBean gcBean : gcBeans) { for (String name : gcBean.getMemoryPoolNames()) { if (isTenuredSpace(name)) { builder.add((NotificationEmitter) gcBean); } } } return builder.build(); }
Example 3
Source File: GarbageCollectorMXBeanAttributeHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Override protected void executeReadAttribute(OperationContext context, ModelNode operation) throws OperationFailedException { final String gcName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue(); final String name = operation.require(ModelDescriptionConstants.NAME).asString(); GarbageCollectorMXBean gcMBean = null; for (GarbageCollectorMXBean mbean : ManagementFactory.getGarbageCollectorMXBeans()) { if (gcName.equals(escapeMBeanName(mbean.getName()))) { gcMBean = mbean; } } if (gcMBean == null) { throw PlatformMBeanLogger.ROOT_LOGGER.unknownGarbageCollector(gcName); } if (PlatformMBeanConstants.OBJECT_NAME.getName().equals(name)) { final String objName = PlatformMBeanUtil.getObjectNameStringWithNameKey(ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE, gcName); context.getResult().set(objName); } else if (ModelDescriptionConstants.NAME.equals(name)) { context.getResult().set(escapeMBeanName(gcMBean.getName())); } else if (PlatformMBeanConstants.VALID.getName().equals(name)) { context.getResult().set(gcMBean.isValid()); } else if (PlatformMBeanConstants.MEMORY_POOL_NAMES.equals(name)) { final ModelNode result = context.getResult(); result.setEmptyList(); for (String pool : gcMBean.getMemoryPoolNames()) { result.add(escapeMBeanName(pool)); } } else if (PlatformMBeanConstants.COLLECTION_COUNT.equals(name)) { context.getResult().set(gcMBean.getCollectionCount()); } else if (PlatformMBeanConstants.COLLECTION_TIME.equals(name)) { context.getResult().set(gcMBean.getCollectionTime()); } else if (GarbageCollectorResourceDefinition.GARBAGE_COLLECTOR_READ_ATTRIBUTES.contains(name) || GarbageCollectorResourceDefinition.GARBAGE_COLLECTOR_METRICS.contains(name)) { // Bug throw PlatformMBeanLogger.ROOT_LOGGER.badReadAttributeImpl(name); } else { // Shouldn't happen; the global handler should reject throw unknownAttribute(operation); } }
Example 4
Source File: MemoryMonitorTest.java From pitest with Apache License 2.0 | 4 votes |
@Test public void dumpMemoryInfo() { try { System.out.println("\nDUMPING MEMORY INFO\n"); // Read MemoryMXBean final MemoryMXBean memorymbean = ManagementFactory.getMemoryMXBean(); System.out.println("Heap Memory Usage: " + memorymbean.getHeapMemoryUsage()); System.out.println("Non-Heap Memory Usage: " + memorymbean.getNonHeapMemoryUsage()); // Read Garbage Collection information final List<GarbageCollectorMXBean> gcmbeans = ManagementFactory .getGarbageCollectorMXBeans(); for (final GarbageCollectorMXBean gcmbean : gcmbeans) { System.out.println("\nName: " + gcmbean.getName()); System.out.println("Collection count: " + gcmbean.getCollectionCount()); System.out.println("Collection time: " + gcmbean.getCollectionTime()); System.out.println("Memory Pools: "); final String[] memoryPoolNames = gcmbean.getMemoryPoolNames(); for (final String memoryPoolName : memoryPoolNames) { System.out.println("\t" + memoryPoolName); } } // Read Memory Pool Information System.out.println("Memory Pools Info"); final List<MemoryPoolMXBean> mempoolsmbeans = ManagementFactory .getMemoryPoolMXBeans(); for (final MemoryPoolMXBean mempoolmbean : mempoolsmbeans) { System.out.println("\nName: " + mempoolmbean.getName()); System.out.println("Usage: " + mempoolmbean.getUsage()); System.out.println("Collection Usage: " + mempoolmbean.getCollectionUsage()); System.out.println("Peak Usage: " + mempoolmbean.getPeakUsage()); System.out.println("Type: " + mempoolmbean.getType()); System.out.println("Memory Manager Names: "); final String[] memManagerNames = mempoolmbean.getMemoryManagerNames(); for (final String memManagerName : memManagerNames) { System.out.println("\t" + memManagerName); } System.out.println("\n"); } } catch (final Exception e) { e.printStackTrace(); } }