atg.service.perfmonitor
Class PerformanceMonitor

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.nucleus.TimedOperationService
              extended by atg.nucleus.servlet.ServletService
                  extended by atg.nucleus.servlet.HttpServletService
                      extended by atg.servlet.DynamoServlet
                          extended by atg.service.perfmonitor.PerformanceMonitor
All Implemented Interfaces:
NameContextBindingListener, NameContextElement, NameResolver, AdminableService, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, ParameterServlet, java.util.EventListener, javax.servlet.Servlet

public class PerformanceMonitor
extends DynamoServlet

The Performance Monitor servlet is responsible for gathering two types of performance data from different operations which occur in the server.

The first type of data which it gathers are the current execution stacks of all running threads. This allows users to see what operations a thread is currently doing.

The second type of data which is gathered is the time based performance data for an operation. This data is count, average, min, max, and total execution time for each operation. This also keeps track of parameters on the operations. These parameters are the objects which these operations are working on. The above stats are also kept for each parameter.

In order to use the performance monitor in your code, all you need to do is import atg.service.perfmonitor.* and add the following code snippets to your code. private final String RENDER_JHTML = "Render JHTML page"; private final String EXECUTE_SQL = "Execute SQL Query"; private String mPageName = "page.jhtml"; private String mSQLQuery = "select * from table"; PerformanceMonitor.startOperation(RENDER_JHTML, mPageName); ... source code to start render PerformanceMonitor.startOperation(EXECUTE_SQL, mSQLQuery); ... source code to read from table 1 in database PerformanceMonitor.startOperation(); ... source code to read from database PerformanceMonitor.endOperation(); ... more source code to read from table 1 in database PerformanceMonitor.endOperation(); ... more source code to finish render PerformanceMonitor.endOperation();


Field Summary
static java.lang.String CLASS_VERSION
           
static int DISABLED
          DISABLED mode turns the performance monitor off
static int MEMORY
          MEMORY mode runs the performance monitor with stack tracking, operation timestamping, and memory tracking on
static int NORMAL
          NORMAL mode runs the performance monitor with only stack tracking on
static int TIME
          TIME mode runs the performance monitor with stack tracking and operation timestamping on
 
Fields inherited from class atg.servlet.DynamoServlet
mAllowCleanupRequest, mParameters
 
Fields inherited from class atg.nucleus.servlet.ServletService
SERVLET_INFO_KEY
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
PerformanceMonitor()
          Constructs a null Template.
 
Method Summary
static void cancelOperation(java.lang.String pOpName)
          Cancels an operation
static void cancelOperation(java.lang.String pOpName, java.lang.String pParameter)
          Cancels an operation and supplies a parameter
protected  void cancelOperationInternal(java.lang.String pOpName, java.lang.String pParameter)
          The cancelOperation which does the work for the performance monitor.
protected  void cleanMemoryPerformanceData()
          This method resets the memory data from the PerformanceData objects in the mPerformanceHash table.
protected  void cleanPerformanceStructure()
          This method cleans out the mPerformanceHash table so that there are no PerformanceHashTables in it and no PerformanceData objects within that table.
protected  void cleanStackStructure()
          This method cleans out the mThreadStackHash table so that there are no Stack objects in it and no PerformanceStackData objects within that object.
protected  void cleanThreadStack(java.lang.Thread pThread)
          This method cleans out the Stack in the mThreadStackHash table for the given thread so there are no PerformanceStackData objects within that object.
 void doStartService()
          This is called after a Service has been created, placed into the naming hierarchy, and initialized with its configured property values.
 void doStopService()
          This is called when a Service is required to shut down.
static void endOperation()
          Marks the end of the most recent operation in the code for which monitoring has been started, but not yet ended.
static void endOperation(java.lang.String pOpName)
          Marks the end of an operation in the code
static void endOperation(java.lang.String pOpName, java.lang.String pParameter)
          Marks the end of an operation in the code and supplies a parameter
static void endOperation(java.lang.String pOpName, java.lang.String pParameter, ApplicationLogging pLogger)
          Marks the end of an operation in the code and supplies a parameter.
