Search in sources :

Example 1 with MemoryType

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()));
}
Also used : GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) ImmutableMap(com.google.common.collect.ImmutableMap) MemoryType(java.lang.management.MemoryType)

Example 2 with MemoryType

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());*/
}
Also used : CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) MemoryType(java.lang.management.MemoryType)

Example 3 with MemoryType

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;
}
Also used : StructImpl(lucee.runtime.type.StructImpl) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) MemoryUsage(java.lang.management.MemoryUsage) MemoryType(java.lang.management.MemoryType) Struct(lucee.runtime.type.Struct)

Example 4 with MemoryType

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;
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) Query(lucee.runtime.type.Query) Collection(lucee.runtime.type.Collection) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) MemoryUsage(java.lang.management.MemoryUsage) MemoryType(java.lang.management.MemoryType)

Example 5 with MemoryType

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;
}
Also used : StructImpl(lucee.runtime.type.StructImpl) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) MemoryUsage(java.lang.management.MemoryUsage) MemoryType(java.lang.management.MemoryType) Struct(lucee.runtime.type.Struct)

Aggregations

MemoryType (java.lang.management.MemoryType)5 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)4 MemoryUsage (java.lang.management.MemoryUsage)3 Struct (lucee.runtime.type.Struct)2 StructImpl (lucee.runtime.type.StructImpl)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)1 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)1 Collection (lucee.runtime.type.Collection)1 Query (lucee.runtime.type.Query)1 QueryImpl (lucee.runtime.type.QueryImpl)1