Class SizeOfTool


  • public class SizeOfTool
    extends java.lang.Object
    Toolbox to manage size of objects,
    • Constructor Detail

      • SizeOfTool

        public SizeOfTool()
    • Method Detail

      • getMetrics

        public static java.util.List<SizeOfTool.CacheMetric> getMetrics​(com.simplicite.util.engine.MemoryCache cache,
                                                                        long limit,
                                                                        boolean fast,
                                                                        java.util.List<SizeOfTool.CacheMetric> result)
        Overview of object cache in memory
        Parameters:
        limit - limit return size (0=no limit)
        fast - use serialization method, faster than fields reflection/inspection
        Returns:
        list of memory approximation sorted by sizes
      • getObjectSize

        public static long getObjectSize​(java.lang.Object o,
                                         boolean fast)

        Get the memory used by the object

        Parameters:
        o - Any object
        fast - based on serialization (fast approximation) or reflection (slower)
        Returns:
        memory size (Bytes)
      • getObjectMetrics

        public static java.util.List<SizeOfTool.CacheMetric> getObjectMetrics​(long limit,
                                                                              boolean fast)
      • getProcessMetrics

        public static java.util.List<SizeOfTool.CacheMetric> getProcessMetrics​(long limit,
                                                                               boolean fast)
      • sizeOf

        public static long sizeOf​(java.io.Serializable o)

        Get the size of the serialized object (fast approximation of object size)

        Returns:
        memory size approximation (Bytes), based on serialized objects
      • sizeOf

        public static long sizeOf​(java.lang.Object obj,
                                  boolean deep)
        Object size approximation (slow)
        Parameters:
        obj - Any object
        deep - Deep count
        Returns:
        Size approximation based on fields reflection
      • sizeOf

        public static long sizeOf​(java.lang.Object obj,
                                  boolean deep,
                                  boolean trace)
        Object size approximation
        Parameters:
        obj - Any object
        deep - Deep count
        trace - Log object structure
        Returns:
        Size approximation based on fields reflection
      • roundUp

        public static long roundUp​(long size,
                                   int round)
      • getPrimitiveFieldSize

        public static int getPrimitiveFieldSize​(java.lang.Class<?> c)