Extend metric utils
This commit is contained in:
parent
2fd311f67a
commit
9c167a322a
@ -1,8 +1,5 @@
|
|||||||
package io.netty5.buffer.api.pool;
|
package io.netty5.buffer.api.pool;
|
||||||
|
|
||||||
import io.netty5.buffer.api.pool.PoolArenaMetric;
|
|
||||||
import io.netty5.buffer.api.pool.PooledBufferAllocator;
|
|
||||||
import io.netty5.util.internal.ReflectionUtil;
|
|
||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
import java.lang.invoke.MethodHandles;
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.lang.invoke.MethodType;
|
import java.lang.invoke.MethodType;
|
||||||
@ -22,7 +19,7 @@ public class MetricUtils {
|
|||||||
MethodHandle handle = null;
|
MethodHandle handle = null;
|
||||||
try {
|
try {
|
||||||
// Find the class
|
// Find the class
|
||||||
var pooledBufferClass = Class.forName("io.netty5.buffer.api.pool.PooledBufferAllocatorMetric");
|
var pooledBufferClass = Class.forName("io.netty5.buffer.api.pool.PooledBufferAllocatorMetricUtils");
|
||||||
// Find the handle of the method
|
// Find the handle of the method
|
||||||
handle = lookup.findVirtual(pooledBufferClass, "arenaMetrics", MethodType.methodType(List.class));
|
handle = lookup.findVirtual(pooledBufferClass, "arenaMetrics", MethodType.methodType(List.class));
|
||||||
} catch (NoSuchMethodException | IllegalAccessException | ClassNotFoundException ignored) {
|
} catch (NoSuchMethodException | IllegalAccessException | ClassNotFoundException ignored) {
|
||||||
|
@ -0,0 +1,60 @@
|
|||||||
|
package io.netty5.buffer.api.pool;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PooledBufferAllocatorMetricUtils implements BufferAllocatorMetric {
|
||||||
|
|
||||||
|
private final PooledBufferAllocator allocator;
|
||||||
|
|
||||||
|
@SuppressWarnings("RedundantThrows")
|
||||||
|
public PooledBufferAllocatorMetricUtils(PooledBufferAllocator allocator) throws Throwable {
|
||||||
|
this.allocator = allocator;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the number of arenas.
|
||||||
|
*/
|
||||||
|
public int numArenas() {
|
||||||
|
return allocator.numArenas();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a {@link List} of all {@link PoolArenaMetric}s that are provided by this pool.
|
||||||
|
*/
|
||||||
|
public List<PoolArenaMetric> arenaMetrics() {
|
||||||
|
return allocator.arenaMetrics();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the number of thread local caches used by this {@link PooledBufferAllocator}.
|
||||||
|
*/
|
||||||
|
public int numThreadLocalCaches() {
|
||||||
|
return allocator.numThreadLocalCaches();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the size of the small cache.
|
||||||
|
*/
|
||||||
|
public int smallCacheSize() {
|
||||||
|
return allocator.smallCacheSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the size of the normal cache.
|
||||||
|
*/
|
||||||
|
public int normalCacheSize() {
|
||||||
|
return allocator.normalCacheSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the chunk size for an arena.
|
||||||
|
*/
|
||||||
|
public int chunkSize() {
|
||||||
|
return allocator.chunkSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long usedMemory() {
|
||||||
|
return allocator.usedMemory();
|
||||||
|
}
|
||||||
|
}
|
@ -2,40 +2,23 @@ package it.cavallium.dbengine.netty;
|
|||||||
|
|
||||||
import io.netty5.buffer.api.pool.BufferAllocatorMetric;
|
import io.netty5.buffer.api.pool.BufferAllocatorMetric;
|
||||||
import io.netty5.buffer.api.pool.PooledBufferAllocator;
|
import io.netty5.buffer.api.pool.PooledBufferAllocator;
|
||||||
|
import io.netty5.buffer.api.pool.PooledBufferAllocatorMetricUtils;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
public class JMXPooledNettyMonitoring extends JMXNettyMonitoring implements JMXNettyMonitoringMBean {
|
public class JMXPooledNettyMonitoring extends JMXNettyMonitoring implements JMXNettyMonitoringMBean {
|
||||||
|
|
||||||
private final PooledBufferAllocator alloc;
|
private final PooledBufferAllocator alloc;
|
||||||
private final BufferAllocatorMetric metric;
|
private final BufferAllocatorMetric metric;
|
||||||
private Field smallCacheSize;
|
private PooledBufferAllocatorMetricUtils metricUtils;
|
||||||
private Field numThreadLocalCaches;
|
|
||||||
private Field normalCacheSize;
|
|
||||||
private Field chunkSize;
|
|
||||||
|
|
||||||
public JMXPooledNettyMonitoring(String name, PooledBufferAllocator alloc) {
|
public JMXPooledNettyMonitoring(String name, PooledBufferAllocator alloc) {
|
||||||
super(name, alloc.isDirectBufferPooled(), alloc.metric());
|
super(name, alloc.isDirectBufferPooled(), alloc.metric());
|
||||||
this.alloc = alloc;
|
this.alloc = alloc;
|
||||||
this.metric = alloc.metric();
|
this.metric = alloc.metric();
|
||||||
try {
|
try {
|
||||||
//noinspection JavaReflectionMemberAccess
|
this.metricUtils = new PooledBufferAllocatorMetricUtils(alloc);
|
||||||
numThreadLocalCaches = metric.getClass().getDeclaredField("numThreadLocalCaches");
|
} catch (Throwable e) {
|
||||||
} catch (NoSuchFieldException e) {
|
this.metricUtils = null;
|
||||||
}
|
|
||||||
try {
|
|
||||||
//noinspection JavaReflectionMemberAccess
|
|
||||||
smallCacheSize = metric.getClass().getDeclaredField("smallCacheSize");
|
|
||||||
} catch (NoSuchFieldException e) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
//noinspection JavaReflectionMemberAccess
|
|
||||||
normalCacheSize = metric.getClass().getDeclaredField("normalCacheSize");
|
|
||||||
} catch (NoSuchFieldException e) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
//noinspection JavaReflectionMemberAccess
|
|
||||||
chunkSize = metric.getClass().getDeclaredField("chunkSize");
|
|
||||||
} catch (NoSuchFieldException e) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,11 +34,7 @@ public class JMXPooledNettyMonitoring extends JMXNettyMonitoring implements JMXN
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer getNumThreadLocalCachesArenas() {
|
public Integer getNumThreadLocalCachesArenas() {
|
||||||
try {
|
return metricUtils != null ? metricUtils.numThreadLocalCaches() : 0;
|
||||||
return numThreadLocalCaches.getInt(metric);
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@ -66,28 +45,16 @@ public class JMXPooledNettyMonitoring extends JMXNettyMonitoring implements JMXN
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer getSmallCacheSize() {
|
public Integer getSmallCacheSize() {
|
||||||
try {
|
return metricUtils != null ? metricUtils.smallCacheSize() : 0;
|
||||||
return smallCacheSize.getInt(metric);
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer getNormalCacheSize() {
|
public Integer getNormalCacheSize() {
|
||||||
try {
|
return metricUtils != null ? metricUtils.normalCacheSize() : 0;
|
||||||
return normalCacheSize.getInt(metric);
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer getChunkSize() {
|
public Integer getChunkSize() {
|
||||||
try {
|
return metricUtils != null ? metricUtils.chunkSize() : 0;
|
||||||
return chunkSize.getInt(metric);
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user