Package adams.core

Class SizeOf


  • public class SizeOf
    extends Object
    Helper class for measuring the size of objects using Maxim Zakharenkov's SizeOf agent or simply the length of the byte array generated by serialization.
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    • Field Detail

      • METHOD_FULLSIZEPERCLASS

        public static final String METHOD_FULLSIZEPERCLASS
        the method to use (per class).
        See Also:
        Constant Field Values
      • m_Available

        protected static Boolean m_Available
        whether the SizeOf agent is available.
      • m_Class

        protected static Class m_Class
        the SizeOf agent class.
      • m_FullSizeOf

        protected static Method m_FullSizeOf
        the SizeOf agent method to use.
      • m_FullSizeOfFilter

        protected static Method m_FullSizeOfFilter
        the SizeOf agent method to use (with filter).
      • m_FullSizePerClass

        protected static Method m_FullSizePerClass
        the SizeOf agent method to use (per class).
      • m_FullSizePerClassFilter

        protected static Method m_FullSizePerClassFilter
        the SizeOf agent method to use (per class, with filter).
    • Constructor Detail

      • SizeOf

        public SizeOf()
    • Method Detail

      • isSizeOfAgentAvailable

        public static boolean isSizeOfAgentAvailable()
        Returns whether the SizeOf agent is available or not.
        Returns:
        true if agent available
      • sizeOf

        public static int sizeOf​(Object obj,
                                 sizeof.agent.Filter filter)
        Returns the size of an object.
        Parameters:
        obj - the object to measure
        filter - for filtering objects/fields
        Returns:
        the size or -1 if failed to determine
        See Also:
        sizeOfAgent(Object, Filter), sizeOfSerialization(Object)
      • sizeOfAgent

        public static int sizeOfAgent​(Object obj)
        Returns the size of an object using the agent.
        Parameters:
        obj - the object to measure
        Returns:
        the size or -1 if agent not available
      • sizeOfAgent

        public static int sizeOfAgent​(Object obj,
                                      sizeof.agent.Filter filter)
        Returns the size of an object using the agent.
        Parameters:
        obj - the object to measure
        filter - for filtering objects/fields
        Returns:
        the size or -1 if agent not available
      • sizeOfAgentPerClass

        public static Map<Class,​sizeof.agent.Statistics> sizeOfAgentPerClass​(Object obj)
        Returns the size and number of instances broken down by class for the given object.
        Parameters:
        obj - the object to inspect
        Returns:
        empty map if not available, otherwise the statistics per class
      • sizeOfAgentPerClass

        public static Map<Class,​sizeof.agent.Statistics> sizeOfAgentPerClass​(Object obj,
                                                                                   sizeof.agent.Filter filter)
        Returns the size and number of instances broken down by class for the given object.
        Parameters:
        obj - the object to inspect
        filter - for filtering objects/fields
        Returns:
        empty map if not available, otherwise the statistics per class
      • sizeOfSerialization

        public static int sizeOfSerialization​(Object obj)
        Returns the size of an object using serialization.
        Parameters:
        obj - the object to measure
        Returns:
        the size or -1 if not serializable
      • main

        public static void main​(String[] args)
        For testing only.
        Parameters:
        args - ignored