Add PooledByteBufAllocator.dumpStats() which allows to obtain a human-readable status of the allocator.
Motiviation: Sometimes it is useful to dump the status of the PooledByteBufAllocator and log it. Doing this is currently a bit cumbersome as the user needs to basically iterate through all the metrics and compose the String. we would better provide an easy way to do this. Modification: Add dumpStats() method. Result: Easier to get a view into the status of the allocator.
This commit is contained in:
parent
bfdfb50df6
commit
856d6b9402
@ -18,6 +18,7 @@ package io.netty.buffer;
|
|||||||
|
|
||||||
import io.netty.util.concurrent.FastThreadLocal;
|
import io.netty.util.concurrent.FastThreadLocal;
|
||||||
import io.netty.util.internal.PlatformDependent;
|
import io.netty.util.internal.PlatformDependent;
|
||||||
|
import io.netty.util.internal.StringUtil;
|
||||||
import io.netty.util.internal.SystemPropertyUtil;
|
import io.netty.util.internal.SystemPropertyUtil;
|
||||||
import io.netty.util.internal.logging.InternalLogger;
|
import io.netty.util.internal.logging.InternalLogger;
|
||||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||||
@ -454,31 +455,33 @@ public class PooledByteBufAllocator extends AbstractByteBufAllocator {
|
|||||||
return threadCache.get();
|
return threadCache.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Too noisy at the moment.
|
/**
|
||||||
//
|
* Returns the status of the allocator (which contains all metrics) as string. Be aware this may be expensive
|
||||||
//public String toString() {
|
* and so should not called too frequently.
|
||||||
// StringBuilder buf = new StringBuilder();
|
*/
|
||||||
// int heapArenasLen = heapArenas == null ? 0 : heapArenas.length;
|
public String dumpStats() {
|
||||||
// buf.append(heapArenasLen);
|
int heapArenasLen = heapArenas == null ? 0 : heapArenas.length;
|
||||||
// buf.append(" heap arena(s):");
|
StringBuilder buf = new StringBuilder(512)
|
||||||
// buf.append(StringUtil.NEWLINE);
|
.append(heapArenasLen)
|
||||||
// if (heapArenasLen > 0) {
|
.append(" heap arena(s):")
|
||||||
// for (PoolArena<byte[]> a: heapArenas) {
|
.append(StringUtil.NEWLINE);
|
||||||
// buf.append(a);
|
if (heapArenasLen > 0) {
|
||||||
// }
|
for (PoolArena<byte[]> a: heapArenas) {
|
||||||
// }
|
buf.append(a);
|
||||||
//
|
}
|
||||||
// int directArenasLen = directArenas == null ? 0 : directArenas.length;
|
}
|
||||||
//
|
|
||||||
// buf.append(directArenasLen);
|
int directArenasLen = directArenas == null ? 0 : directArenas.length;
|
||||||
// buf.append(" direct arena(s):");
|
|
||||||
// buf.append(StringUtil.NEWLINE);
|
buf.append(directArenasLen)
|
||||||
// if (directArenasLen > 0) {
|
.append(" direct arena(s):")
|
||||||
// for (PoolArena<ByteBuffer> a: directArenas) {
|
.append(StringUtil.NEWLINE);
|
||||||
// buf.append(a);
|
if (directArenasLen > 0) {
|
||||||
// }
|
for (PoolArena<ByteBuffer> a: directArenas) {
|
||||||
// }
|
buf.append(a);
|
||||||
//
|
}
|
||||||
// return buf.toString();
|
}
|
||||||
//}
|
|
||||||
|
return buf.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user