use of java.lang.management.MemoryType in project buck by facebook.
the class PerfStatsTracking method probeMemory.
public void probeMemory() {
long freeMemoryBytes = Runtime.getRuntime().freeMemory();
long totalMemoryBytes = Runtime.getRuntime().totalMemory();
long totalGcTimeMs = 0;
for (GarbageCollectorMXBean gcMxBean : ManagementFactory.getGarbageCollectorMXBeans()) {
long collectionTimeMs = gcMxBean.getCollectionTime();
if (collectionTimeMs == -1) {
// Gc collection time is not supported on this JVM.
totalGcTimeMs = -1;
break;
}
totalGcTimeMs += collectionTimeMs;
}
ImmutableMap.Builder<String, Long> currentMemoryBytesUsageByPool = ImmutableMap.builder();
for (MemoryPoolMXBean memoryPoolBean : ManagementFactory.getMemoryPoolMXBeans()) {
String name = memoryPoolBean.getName();
MemoryType type = memoryPoolBean.getType();
long currentlyUsedBytes = memoryPoolBean.getUsage().getUsed();
currentMemoryBytesUsageByPool.put(name + "(" + type + ")", currentlyUsedBytes);
}
eventBus.post(new MemoryPerfStatsEvent(freeMemoryBytes, totalMemoryBytes, totalGcTimeMs, currentMemoryBytesUsageByPool.build()));
}
use of java.lang.management.MemoryType in project Lucee by lucee.
the class MemoryNotificationListener method handleNotification.
@Override
public void handleNotification(Notification not, Object handback) {
if (not.getType().equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) {
CompositeDataSupport data = (CompositeDataSupport) not.getUserData();
String poolName = (String) data.get("poolName");
MemoryType type = types.get(poolName);
if (type == MemoryType.HEAP) {
// clear heap
aprint.e("Clear heap!");
} else if (type == MemoryType.NON_HEAP) {
// clear none-heap
((Config) handback).checkPermGenSpace(false);
}
/*CompositeDataSupport usage=(CompositeDataSupport) data.get("usage");
print.e(poolName);
print.e(types.get(poolName));
print.e(data.get("count"));
print.e(usage.get("committed"));
print.e(usage.get("init"));
print.e(usage.get("max"));
print.e(usage.get("used"));
long max=Caster.toLongValue(usage.get("max"),0);
long used=Caster.toLongValue(usage.get("used"),0);
long free=max-used;
print.o("m:"+max);
print.o("f:"+free);
print.o("%:"+(100L*used/max));
//not.*/
}
/*
javax.management.openmbean.CompositeDataSupport(
compositeType=javax.management.openmbean.CompositeType(
name=java.lang.management.MemoryUsage,
items=(
(itemName=committed,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),
(itemName=init,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),
(itemName=max,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),
(itemName=used,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)))),contents={committed=101580800, init=65404928, max=110362624, used=101085960})
javax.management.openmbean.CompositeDataSupport(
compositeType=javax.management.openmbean.CompositeType(
name=java.lang.management.MemoryNotificationInfo,
items=(
(itemName=count,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),
(itemName=poolName,itemType=javax.management.openmbean.SimpleType(name=java.lang.String)),
(itemName=usage,itemType=javax.management.openmbean.CompositeType(name=java.lang.management.MemoryUsage,items=((itemName=committed,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=init,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=max,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=used,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long))))))),contents={count=1, poolName=CMS Old Gen, usage=javax.management.openmbean.CompositeDataSupport(compositeType=javax.management.openmbean.CompositeType(name=java.lang.management.MemoryUsage,items=((itemName=committed,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=init,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=max,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=used,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)))),contents={committed=101580800, init=65404928, max=110362624, used=101085944})})
*/
/*
print.e(data.getCompositeType());
print.e(not.getSource().getClass().getName());
print.e(not.getSource());
ObjectName on=(ObjectName) not.getSource();
print.e(on.getKeyPropertyList());
*/
/*
print.e(not.getUserData().getClass().getName());
print.e(not.getUserData());
print.e(not.getMessage());
print.e(not.getSequenceNumber());
print.e(not.getTimeStamp());
print.e(not.getType());*/
}
use of java.lang.management.MemoryType in project Lucee by lucee.
the class MacAddressWrap method getMemoryUsageCompact.
public static Struct getMemoryUsageCompact(int type) {
java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
Iterator<MemoryPoolMXBean> it = manager.iterator();
MemoryPoolMXBean bean;
MemoryUsage usage;
MemoryType _type;
Struct sct = new StructImpl();
while (it.hasNext()) {
bean = it.next();
usage = bean.getUsage();
_type = bean.getType();
if (type == MEMORY_TYPE_HEAP && _type != MemoryType.HEAP)
continue;
if (type == MEMORY_TYPE_NON_HEAP && _type != MemoryType.NON_HEAP)
continue;
double d = ((int) (100D / usage.getMax() * usage.getUsed())) / 100D;
sct.setEL(KeyImpl.init(bean.getName()), Caster.toDouble(d));
}
return sct;
}
use of java.lang.management.MemoryType in project Lucee by lucee.
the class MacAddressWrap method getMemoryUsageAsQuery.
public static Query getMemoryUsageAsQuery(int type) throws DatabaseException {
java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
Iterator<MemoryPoolMXBean> it = manager.iterator();
Query qry = new QueryImpl(new Collection.Key[] { KeyConstants._name, KeyConstants._type, KeyConstants._used, KeyConstants._max, KeyConstants._init }, 0, "memory");
int row = 0;
MemoryPoolMXBean bean;
MemoryUsage usage;
MemoryType _type;
while (it.hasNext()) {
bean = it.next();
usage = bean.getUsage();
_type = bean.getType();
if (type == MEMORY_TYPE_HEAP && _type != MemoryType.HEAP)
continue;
if (type == MEMORY_TYPE_NON_HEAP && _type != MemoryType.NON_HEAP)
continue;
row++;
qry.addRow();
qry.setAtEL(KeyConstants._name, row, bean.getName());
qry.setAtEL(KeyConstants._type, row, _type.name());
qry.setAtEL(KeyConstants._max, row, Caster.toDouble(usage.getMax()));
qry.setAtEL(KeyConstants._used, row, Caster.toDouble(usage.getUsed()));
qry.setAtEL(KeyConstants._init, row, Caster.toDouble(usage.getInit()));
}
return qry;
}
use of java.lang.management.MemoryType in project Lucee by lucee.
the class MacAddressWrap method getMemoryUsageAsStruct.
public static Struct getMemoryUsageAsStruct(int type) {
java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
Iterator<MemoryPoolMXBean> it = manager.iterator();
MemoryPoolMXBean bean;
MemoryUsage usage;
MemoryType _type;
long used = 0, max = 0, init = 0;
while (it.hasNext()) {
bean = it.next();
usage = bean.getUsage();
_type = bean.getType();
if ((type == MEMORY_TYPE_HEAP && _type == MemoryType.HEAP) || (type == MEMORY_TYPE_NON_HEAP && _type == MemoryType.NON_HEAP)) {
used += usage.getUsed();
max += usage.getMax();
init += usage.getInit();
}
}
Struct sct = new StructImpl();
sct.setEL(KeyConstants._used, Caster.toDouble(used));
sct.setEL(KeyConstants._max, Caster.toDouble(max));
sct.setEL(KeyConstants._init, Caster.toDouble(init));
sct.setEL(KeyImpl.init("available"), Caster.toDouble(max - used));
return sct;
}
Aggregations