Project Wonder 5.0

er.extensions.statistics
Class ERXStats

java.lang.Object
  extended by er.extensions.statistics.ERXStats

public class ERXStats
extends java.lang.Object

ERXStats provides a simple interface for logging statistics information like WOEvent, but also tracked on a per-thread basis (so you can dump stats just for a particular thread). YOU PROBABLY DO NOT WANT TO TURN THIS ON IN PRODUCTION.

As an example, you may want to track stats on keypaths in your components. In your base components, you could add:

 public Object valueForKeyPath(String keyPath) {
   Object value;
   if (_shouldTrackStats) {
     String logName = ERXStringUtilities.getSimpleClassName(getClass()) + ": " + keyPath;
     ERXStats.markStart(logName);
     value = super.valueForKeyPath(keyPath);
     ERXStats.markEnd(logName);
   }
   else {
     value = super.valueForKeyPath(keyPath);
   }
   return value;
 }
 

Author:
anjo, mschrag
Properties
er.extensions.erxStats.enabled if true, stats will be initialized on each for each request
           
er.extensions.erxStats.traceCollectingEnabled defaults to false
           
er.extensions.erxStats.max the maximum historical stats to collect (defaults to 1000)
           

Nested Class Summary
static interface ERXStats.Group
           
static class ERXStats.LogEntry
          A statistics logging entry.
 
Field Summary
static org.apache.log4j.Logger log
           
static java.lang.String STATS_ENABLED_KEY
           
static java.lang.String STATS_TRACE_COLLECTING_ENABLED_KEY
           
 
Constructor Summary
ERXStats()
           
 
Method Summary
static void addDurationForKey(long duration, java.lang.String key)
          Adds the specified duration in milliseconds for the given key.
static void addDurationForKey(long duration, java.lang.String group, java.lang.String key)
          Adds the specified duration in milliseconds for the given key.
static com.webobjects.foundation.NSSet<java.lang.String> aggregateKeys()
          Returns the aggregate key names for all of the threads that have been recorded.
static com.webobjects.foundation.NSArray<ERXStats.LogEntry> aggregateLogEntries()
          Returns an array of LogEntries that represents the aggregate time for all of the tracked stats in the queue, uniqued on key.
static void initStatistics()
          Initializes the logging stats manually.
static void initStatisticsIfNecessary()
          Initializes the logging system if the property er.extensions.erxStats.enabled is true.
static boolean isTrackingStatistics()
          Returns true if the current thread is tracking statistics.
static ERXStats.LogEntry logEntryForKey(java.lang.String key)
          Returns the log entry for the given key.
static ERXStats.LogEntry logEntryForKey(java.lang.String group, java.lang.String key)
          Returns the log entry for the given key within the specified logging group.
static void logStatisticsForOperation(org.apache.log4j.Logger statsLog, java.lang.String operation)
          Logs the messages since the last call to initStatistics() ordered by some key.
static void logStatisticsForOperation(java.lang.String operation)
          Logs the messages since the last call to initStatistics() ordered by some key.
static void markEnd(java.lang.String key)
          Marks the end of a process, and calls addDuration(..) with the time since markStart.
static void markEnd(java.lang.String group, java.lang.String key)
          Marks the end of a process, and calls addDuration(..) with the time since markStart.
static void markStart(java.lang.String key)
          Mark the start of a process, call markEnd when it is over to log the duration.
static void markStart(java.lang.String group, java.lang.String key)
          Mark the start of a process, call markEnd when it is over to log the duration.
static void reset()
          Resets statistics for this thread AND the global queue.
static com.webobjects.foundation.NSMutableDictionary<java.lang.String,ERXStats.LogEntry> statistics()
          Returns the statistics for the current thread.
static boolean traceCollectingEnabled()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATS_ENABLED_KEY

public static final java.lang.String STATS_ENABLED_KEY
See Also:
Constant Field Values

STATS_TRACE_COLLECTING_ENABLED_KEY