protected  void endOperationInternal(java.lang.String pOpName, java.lang.String pParameter)
          The endOperation which does the work for the performance monitor.
 java.lang.Thread[] getExcludedThreads()
          Returns property excludedThreads
 java.lang.String[] getExcludeServers()
          Returns property excludeServers
 boolean getIncludeNestedOperations()
          Returns property includeNestedOperations
 int getInitialPerformanceDataPoolSize()
          Returns property initialPerformanceDataPoolSize
 int getInitialStackDataPoolSize()
          Returns property initialStackDataPoolSize
 int getInitialStackPoolSize()
          Returns property initialStackPoolSize
 int getMode()
          Returns property mode
 java.util.Hashtable getPerformanceHash()
          Returns property performanceHash
static PerformanceMonitor getPerformanceMonitor()
          Returns the global PerformanceMonitor object
 java.util.Hashtable getThreadStackHash()
          Returns property threadStackHash
 boolean getVerbose()
          Returns property verbose
 boolean handleReset(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          This method handles the reset data button on the performance monitor page.
static boolean isEnabled()
          Returns whether the perf monitor is enabled or not
protected  boolean isExcludedThread(java.lang.Thread pThread)
          This method determines if the given thread is in the excludedThreads list.
 void resetPerformanceData()
          Resets all the time performance data back to 0
protected  void setExcludedThreads(java.lang.Thread[] pExcludedThreads)
          Sets property excludedThreads
 void setExcludeServers(java.lang.String[] pExcludeServers)
          Sets property excludeServers
 void setIncludeNestedOperations(boolean pIncludeNestedOperations)
          Sets property includeNestedOperations
 void setInitialPerformanceDataPoolSize(int pInitialPerformanceDataPoolSize)
          Sets property initialPerformanceDataPoolSize
 void setInitialStackDataPoolSize(int pInitialStackDataPoolSize)
          Sets property initialStackDataPoolSize
 void setInitialStackPoolSize(int pInitialStackPoolSize)
          Sets property initialStackPoolSize
 void setMode(int pMode)
          Sets property mode
protected  void setupExcludeServers()
          This method takes the mExcludeServers list and adds all the threads from that component to the mExcludedThreads list.
 void setVerbose(boolean pVerbose)
          Sets property verbose
static void startOperation(java.lang.String pOpName)
          Marks the beginning of an operation in the code
static void startOperation(java.lang.String pOpName, java.lang.String pParameter)
          Marks the beginning of an operation in the code and supplies a parameter
protected  void startOperationInternal(java.lang.String pOpName, java.lang.String pParameter)
          The startOperation which does the work for the performance monitor.
 
Methods inherited from class atg.servlet.DynamoServlet
doDelete, doGet, doPost, doPut, getParameter, getParameters, getServletContext, service, service, service, setParameter
 
Methods inherited from class atg.nucleus.servlet.ServletService
destroy, getServletConfig, getServletInfo, init, setServletInfo
 
Methods inherited from class atg.nucleus.TimedOperationService
getAverageRequestHandlingTime, getHandledRequestCount, getRequestStartTime, getTotalRequestHandlingTime, isKeepingStatistics, notifyHandledRequest, resetStatistics, setKeepingStatistics
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, getAbsoluteName, getAdminServlet, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, reResolveThis, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION

DISABLED

public static final int DISABLED
DISABLED mode turns the performance monitor off

See Also:
Constant Field Values

NORMAL

public static final int NORMAL
NORMAL mode runs the performance monitor with only stack tracking on

See Also:
Constant Field Values

TIME

public static final int TIME
TIME mode runs the performance monitor with stack tracking and operation timestamping on

See Also:
Constant Field Values

MEMORY

public static final int MEMORY
MEMORY mode runs the performance monitor with stack tracking, operation timestamping, and memory tracking on

See Also:
Constant Field Values
Constructor Detail

PerformanceMonitor

public PerformanceMonitor()
Constructs a null Template.

Method Detail

resetPerformanceData

public void resetPerformanceData()
Resets all the time performance data back to 0


startOperationInternal

protected void startOperationInternal(java.lang.String pOpName,
                                      java.lang.String pParameter)
The startOperation which does the work for the performance monitor. When a new operation is started, the current thread is used as a key and a Stack is allocated to be used for storing the PerformanceStackData objects for this thread. The stack is stored in the mThreadStackHash hashtable.

Starting an operation entails allocating a new Stack object if it does not exist and then pushing a PerformanceStackData object populated with the supplied data onto the stack and setting the start time.

Parameters:
pOpName - the name of the operation
pParameter - the object or name of object which this operation is working on

endOperationInternal

protected void endOperationInternal(java.lang.String pOpName,
                                    java.lang.String pParameter)
                             throws PerfStackMismatchException
The endOperation which does the work for the performance monitor. The Stack is retrieved from the mThreadStackHash table and the top operation in the stack is popped off. If this is TIME mode then the execution time is determined and stats calculated and added to the mPerformanceHash table.

Ending an operation entails getting the PerformanceStackData object from the top of the stack, comparing it for stack mismatch, getting the execution time for the operation and setting some stats based on that information.

Parameters:
pOpName - the name of the operation; if null, then no stack mismatch check takes place.
pParameter - the object or name of object which this operation is working on
Throws:
PerfStackMismatchException - if the arguments do not match the operation in the top of the stack

cancelOperationInternal

protected void cancelOperationInternal(java.lang.String pOpName,
                                       java.lang.String pParameter)
                                throws PerfStackMismatchException
The cancelOperation which does the work for the performance monitor. This method exists for the case when operations do not complete successfully and the developer does not want this instance of performance data to be used in calculating stats.

Parameters:
pOpName - the name of the operation
pParameter - the object or name of object which this operation is working on
Throws:
PerfStackMismatchException - if the arguments do not match the operation in the top of the stack

cleanThreadStack

protected void cleanThreadStack(java.lang.Thread pThread)
This method cleans out the Stack in the mThreadStackHash table for the given thread so there are no PerformanceStackData objects within that object. The PerformanceStackData objects are returned to their pools and the Stack object is removed from the table.


cleanStackStructure

protected void cleanStackStructure()
This method cleans out the mThreadStackHash table so that there are no Stack objects in it and no PerformanceStackData objects within that object. The PerformanceStackData objects are returned to their pools.


cleanPerformanceStructure

protected void cleanPerformanceStructure()
This method cleans out the mPerformanceHash table so that there are no PerformanceHashTables in it and no PerformanceData objects within that table. The PerformanceData objects are returned to their pools.


cleanMemoryPerformanceData

protected void cleanMemoryPerformanceData()
This method resets the memory data from the PerformanceData objects in the mPerformanceHash table.


setupExcludeServers

protected void setupExcludeServers()
This method takes the mExcludeServers list and adds all the threads from that component to the mExcludedThreads list.


isExcludedThread

protected boolean isExcludedThread(java.lang.Thread pThread)
This method determines if the given thread is in the excludedThreads list. If so, the thread will not be used to record performance data.

Parameters:
pThread - the thread to search for in the excludedThreads list

setMode

public void setMode(int pMode)
Sets property mode


getMode

public int getMode()
Returns property mode


setVerbose

public void setVerbose(boolean pVerbose)
Sets property verbose


getVerbose

public boolean getVerbose()
Returns property verbose


setIncludeNestedOperations

public void setIncludeNestedOperations(boolean pIncludeNestedOperations)
Sets property includeNestedOperations


getIncludeNestedOperations

public boolean getIncludeNestedOperations()
Returns property includeNestedOperations


setExcludeServers

public void setExcludeServers(java.lang.String[] pExcludeServers)
Sets property excludeServers


getExcludeServers

public java.lang.String[] getExcludeServers()
Returns property excludeServers


setExcludedThreads

protected void setExcludedThreads(java.lang.Thread[] pExcludedThreads)
Sets property excludedThreads


getExcludedThreads

public java.lang.Thread[] getExcludedThreads()
Returns property excludedThreads


setInitialStackDataPoolSize

public void setInitialStackDataPoolSize(int pInitialStackDataPoolSize)
Sets property initialStackDataPoolSize


getInitialStackDataPoolSize

public int getInitialStackDataPoolSize()
Returns property initialStackDataPoolSize


setInitialPerformanceDataPoolSize

public void setInitialPerformanceDataPoolSize(int pInitialPerformanceDataPoolSize)
Sets property initialPerformanceDataPoolSize


getInitialPerformanceDataPoolSize

public int getInitialPerformanceDataPoolSize()
Returns property initialPerformanceDataPoolSize


setInitialStackPoolSize

public void setInitialStackPoolSize(int pInitialStackPoolSize)
Sets property initialStackPoolSize


getInitialStackPoolSize

public int getInitialStackPoolSize()
Returns property initialStackPoolSize


getThreadStackHash

public java.util.Hashtable getThreadStackHash()
Returns property threadStackHash


getPerformanceHash

public java.util.Hashtable getPerformanceHash()
Returns property performanceHash


getPerformanceMonitor

public static final PerformanceMonitor getPerformanceMonitor()
Returns the global PerformanceMonitor object


startOperation

public static final void startOperation(java.lang.String pOpName)
Marks the beginning of an operation in the code

Parameters:
pOpName - the name of the operation which begins in the code

startOperation

public static final void startOperation(java.lang.String pOpName,
                                        java.lang.String pParameter)
Marks the beginning of an operation in the code and supplies a parameter

Parameters:
pOpName - the name of the operation which begins in the code
pParameter - the object or name of the object which the operation is executing on

endOperation

public static final void endOperation()
Marks the end of the most recent operation in the code for which monitoring has been started, but not yet ended.


endOperation

public static final void endOperation(java.lang.String pOpName)
                               throws PerfStackMismatchException
Marks the end of an operation in the code

Parameters:
pOpName - the name of the operation which has completed in the code
Throws:
PerfStackMismatchException - if this call is called out of order in relation to the other endOperation calls.

endOperation

public static final void endOperation(java.lang.String pOpName,
                                      java.lang.String pParameter)
                               throws PerfStackMismatchException
Marks the end of an operation in the code and supplies a parameter

Parameters:
pOpName - the name of the operation which has completed in the code
pParameter - the object or name of the object which the operation has completed executing on
Throws:
PerfStackMismatchException - if this call is called out of order in relation to the other endOperation calls.

endOperation

public static final void endOperation(java.lang.String pOpName,
                                      java.lang.String pParameter,
                                      ApplicationLogging pLogger)
Marks the end of an operation in the code and supplies a parameter. This version does not throw a PerfStackException, but instead takes an ApplicationLogging to log an error if one occurs. You can pass null here to avoid all error checking.

Parameters:
pOpName - the name of the operation which has completed in the code
pParameter - the object or name of the object which the operation has completed executing on
Throws:
PerfStackMismatchException - if this call is called out of order in relation to the other endOperation calls.

cancelOperation

public static final void cancelOperation(java.lang.String pOpName)
                                  throws PerfStackMismatchException
Cancels an operation

Parameters:
pOpName - the name of the operation which is to be cancelled
Throws:
PerfStackMismatchException - if this call is called out of order in relation to the other endOperation calls.

cancelOperation

public static final void cancelOperation(java.lang.String pOpName,
                                         java.lang.String pParameter)
                                  throws PerfStackMismatchException
Cancels an operation and supplies a parameter

Parameters:
pOpName - the name of the operation which is to be cancelled
pParameter - the object or name of the object which the operation is to be cancelled on
Throws:
PerfStackMismatchException - if this call is called out of order in relation to the other endOperation calls.

isEnabled

public static final boolean isEnabled()
Returns whether the perf monitor is enabled or not

Returns:
whether the performance monitor is enabled or not

doStartService

public void doStartService()
                    throws ServiceException
Description copied from class: GenericService
This is called after a Service has been created, placed into the naming hierarchy, and initialized with its configured property values. The Service should override this method to start any processes it requires.

Overrides:
doStartService in class GenericService
Throws:
ServiceException - if the Service had a problem starting up

doStopService

public void doStopService()
                   throws ServiceException
Description copied from class: GenericService
This is called when a Service is required to shut down. The Service should respond by stopping any processes that it has started.

Overrides:
doStopService in class GenericService
Throws:
ServiceException - if the Service had a problem shutting down

handleReset

public boolean handleReset(javax.servlet.http.HttpServletRequest req,
                           javax.servlet.http.HttpServletResponse res)
This method handles the reset data button on the performance monitor page.

Parameters:
req - the request to be processed
res - the response object for this request