Search in sources :

Example 6 with PooledByteBufAllocatorMetric

use of io.netty.buffer.PooledByteBufAllocatorMetric in project jocean-http by isdom.

the class PooledAllocatorStats method getMetrics.

public Map<String, Object> getMetrics() {
    final PooledByteBufAllocatorMetric allocatorMetric = PooledByteBufAllocator.DEFAULT.metric();
    final Map<String, Object> metrics = new HashMap<>();
    {
        int idx = 0;
        for (PoolArenaMetric poolArenaMetric : allocatorMetric.directArenas()) {
            metrics.put("1_DirectArena[" + idx++ + "]", metricsOfPoolArena(poolArenaMetric));
        }
    }
    {
        int idx = 0;
        for (PoolArenaMetric poolArenaMetric : allocatorMetric.heapArenas()) {
            metrics.put("2_HeapArena[" + idx++ + "]", metricsOfPoolArena(poolArenaMetric));
        }
    }
    return metrics;
}
Also used : PoolArenaMetric(io.netty.buffer.PoolArenaMetric) HashMap(java.util.HashMap) PooledByteBufAllocatorMetric(io.netty.buffer.PooledByteBufAllocatorMetric)

Example 7 with PooledByteBufAllocatorMetric

use of io.netty.buffer.PooledByteBufAllocatorMetric in project ambry by linkedin.

the class NettyByteBufLeakHelper method beforeTest.

/**
 * Method to call at any method that is tagged {@link org.junit.Before} to collect some allocation stats.
 */
public void beforeTest() {
    if (cachedEnabled) {
        return;
    }
    PooledByteBufAllocatorMetric metric = PooledByteBufAllocator.DEFAULT.metric();
    List<PoolArenaMetric> heaps = metric.heapArenas();
    activeHeapAllocations = heaps.stream().mapToLong(PoolArenaMetric::numActiveAllocations).sum();
    heapAllocations = heaps.stream().mapToLong(PoolArenaMetric::numAllocations).sum();
    heapDeallocations = heaps.stream().mapToLong(PoolArenaMetric::numDeallocations).sum();
    List<PoolArenaMetric> directs = metric.directArenas();
    activeDirectAllocations = directs.stream().mapToLong(PoolArenaMetric::numActiveAllocations).sum();
    directAllocations = directs.stream().mapToLong(PoolArenaMetric::numAllocations).sum();
    directDeallocations = directs.stream().mapToLong(PoolArenaMetric::numDeallocations).sum();
}
Also used : PoolArenaMetric(io.netty.buffer.PoolArenaMetric) PooledByteBufAllocatorMetric(io.netty.buffer.PooledByteBufAllocatorMetric)

Aggregations

PooledByteBufAllocatorMetric (io.netty.buffer.PooledByteBufAllocatorMetric)7 PoolArenaMetric (io.netty.buffer.PoolArenaMetric)5 PooledByteBufAllocator (io.netty.buffer.PooledByteBufAllocator)2 Tags (io.micrometer.api.instrument.Tags)1 ByteBufAllocator (io.netty.buffer.ByteBufAllocator)1 ByteBufAllocatorMetric (io.netty.buffer.ByteBufAllocatorMetric)1 UnpooledByteBufAllocator (io.netty.buffer.UnpooledByteBufAllocator)1 Instant (java.time.Instant)1 HashMap (java.util.HashMap)1 NettyDataBufferFactory (org.springframework.core.io.buffer.NettyDataBufferFactory)1