public static final java.lang.String STATS_TRACE_COLLECTING_ENABLED_KEY
See Also:
Constant Field Values

log

public static final org.apache.log4j.Logger log
Constructor Detail

ERXStats

public ERXStats()
Method Detail

initStatisticsIfNecessary

public static void initStatisticsIfNecessary()
Initializes the logging system if the property er.extensions.erxStats.enabled is true. ERXApplication.dispatchRequest will automatically call this.


traceCollectingEnabled

public static boolean traceCollectingEnabled()

initStatistics

public static void initStatistics()
Initializes the logging stats manually. You can call this if you want to turn on thread logging just for a particular area of your application.


isTrackingStatistics

public static boolean isTrackingStatistics()
Returns true if the current thread is tracking statistics.

Returns:
true if the current thread is tracking statistics

statistics

public static com.webobjects.foundation.NSMutableDictionary<java.lang.String,ERXStats.LogEntry> statistics()
Returns the statistics for the current thread.

Returns:
the statistics for the current thread

logEntryForKey

public static ERXStats.LogEntry logEntryForKey(java.lang.String key)
Returns the log entry for the given key.

Parameters:
key - the key to lookup
Returns:
the log entry for the given key

logEntryForKey

public static ERXStats.LogEntry logEntryForKey(java.lang.String group,
                                               java.lang.String key)
Returns the log entry for the given key within the specified logging group.

Parameters:
group - the logging group to search for the key
key - the key to lookup
Returns:
the log entry for the given key

aggregateKeys

public static com.webobjects.foundation.NSSet<java.lang.String> aggregateKeys()
Returns the aggregate key names for all of the threads that have been recorded.

Returns:
the aggregate key names for all of the threads that have been recorded

aggregateLogEntries

public static com.webobjects.foundation.NSArray<ERXStats.LogEntry> aggregateLogEntries()
Returns an array of LogEntries that represents the aggregate time for all of the tracked stats in the queue, uniqued on key.

Returns:
an aggregate set of log entries

markStart

public static void markStart(java.lang.String group,
                             java.lang.String key)
Mark the start of a process, call markEnd when it is over to log the duration.

Parameters:
key - the key log to start logging

markStart

public static void markStart(java.lang.String key)
Mark the start of a process, call markEnd when it is over to log the duration.

Parameters:
key - the key log to start logging

markEnd

public static void markEnd(java.lang.String group,
                           java.lang.String key)
Marks the end of a process, and calls addDuration(..) with the time since markStart.

Parameters:
key - the key to log under

markEnd

public static void markEnd(java.lang.String key)
Marks the end of a process, and calls addDuration(..) with the time since markStart.

Parameters:
key - the key to log under

addDurationForKey

public static void addDurationForKey(long duration,
                                     java.lang.String key)
Adds the specified duration in milliseconds for the given key.

Parameters:
duration - the duration in milliseconds of the operation
key - the name to log the time under

addDurationForKey

public static void addDurationForKey(long duration,
                                     java.lang.String group,
                                     java.lang.String key)
Adds the specified duration in milliseconds for the given key.

Parameters:
duration - the duration in milliseconds of the operation
key - the name to log the time under

reset

public static void reset()
Resets statistics for this thread AND the global queue.


logStatisticsForOperation

public static void logStatisticsForOperation(java.lang.String operation)
Logs the messages since the last call to initStatistics() ordered by some key.

Parameters:
operation - operation to sort on ("sum", "count", "min", "max", "avg")

logStatisticsForOperation

public static void logStatisticsForOperation(org.apache.log4j.Logger statsLog,
                                             java.lang.String operation)
Logs the messages since the last call to initStatistics() ordered by some key. Note that no log message is output if there aren't any values

Parameters:
operation - operation to sort on ("sum", "count", "min", "max", "avg", "key")

Last updated: Tue, Feb 21, 2017 • 05:45 PM CET

Copyright © 2002 – 2007 Project Wonder.