Expose the global direct memory counter. (#8945)

Motivation:
This counter is very useful in order to monitor Netty without having every ByteBufAllocator in the JVM

Modification:
Expose the value of DIRECT_MEMORY_COUNTER as we are already doing for DIRECT_MEMORY_LIMIT.
We are returning -1 in case that DIRECT_MEMORY_COUNTER is not available.

Result:

Be able to get the amount of direct memory used.
This commit is contained in:
Enrico Olivelli 2019-03-19 08:34:35 +01:00 committed by Norman Maurer
parent 21cb040aef
commit ac23f2485e

View File

@ -263,6 +263,16 @@ public final class PlatformDependent {
return DIRECT_MEMORY_LIMIT;
}
/**
* Returns the current memory reserved for direct buffer allocation.
* This method returns -1 in case that a value is not available.
*
* @see #maxDirectMemory()
*/
public static long usedDirectMemory() {
return DIRECT_MEMORY_COUNTER != null ? DIRECT_MEMORY_COUNTER.get() : -1;
}
/**
* Returns the temporary directory.
*/