List of usage examples for io.netty.buffer PooledByteBufAllocatorMetric directArenas
public List<PoolArenaMetric> directArenas()
From source file:org.apache.spark.network.util.NettyMemoryMetrics.java
License:Apache License
private void registerMetrics(PooledByteBufAllocator allocator) { PooledByteBufAllocatorMetric pooledAllocatorMetric = allocator.metric(); // Register general metrics. allMetrics.put(MetricRegistry.name(metricPrefix, "usedHeapMemory"), (Gauge<Long>) () -> pooledAllocatorMetric.usedHeapMemory()); allMetrics.put(MetricRegistry.name(metricPrefix, "usedDirectMemory"), (Gauge<Long>) () -> pooledAllocatorMetric.usedDirectMemory()); if (verboseMetricsEnabled) { int directArenaIndex = 0; for (PoolArenaMetric metric : pooledAllocatorMetric.directArenas()) { registerArenaMetric(metric, "directArena" + directArenaIndex); directArenaIndex++;/*from w ww .j a va 2s. com*/ } int heapArenaIndex = 0; for (PoolArenaMetric metric : pooledAllocatorMetric.heapArenas()) { registerArenaMetric(metric, "heapArena" + heapArenaIndex); heapArenaIndex++; } } }
From source file:org.springframework.core.io.buffer.AbstractDataBufferAllocatingTests.java
License:Apache License
private void verifyAllocations() { if (this.bufferFactory instanceof NettyDataBufferFactory) { ByteBufAllocator allocator = ((NettyDataBufferFactory) this.bufferFactory).getByteBufAllocator(); if (allocator instanceof PooledByteBufAllocator) { Instant start = Instant.now(); while (true) { PooledByteBufAllocatorMetric metric = ((PooledByteBufAllocator) allocator).metric(); long total = getAllocations(metric.directArenas()) + getAllocations(metric.heapArenas()); if (total == 0) { return; }/*from w w w . j ava2 s . co m*/ if (Instant.now().isBefore(start.plus(Duration.ofSeconds(5)))) { try { Thread.sleep(50); } catch (InterruptedException ex) { // ignore } continue; } assertThat(total).as("ByteBuf Leak: " + total + " unreleased allocations").isEqualTo(0); } } } }
From source file:ratpack.dropwizard.metrics.internal.PooledByteBufAllocatorMetricSet.java
License:Apache License
private void initMetrics() { final PooledByteBufAllocatorMetric metric = pooledByteBufAllocator.metric(); metrics.put("numDirectArenas", (Gauge<Integer>) () -> metric.numDirectArenas()); metrics.put("numHeapArenas", (Gauge<Integer>) () -> metric.numHeapArenas()); metrics.put("numThreadLocalCaches", (Gauge<Integer>) () -> metric.numThreadLocalCaches()); metrics.put("smallCacheSize", (Gauge<Integer>) () -> metric.smallCacheSize()); metrics.put("tinyCacheSize", (Gauge<Integer>) () -> metric.tinyCacheSize()); metrics.put("normalCacheSize", (Gauge<Integer>) () -> metric.normalCacheSize()); metrics.put("chunkSize", (Gauge<Integer>) () -> metric.chunkSize()); metrics.put("usedDirectMemory", (Gauge<Long>) () -> metric.usedDirectMemory()); metrics.put("usedHeapMemory", (Gauge<Long>) () -> metric.usedHeapMemory()); if (includeArenas) { final Iterator<PoolArenaMetric> directArenasIterator = metric.directArenas().iterator(); initPoolArenaMetrics(directArenasIterator); final Iterator<PoolArenaMetric> heapArenasIterator = metric.heapArenas().iterator(); initPoolArenaMetrics(heapArenasIterator); }// w ww . j ava2s . c o m }