Search in sources :

Example 6 with MemoryPoolMXBean

use of java.lang.management.MemoryPoolMXBean in project adempiere by adempiere.

the class MSystem method info.

//	getDBInfoSQL
/**
	 * 	Print info
	 */
public void info() {
    if (!CLogMgt.isLevelFine())
        return;
    //	OS
    //	OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
    //	log.fine(os.getName() + " " + os.getVersion() + " " + os.getArch() 
    //		+ " Processors=" + os.getAvailableProcessors());
    //	Runtime
    RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean();
    //	Memory
    if (CLogMgt.isLevelFiner()) {
        List<MemoryPoolMXBean> list = ManagementFactory.getMemoryPoolMXBeans();
        Iterator<MemoryPoolMXBean> it = list.iterator();
        while (it.hasNext()) {
            MemoryPoolMXBean pool = (MemoryPoolMXBean) it.next();
        /*
				log.finer(pool.getName() + " " + pool.getType() 
					+ ": " + new CMemoryUsage(pool.getUsage()));
				*/
        }
    } else {
        MemoryMXBean memory = ManagementFactory.getMemoryMXBean();
    // log.fine("VM: " + new CMemoryUsage(memory.getNonHeapMemoryUsage()));
    // log.fine("Heap: " + new CMemoryUsage(memory.getHeapMemoryUsage()));
    }
    //	Thread
    ThreadMXBean th = ManagementFactory.getThreadMXBean();
/*
		log.fine("Threads=" + th.getThreadCount()
			+ ", Peak=" + th.getPeakThreadCount()
			+ ", Demons=" + th.getDaemonThreadCount()
			+ ", Total=" + th.getTotalStartedThreadCount()
		);
		*/
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) MemoryMXBean(java.lang.management.MemoryMXBean) RuntimeMXBean(java.lang.management.RuntimeMXBean) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean)

Example 7 with MemoryPoolMXBean

use of java.lang.management.MemoryPoolMXBean in project geode by apache.

the class MemoryMonitorJUnitTest method testCriticalHeapThreshold.

@Test
public void testCriticalHeapThreshold() throws Exception {
    final int toohigh = 101;
    final int toolow = -1;
    final float disabled = 0.0f;
    final float justright = 92.5f;
    final ResourceManager rm = this.cache.getResourceManager();
    long usageThreshold = -1;
    int once = 0;
    for (MemoryPoolMXBean p : ManagementFactory.getMemoryPoolMXBeans()) {
        if (p.isUsageThresholdSupported() && HeapMemoryMonitor.isTenured(p)) {
            usageThreshold = p.getUsageThreshold();
            once++;
        }
    }
    assertEquals("Expected only one pool to be assigned", 1, once);
    // Default test, current default is disabled
    assertEquals(rm.getCriticalHeapPercentage(), MemoryThresholds.DEFAULT_CRITICAL_PERCENTAGE, 0.01);
    NotificationEmitter emitter = (NotificationEmitter) ManagementFactory.getMemoryMXBean();
    try {
        emitter.removeNotificationListener(InternalResourceManager.getInternalResourceManager(cache).getHeapMonitor());
        assertTrue("Expected that the resource manager was not registered", false);
    } catch (ListenerNotFoundException expected) {
    }
    try {
        rm.setCriticalHeapPercentage(toohigh);
        assertTrue("Expected illegal argument exception for value " + toohigh, false);
    } catch (IllegalArgumentException toohi) {
    }
    try {
        rm.setCriticalHeapPercentage(toolow);
        assertTrue("Expected illegal argument exception for value " + toolow, false);
    } catch (IllegalArgumentException toohi) {
    }
    rm.setCriticalHeapPercentage(justright);
    emitter = (NotificationEmitter) ManagementFactory.getMemoryMXBean();
    {
        InternalResourceManager irm = InternalResourceManager.getInternalResourceManager(cache);
        HeapMemoryMonitor hmm = irm.getHeapMonitor();
        // Expect no exception for removal (it was installed during set)
        hmm.stopMonitoring();
    }
    assertEquals(rm.getCriticalHeapPercentage(), justright, 0.01);
    rm.setCriticalHeapPercentage(disabled);
    assertEquals(rm.getCriticalHeapPercentage(), disabled, 0.01);
    emitter = (NotificationEmitter) ManagementFactory.getMemoryMXBean();
    try {
        emitter.removeNotificationListener(InternalResourceManager.getInternalResourceManager(cache).getHeapMonitor());
        assertTrue("Expected that the resource manager was not registered", false);
    } catch (ListenerNotFoundException expected) {
    }
    // Assert the threshold was reset
    for (MemoryPoolMXBean p : ManagementFactory.getMemoryPoolMXBeans()) {
        if (HeapMemoryMonitor.isTenured(p)) {
            assertEquals(usageThreshold, p.getUsageThreshold());
        }
    }
}
Also used : NotificationEmitter(javax.management.NotificationEmitter) ListenerNotFoundException(javax.management.ListenerNotFoundException) ResourceManager(org.apache.geode.cache.control.ResourceManager) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 8 with MemoryPoolMXBean

