Only increment metric for huge / normal allocations after the allocation was really done.

Motivation:

We should only increment the metric for the huge / normal allocation after it is done. Also we should only decrement once deallocate.

Modifications:

- Move increment after the allocation.
- Fix deallocation metric and move it after deallocation

Result:

More correct metrics.
This commit is contained in:
Norman Maurer 2016-04-05 11:46:25 +02:00
parent b32e07c75a
commit 1d23e358b4

View File

@ -223,30 +223,31 @@ abstract class PoolArena<T> implements PoolArenaMetric {
} }
private synchronized void allocateNormal(PooledByteBuf<T> buf, int reqCapacity, int normCapacity) { private synchronized void allocateNormal(PooledByteBuf<T> buf, int reqCapacity, int normCapacity) {
++allocationsNormal;
if (q050.allocate(buf, reqCapacity, normCapacity) || q025.allocate(buf, reqCapacity, normCapacity) || if (q050.allocate(buf, reqCapacity, normCapacity) || q025.allocate(buf, reqCapacity, normCapacity) ||
q000.allocate(buf, reqCapacity, normCapacity) || qInit.allocate(buf, reqCapacity, normCapacity) || q000.allocate(buf, reqCapacity, normCapacity) || qInit.allocate(buf, reqCapacity, normCapacity) ||
q075.allocate(buf, reqCapacity, normCapacity) || q100.allocate(buf, reqCapacity, normCapacity)) { q075.allocate(buf, reqCapacity, normCapacity) || q100.allocate(buf, reqCapacity, normCapacity)) {
++allocationsNormal;
return; return;
} }
// Add a new chunk. // Add a new chunk.
PoolChunk<T> c = newChunk(pageSize, maxOrder, pageShifts, chunkSize); PoolChunk<T> c = newChunk(pageSize, maxOrder, pageShifts, chunkSize);
long handle = c.allocate(normCapacity); long handle = c.allocate(normCapacity);
++allocationsNormal;
assert handle > 0; assert handle > 0;
c.initBuf(buf, handle, reqCapacity); c.initBuf(buf, handle, reqCapacity);
qInit.add(c); qInit.add(c);
} }
private void allocateHuge(PooledByteBuf<T> buf, int reqCapacity) { private void allocateHuge(PooledByteBuf<T> buf, int reqCapacity) {
allocationsHuge.increment();
buf.initUnpooled(newUnpooledChunk(reqCapacity), reqCapacity); buf.initUnpooled(newUnpooledChunk(reqCapacity), reqCapacity);
allocationsHuge.increment();
} }
void free(PoolChunk<T> chunk, long handle, int normCapacity, PoolThreadCache cache) { void free(PoolChunk<T> chunk, long handle, int normCapacity, PoolThreadCache cache) {
if (chunk.unpooled) { if (chunk.unpooled) {
allocationsHuge.decrement();
destroyChunk(chunk); destroyChunk(chunk);
deallocationsHuge.decrement();
} else { } else {
SizeClass sizeClass = sizeClass(normCapacity); SizeClass sizeClass = sizeClass(normCapacity);
if (cache != null && cache.add(this, chunk, handle, normCapacity, sizeClass)) { if (cache != null && cache.add(this, chunk, handle, normCapacity, sizeClass)) {