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). 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;
}
Name | Description |
---|---|
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) |
Modifier and Type | Class and Description |
---|---|
static interface |
ERXStats.Group |
static class |
ERXStats.LogEntry
A statistics logging entry.
|
Modifier and Type | Field and Description |
---|---|
static Logger |
log |
static String |
STATS_ENABLED_KEY |
static String |
STATS_TRACE_COLLECTING_ENABLED_KEY |
Constructor and Description |
---|
ERXStats() |
Modifier and Type | Method and Description |
---|---|
static void |
addDurationForKey(long duration,
String key)
Adds the specified duration in milliseconds for the given key.
|
static void |
addDurationForKey(long duration,
String group,
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 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 ERXStats.LogEntry |
logEntryForKey(String group,
String key)
Returns the log entry for the given key within the specified logging group.
|
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 |
markEnd(String group,
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 |
markStart(String group,
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() |
public static final String STATS_ENABLED_KEY
public static final String STATS_TRACE_COLLECTING_ENABLED_KEY
public static final Logger log
public static void initStatisticsIfNecessary()
public static boolean traceCollectingEnabled()
public static void initStatistics()
public static boolean isTrackingStatistics()
public static NSMutableDictionary<String,ERXStats.LogEntry> statistics()
public static ERXStats.LogEntry logEntryForKey(String key)
key
- the key to lookuppublic static ERXStats.LogEntry logEntryForKey(String group, String key)
group
- the logging group to search for the keykey
- the key to lookuppublic static NSSet<String> aggregateKeys()
public static NSArray<ERXStats.LogEntry> aggregateLogEntries()
public static void markStart(String group, String key)
key
- the key log to start loggingpublic static void markStart(String key)
key
- the key log to start loggingpublic static void markEnd(String group, String key)
key
- the key to log underpublic static void markEnd(String key)
key
- the key to log underpublic static void addDurationForKey(long duration, String key)
duration
- the duration in milliseconds of the operationkey
- the name to log the time underpublic static void addDurationForKey(long duration, String group, String key)
duration
- the duration in milliseconds of the operationkey
- the name to log the time underpublic static void reset()
public static void logStatisticsForOperation(String operation)
operation
- operation to sort on ("sum", "count", "min", "max", "avg")public static void logStatisticsForOperation(Logger statsLog, String operation)
operation
- operation to sort on ("sum", "count", "min", "max", "avg", "key")Copyright © 2002 – 2020 Project Wonder.