net.sf.infrared.agent
Class StatisticsCollector

java.lang.Object
  extended bynet.sf.infrared.agent.StatisticsCollector

public class StatisticsCollector
extends Object

This class is to track statistics for a single request. At the end of the request the collected statistics is passed onto the CollectionStrategy for further processing


Constructor Summary
StatisticsCollector()
          Default constructor, used mainly for unit testing
StatisticsCollector(CollectionStrategy collectionStartegy, String applicationName, String instanceName)
          Construct a new instance
 
Method Summary
 String constructApiName(Class declaringType, String methodName)
          Constructs the api name combining the class name and method name.
 void endRequest()
          This method is called when the processing of a request (operation) has ended.
 void recordExecuteError(String sql, long time, boolean prepared)
           
 void recordExecuteSql(String sql, long time, boolean prepared)
           
 void recordFetchComplete(String sql, long noOfRowsFetched, long timeTakenForFetch)
           
 void recordHTTPRequest(String request, long execTime)
           
 void recordMethodBegin(String methodName, String layer)
          This is to record that a new method has started execution This method does the following Adds a new entry into the childMethodTimes to track time taken by its child methods Calls methods to setup collection of layer times If call tracing is enabled adds a new node (correponding to the method being called) to the operation tree and points the currNode to the newly added node
 void recordMethodBegin(String methodName, String layer, String componentName, ApiContext context)
          Called when an API of given name, type, arguments, belonging to the given component and with given context information has started execution.
 void recordMethodEnd(String methodName, String layer)
          Called when the method has completed execution.
 void recordMethodEnd(String methodName, String layer, String componentName, ApiContext context)
          Called when an API of given name, of a given component has stopped execution
 void recordMethodTime(String methodName, String layer, long time)
          This method is callled to record the time to execute a method
 void recordMethodTime(String methodName, String layer, String componentName, ApiContext apiCtx, long time)
          This method is called to
 void recordPrepareSql(String sql, long time)
           
 void startRequest()
          This method is called when the processing of a new request (operation) has begun.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StatisticsCollector

public StatisticsCollector(CollectionStrategy collectionStartegy,
                           String applicationName,
                           String instanceName)
Construct a new instance

Parameters:
collectionStartegy -
applicationName -
instanceName -

StatisticsCollector

public StatisticsCollector()
Default constructor, used mainly for unit testing

Method Detail

recordMethodBegin

public void recordMethodBegin(String methodName,
                              String layer)
This is to record that a new method has started execution This method does the following Adds a new entry into the childMethodTimes to track time taken by its child methods Calls methods to setup collection of layer times If call tracing is enabled adds a new node (correponding to the method being called) to the operation tree and points the currNode to the newly added node

Parameters:
methodName -
layer -

recordMethodBegin

public void recordMethodBegin(String methodName,
                              String layer,
                              String componentName,
                              ApiContext context)
Called when an API of given name, type, arguments, belonging to the given component and with given context information has started execution.

Parameters:
methodName -
layer -
componentName -
context -

recordMethodEnd

public void recordMethodEnd(String methodName,
                            String layer)
Called when the method has completed execution. Pops an element corresponding to the method that completed execution out of the childMethodTimes stack Calls the method to record the layer times If call tracing is on updates the operation tree.

Parameters:
methodName -
layer -

recordMethodTime

public void recordMethodTime(String methodName,
                             String layer,
                             long time)
This method is callled to record the time to execute a method

Parameters:
methodName -
layer -
time -

recordMethodEnd

public void recordMethodEnd(String methodName,
                            String layer,
                            String componentName,
                            ApiContext context)
Called when an API of given name, of a given component has stopped execution

Parameters:
methodName -
componentName -
context -

recordMethodTime

public void recordMethodTime(String methodName,
                             String layer,
                             String componentName,
                             ApiContext apiCtx,
                             long time)
This method is called to

Parameters:
methodName -
layer -
componentName -
apiCtx -
time -

recordExecuteError

public void recordExecuteError(String sql,
                               long time,
                               boolean prepared)

recordExecuteSql

public void recordExecuteSql(String sql,
                             long time,
                             boolean prepared)

recordPrepareSql

public void recordPrepareSql(String sql,
                             long time)

recordFetchComplete

public void recordFetchComplete(String sql,
                                long noOfRowsFetched,
                                long timeTakenForFetch)

startRequest

public void startRequest()
This method is called when the processing of a new request (operation) has begun. Need to register with the statistics object so that we get notified when a reset is called. Rest is called on one statisticsMgr, this mecahnism is to trigger reset of the other statisticsMgrs.


endRequest

public void endRequest()
This method is called when the processing of a request (operation) has ended. Unregister from the statistics mgr. We can extend this to collect the data per thread basis and update the statistics object in one shot.


recordHTTPRequest

public void recordHTTPRequest(String request,
                              long execTime)

constructApiName

public String constructApiName(Class declaringType,
                               String methodName)
Constructs the api name combining the class name and method name. This operation is invoked a lot and hence has been optimized to cache the constructed name. The optimization was done after profiling wit optimizeIt showed the method as taking too much time.

Parameters:
declaringType -
methodName -
Returns: