Project Wonder 5.0.0.8794

er.extensions.statistics
Class ERXStats

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

public class ERXStats
extends 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). DO 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); try { value = super.valueForKeyPath(keyPath); } finally { 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.max the maximum historical stats to collect (defaults to 1000)
           

Nested Class Summary
static class ERXStats.LogEntry
           
 
Field Summary
static Logger log
           
 
Constructor Summary
ERXStats()
           
 
Method Summary
static void addDurationForKey(long duration, String key)
          Adds the specified duration in milliseconds for the given key.
static NSSet<String> aggregateKeys()
          Returns the aggregate key names for all of the threads that have been recorded.
static 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 ERXStats.LogEntry aggregateLogEntryForKey(String key)
          Returns a LogEntry that represents the aggregate data collected for the given key in all of the recorded threads.
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(String key)
          Returns the log entry for the given key.
static void logStatisticsForOperation(Logger statsLog, String operation)
          Logs the messages since the last call to initStatistics() ordered by some key.
static void logStatisticsForOperation(String operation)
          Logs the messages since the last call to initStatistics() ordered by some key.
static void markEnd(String key)
          Marks the end of a process, and calls addDuration(..) with the time since markStart.
static void markStart(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 NSMutableDictionary<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

log

public static final 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 all 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 NSMutableDictionary<String,ERXStats.LogEntry> statistics()
Returns the statistics for the current thread.

Returns:
the statistics for the current thread

logEntryForKey

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

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

aggregateKeys

public static NSSet<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

aggregateLogEntryForKey

public static ERXStats.LogEntry aggregateLogEntryForKey(String key)
Returns a LogEntry that represents the aggregate data collected for the given key in all of the recorded threads.

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

aggregateLogEntries

public static 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(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(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,
                                     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(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(Logger statsLog,
                                             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")

Last updated: Thu, Jan 8, 2009 • 12:32 PM EST

Copyright © 2002 – 2007 Project Wonder.