patterntesting.runtime.monitor
Class ProfileStatistic

Package class diagram package ProfileStatistic
java.lang.Object
  extended by java.lang.Thread
      extended by patterntesting.runtime.monitor.ProfileStatistic
All Implemented Interfaces:
Runnable, ProfileStatisticMBean
Direct Known Subclasses:
SqlStatistic

public class ProfileStatistic
extends 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.24 $
Author:
oliver
See Also:
MonitorFactory

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
protected static boolean jamonAvailable
          Is JaMon library available?.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
protected ProfileStatistic(String rootLabel)
          Instantiates a new profile statistic.
 
Method Summary
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.
 void dumpStatistic()
          Dump statistic to a file in the temporary directory.
 void dumpStatisticTo(File dumpFile)
          Dump statistic to the given file
static ProfileStatistic getInstance()
          Gets the single instance of ProfileStatistic.
 double getMaxAvg()
          Gets the max avg.
 String getMaxAvgLabel()
          Gets the max avg label.
 String getMaxAvgStatistic()
          Gets the max avg statistic.
 int getMaxHits()
          Gets the max hits.
 String getMaxHitsLabel()
          Gets the max hits label.
 String getMaxHitsStatistic()
          Gets the max hits statistic.
 double getMaxMax()
          Gets the max max.
 String getMaxMaxLabel()
          Gets the max max label.
 String getMaxMaxStatistic()
          Gets the max max statistic.
 double getMaxTotal()
          Gets the max total.
 String getMaxTotalLabel()
          Gets the max total label.
 String getMaxTotalStatistic()
          Gets the max total statistic.
 ObjectName getMBeanName()
          Gets the MBean name of the registered ProfileStatistic bean.
 ProfileMonitor getProfileMonitor(Class<?> clazz, String method)
          Do you want to look for the monitor of a given method?
 ProfileMonitor getProfileMonitor(Signature signature)
          Do you want to look for the monitor of a given method?
 ProfileMonitor getProfileMonitor(String 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.
 TabularData getStatistics()
          Gets the statistics.
 void init(Class<?> cl)
          For each constructor and for each method of the given class a ProfileMonitor is initialized.
 void logStatistic()
          Log statistic.
 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.
static ProfileMonitor start(Signature sig)
          Start.
 ProfileMonitor startProfileMonitorFor(Signature sig)
          Start profile monitor for the given signature.
 ProfileMonitor startProfileMonitorFor(String sig)
          Start profile monitor for the given signature.
 String toString()
          To string.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

jamonAvailable

protected static final boolean jamonAvailable
Is JaMon library available?.

Constructor Detail

ProfileStatistic

protected ProfileStatistic(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

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(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 ObjectName getMBeanName()
Gets the MBean name of the registered ProfileStatistic bean.

Returns:
the MBean name

run

public void run()
This method is called when the PerformanceMonitor is registered as shutdown hook.

Specified by:
run in interface Runnable
Overrides:
run in class Thread
See Also:
Thread.run()

start

public static ProfileMonitor start(Signature sig)
Start.

Parameters:
sig - the sig
Returns:
the profile monitor

startProfileMonitorFor

public ProfileMonitor startProfileMonitorFor(Signature sig)
Start profile monitor for the given signature.

Parameters:
sig - the signature
Returns:
the profile monitor

startProfileMonitorFor

public ProfileMonitor startProfileMonitorFor(String sig)
Start profile monitor for the given signature.

Parameters:
sig - the signature
Returns:
the profile monitor

getSortedMonitors

protected final ProfileMonitor[] getSortedMonitors()
Gets the sorted monitors.

Returns:
monitors sorted after total time (descending order)

getMaxHits

public int getMaxHits()
Gets the max hits.

Specified by:
getMaxHits in interface ProfileStatisticMBean
Returns:
the max hits
See Also:
ProfileStatisticMBean.getMaxHits()

getMaxHitsLabel

public String getMaxHitsLabel()
Gets the max hits label.

Specified by:
getMaxHitsLabel in interface ProfileStatisticMBean
Returns:
the max hits label
See Also:
ProfileStatisticMBean.getMaxHitsLabel()

getMaxHitsStatistic

public String getMaxHitsStatistic()
Gets the max hits statistic.

Specified by:
getMaxHitsStatistic in interface ProfileStatisticMBean
Returns:
the max hits statistic
See Also:
ProfileStatisticMBean.getMaxHitsStatistic()

getMaxTotal

public double getMaxTotal()
Gets the max total.

Specified by:
getMaxTotal in interface ProfileStatisticMBean
Returns:
the max total
See Also:
ProfileStatisticMBean.getMaxTotal()

getMaxTotalLabel

public String getMaxTotalLabel()
Gets the max total label.

Specified by:
getMaxTotalLabel in interface ProfileStatisticMBean
Returns:
the max total label
See Also:
ProfileStatisticMBean.getMaxTotalLabel()

getMaxTotalStatistic

public String getMaxTotalStatistic()
Gets the max total statistic.

Specified by:
getMaxTotalStatistic in interface ProfileStatisticMBean
Returns:
the max total statistic
See Also:
ProfileStatisticMBean.getMaxTotalStatistic()

getRootMonitor

protected ProfileMonitor getRootMonitor()
Gets the root monitor.

Returns:
the root monitor

getMaxAvg

public double getMaxAvg()
Gets the max avg.

Specified by:
getMaxAvg in interface ProfileStatisticMBean
Returns:
the max avg
See Also:
ProfileStatisticMBean.getMaxAvg()

getMaxAvgLabel

public String getMaxAvgLabel()
Gets the max avg label.

Specified by:
getMaxAvgLabel in interface ProfileStatisticMBean
Returns:
the max avg label
See Also:
ProfileStatisticMBean.getMaxAvgLabel()

getMaxAvgStatistic

public String getMaxAvgStatistic()
Gets the max avg statistic.

Specified by:
getMaxAvgStatistic in interface ProfileStatisticMBean
Returns:
the max avg statistic
See Also:
ProfileStatisticMBean.getMaxAvgStatistic()

getMaxMax

public double getMaxMax()
Gets the max max.

Specified by:
getMaxMax in interface ProfileStatisticMBean
Returns:
the max max
See Also:
ProfileStatisticMBean.getMaxMax()

getMaxMaxLabel

public String getMaxMaxLabel()
Gets the max max label.

Specified by:
getMaxMaxLabel in interface ProfileStatisticMBean
Returns:
the max max label
See Also:
ProfileStatisticMBean.getMaxMaxLabel()

getMaxMaxStatistic

public String getMaxMaxStatistic()
Gets the max max statistic.

Specified by:
getMaxMaxStatistic in interface ProfileStatisticMBean
Returns:
the max max statistic
See Also:
ProfileStatisticMBean.getMaxMaxStatistic()

getStatistics

public TabularData getStatistics()
Gets the statistics.

Specified by:
getStatistics in interface ProfileStatisticMBean
Returns:
the statistics
See Also:
ProfileStatisticMBean.getStatistics()

logStatistic

public void logStatistic()
Log statistic.

Specified by:
logStatistic in interface ProfileStatisticMBean
See Also:
ProfileStatisticMBean.logStatistic()

dumpStatistic

public void dumpStatistic()
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
See Also:
ProfileStatisticMBean.dumpStatistic()

dumpStatisticTo

public void dumpStatisticTo(File dumpFile)
                     throws IOException
Dump statistic to the given file

Parameters:
dumpFile - the dump file
Throws:
IOException - Signals that an I/O exception has occurred.

getProfileMonitor

@MayReturnNull
public ProfileMonitor getProfileMonitor(Class<?> clazz,
                                                      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(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(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 String toString()
To string.

Overrides:
toString in class Thread
Returns:
the string
See Also:
Thread.toString()


Copyright © 2002–2014 PatternTesting Team. All rights reserved.