use of java.lang.management.MemoryPoolMXBean in project intellij-community by JetBrains.

the class PerformanceWatcher method initComponent.

@Override
public void initComponent() {
    if (shouldWatch()) {
        final AppScheduledExecutorService service = (AppScheduledExecutorService) AppExecutorUtil.getAppScheduledExecutorService();
        service.setNewThreadListener(new Consumer<Thread>() {

            private final int ourReasonableThreadPoolSize = Registry.intValue("core.pooled.threads");

            @Override
            public void consume(Thread thread) {
                if (service.getBackendPoolExecutorSize() > ourReasonableThreadPoolSize && ApplicationInfoImpl.getShadowInstance().isEAP()) {
                    File file = dumpThreads("newPooledThread/", true);
                    LOG.info("Not enough pooled threads" + (file != null ? "; dumped threads into file '" + file.getPath() + "'" : ""));
                }
            }
        });
        ApplicationManager.getApplication().executeOnPooledThread(() -> cleanOldFiles(myLogDir, 0));
        for (MemoryPoolMXBean bean : ManagementFactory.getMemoryPoolMXBeans()) {
            if ("Code Cache".equals(bean.getName())) {
                watchCodeCache(bean);
                break;
            }
        }
    }
}
Also used : AppScheduledExecutorService(com.intellij.util.concurrency.AppScheduledExecutorService) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) File(java.io.File)

Example 9 with MemoryPoolMXBean

use of java.lang.management.MemoryPoolMXBean in project gephi by gephi.

the class MemoryStarvationManager method startup.

public void startup() {
    ((NotificationEmitter) ManagementFactory.getMemoryMXBean()).addNotificationListener(this, null, null);
    List<MemoryPoolMXBean> mpbeans = ManagementFactory.getMemoryPoolMXBeans();
    MemoryPoolMXBean biggestHeap = null;
    long biggestSize = 0;
    for (MemoryPoolMXBean b : mpbeans) {
        if (b.getType() == MemoryType.HEAP) {
            /* Here we are making the leap of faith that the biggest
                 * heap is the tenured heap
                 */
            long size = b.getUsage().getMax();
            if (size > biggestSize) {
                biggestSize = size;
                biggestHeap = b;
            }
        }
    }
    if (biggestHeap != null) {
        long usageThreshold = (long) (biggestSize - reservedMemory);
        biggestHeap.setUsageThreshold(usageThreshold);
        biggestHeap.setCollectionUsageThreshold(usageThreshold);
    }
}
Also used : NotificationEmitter(javax.management.NotificationEmitter) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean)

Example 10 with MemoryPoolMXBean

use of java.lang.management.MemoryPoolMXBean in project uavstack by uavorg.

the class JVMToolHelper method readHeapPoolUsage.

public static Map<String, Long> readHeapPoolUsage(List<MemoryPoolMXBean> pmbList) {
    Map<String, Long> m = new LinkedHashMap<String, Long>();
    for (MemoryPoolMXBean mpmb : pmbList) {
        String jvmMemPoolName = getHeapPoolName(mpmb.getName().trim());
        MemoryUsage mu = mpmb.getUsage();
        m.put(jvmMemPoolName + "_use", mu.getUsed());
        m.put(jvmMemPoolName + "_commit", mu.getCommitted());
        m.put(jvmMemPoolName + "_max", mu.getMax());
        m.put(jvmMemPoolName + "_init", mu.getInit());
    }
    return m;
}
Also used : MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) MemoryUsage(java.lang.management.MemoryUsage) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)107 MemoryUsage (java.lang.management.MemoryUsage)43 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)16 ArrayList (java.util.ArrayList)14 Test (org.testng.annotations.Test)11 MemoryMXBean (java.lang.management.MemoryMXBean)10 InstanceNotFoundException (javax.management.InstanceNotFoundException)9 ReflectionException (javax.management.ReflectionException)9 NotificationEmitter (javax.management.NotificationEmitter)8 MemoryType (java.lang.management.MemoryType)7 HashMap (java.util.HashMap)7 AttributeNotFoundException (javax.management.AttributeNotFoundException)7 IntrospectionException (javax.management.IntrospectionException)7 MBeanException (javax.management.MBeanException)7 Map (java.util.Map)6 Attribute (javax.management.Attribute)6 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)6 VisibleForTesting (com.google.common.annotations.VisibleForTesting)5 ThreadMXBean (java.lang.management.ThreadMXBean)5 Test (org.junit.Test)5