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()
);
*/
}
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());
}
}
}
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;
}
}
}
}
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);
}
}
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;
}
Aggregations