Class ProfileStatistic

  • All Implemented Interfaces:
    java.lang.Runnable, ProfileStatisticMBean

    public class ProfileStatistic
    extends java.lang.Thread
    implements ProfileStatisticMBean
    This is constructed as a thin layer around com.jamonapi.MonitorFactory for the needs of patterntesting. The reason for this layer is that sometimes you want to minimize the use of other libraries. So this implementation provides also an implementation if the JaMon library is missing.
    Since:
    22.12.2008
    Version:
    $Revision: 1.40 $
    Author:
    oliver
    See Also:
    MonitorFactory
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.lang.Thread

        java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
    • Field Summary

      • Fields inherited from class java.lang.Thread

        MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected ProfileStatistic​(java.lang.String rootLabel)
      Instantiates a new profile statistic.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static void addAsShutdownHook()
      You can register the instance as shutdown hook.
      protected static void addAsShutdownHook​(ProfileStatistic hook)
      Adds the given instance (hook) as shutdown hook.
      java.io.File dumpStatistic()
      Dump statistic to a file in the temporary directory.
      void dumpStatistic​(java.lang.String filename)
      This operation dumps the statistic to the given file.
      void dumpStatisticTo​(java.io.File dumpFile)
      Dump statistic to the given file.
      static ProfileStatistic getInstance()
      Gets the single instance of ProfileStatistic.
      double getMaxAvg()
      Gets the max avg.
      java.lang.String getMaxAvgLabel()
      Gets the max avg label.
      java.lang.String getMaxAvgStatistic()
      Gets the max avg statistic.
      int getMaxHits()
      Gets the max hits.
      java.lang.String getMaxHitsLabel()
      Gets the max hits label.
      java.lang.String getMaxHitsStatistic()
      Gets the max hits statistic.
      double getMaxMax()
      Gets the max max.
      java.lang.String getMaxMaxLabel()
      Gets the max max label.
      java.lang.String getMaxMaxStatistic()
      Gets the max max statistic.
      int getMaxSize()
      Gets the max size.
      double getMaxTotal()
      Gets the max total.
      java.lang.String getMaxTotalLabel()
      Gets the max total label.
      java.lang.String getMaxTotalStatistic()
      Gets the max total statistic.
      javax.management.ObjectName getMBeanName()
      Gets the MBean name of the registered ProfileStatistic bean.
      ProfileMonitor[] getMonitors()
      Gets the monitors (unsorted).
      ProfileMonitor getProfileMonitor​(java.lang.Class<?> clazz, java.lang.String method)
      Do you want to look for the monitor of a given method?
      ProfileMonitor getProfileMonitor​(java.lang.String signature)
      Do you want to look for the monitor of a given method?
      ProfileMonitor getProfileMonitor​(org.aspectj.lang.Signature signature)
      Do you want to look for the monitor of a given method?
      protected ProfileMonitor getRootMonitor()
      Gets the root monitor.
      protected ProfileMonitor[] getSortedMonitors()
      Gets the sorted monitors.
      javax.management.openmbean.TabularData getStatistics()
      Gets the statistics.
      void init​(java.lang.Class<?> cl)
      For each constructor and for each method of the given class a ProfileMonitor is initialized.
      void logStatistic()
      Log statistic.
      static void registerAsMBean​(java.lang.String name)
      Normally the ProfileMonitor is already registered as MBean.
      protected void registerMeAsMBean​(java.lang.String name)
      Register me as MBean.
      void reset()
      We can't reset all ProfileMonitors - we must keep the empty monitors with 0 hits to see which methods or constructors are never called.
      protected void resetRootMonitor()
      Resets the root monitor.
      void run()
      This method is called when the PerformanceMonitor is registered as shutdown hook.
      void setMaxSize​(int size)
      Here you can set the maximal size of the statistic entries.
      static ProfileMonitor start​(org.aspectj.lang.Signature sig)
      Start.
      ProfileMonitor startProfileMonitorFor​(java.lang.String sig)
      Start profile monitor for the given signature.
      ProfileMonitor startProfileMonitorFor​(org.aspectj.lang.Signature sig)
      Start profile monitor for the given signature.
      java.lang.String toString()
      To string.
      • Methods inherited from class java.lang.Thread

        activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, yield
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ProfileStatistic

        protected ProfileStatistic​(java.lang.String rootLabel)
        Instantiates a new profile statistic.
        Parameters:
        rootLabel - the root label
    • Method Detail

      • getInstance

        public static ProfileStatistic getInstance()
        Gets the single instance of ProfileStatistic.
        Returns:
        single instance of ProfileStatistic
      • registerAsMBean

        public static void registerAsMBean​(java.lang.String name)
        Normally the ProfileMonitor is already registered as MBean. So you don't need to register it manually. But if you want to register it under your own name you can use this method here. This can be useful if your application runs on an application server with several other active applications.
        Parameters:
        name - e.g "my.company.ProfileMonitor"
        Since:
        1.6
      • registerMeAsMBean

        protected void registerMeAsMBean​(java.lang.String name)
        Register me as MBean.
        Parameters:
        name - the name
      • addAsShutdownHook

        public static void addAsShutdownHook()
        You can register the instance as shutdown hook. If the VM is terminated the profile values are logged and dumped to a CSV file in the tmp directory.
        See Also:
        logStatistic(), dumpStatistic()
      • addAsShutdownHook

        protected static void addAsShutdownHook​(ProfileStatistic hook)
        Adds the given instance (hook) as shutdown hook.
        Parameters:
        hook - the hook
      • reset

        public void reset()
        We can't reset all ProfileMonitors - we must keep the empty monitors with 0 hits to see which methods or constructors are never called.
        Specified by:
        reset in interface ProfileStatisticMBean
      • resetRootMonitor

        protected void resetRootMonitor()
        Resets the root monitor.
      • init

        public void init​(java.lang.Class<?> cl)
        For each constructor and for each method of the given class a ProfileMonitor is initialized. This is done to be able to find constructors and methods which are are never used (i.e. their hit count is zero).
        Parameters:
        cl - the given class
      • getMBeanName

        public javax.management.ObjectName getMBeanName()
        Gets the MBean name of the registered ProfileStatistic bean.
        Returns:
        the MBean name
      • setMaxSize

        public void setMaxSize​(int size)
        Here you can set the maximal size of the statistic entries.
        Specified by:
        setMaxSize in interface ProfileStatisticMBean
        Parameters:
        size - the new max size
        Since:
        1.6
      • run

        public void run()
        This method is called when the PerformanceMonitor is registered as shutdown hook.
        Specified by:
        run in interface java.lang.Runnable
        Overrides:
        run in class java.lang.Thread
        See Also:
        Thread.run()
      • start

        public static ProfileMonitor start​(org.aspectj.lang.Signature sig)
        Start.
        Parameters:
        sig - the sig
        Returns:
        the profile monitor
      • startProfileMonitorFor

        public ProfileMonitor startProfileMonitorFor​(org.aspectj.lang.Signature sig)
        Start profile monitor for the given signature.
        Parameters:
        sig - the signature
        Returns:
        the profile monitor
      • startProfileMonitorFor

        public ProfileMonitor startProfileMonitorFor​(java.lang.String sig)
        Start profile monitor for the given signature.
        Parameters:
        sig - the signature
        Returns:
        the profile monitor
      • getMonitors

        public ProfileMonitor[] getMonitors()
        Gets the monitors (unsorted).
        Returns:
        the monitors
      • getSortedMonitors

        protected final ProfileMonitor[] getSortedMonitors()
        Gets the sorted monitors.
        Returns:
        monitors sorted after total time (descending order)
      • getRootMonitor

        protected ProfileMonitor getRootMonitor()
        Gets the root monitor.
        Returns:
        the root monitor
      • dumpStatistic

        public java.io.File dumpStatistic()
                                   throws java.io.IOException
        Dump statistic to a file in the temporary directory. Since 1.4.2 the filename is no longer "profile###.csv", but begins with the classname. The reason is located in the subclass SqlStatistic - now you can see which CSV file belongs to which statistic.
        Specified by:
        dumpStatistic in interface ProfileStatisticMBean
        Returns:
        the name of the dump file
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
        See Also:
        ProfileStatisticMBean.dumpStatistic()
      • dumpStatistic

        public void dumpStatistic​(java.lang.String filename)
                           throws java.io.IOException
        This operation dumps the statistic to the given file.
        Specified by:
        dumpStatistic in interface ProfileStatisticMBean
        Parameters:
        filename - the file name
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
        Since:
        1.5
        See Also:
        ProfileStatisticMBean.dumpStatistic(String)
      • dumpStatisticTo

        public void dumpStatisticTo​(java.io.File dumpFile)
                             throws java.io.IOException
        Dump statistic to the given file.
        Parameters:
        dumpFile - the dump file
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • getProfileMonitor

        @MayReturnNull
        public ProfileMonitor getProfileMonitor​(java.lang.Class<?> clazz,
                                                java.lang.String method)
        Do you want to look for the monitor of a given method? Use this method here.
        Parameters:
        clazz - the clazz
        method - the method name, including parameter e.g. "getProfileMonitor(Class,String)"
        Returns:
        monitor of the given class or null
      • getProfileMonitor

        @MayReturnNull
        public ProfileMonitor getProfileMonitor​(org.aspectj.lang.Signature signature)
        Do you want to look for the monitor of a given method? Use this method here.
        Parameters:
        signature - e.g. "hello.World(String[])"
        Returns:
        monitor for the given signature or null
        Since:
        1.4.2
      • getProfileMonitor

        @MayReturnNull
        public ProfileMonitor getProfileMonitor​(java.lang.String signature)
        Do you want to look for the monitor of a given method? Use this method here.
        Parameters:
        signature - e.g. "hello.World(String[])"
        Returns:
        monitor for the given signature or null
      • toString

        public java.lang.String toString()
        To string.
        Overrides:
        toString in class java.lang.Thread
        Returns:
        the string
        See Also:
        Thread.toString()