Inherits: ICounters, IReconfigurable, ICounterTimingCallback
Description
The CachedCounters class allows you to create performace counters that measure and store those values in memory.
Important points
- Child classes can implement saving of the counters into various different destinations.
Configuration parameters
options:
- interval: interval in milliseconds to save current counters measurements (default: 5 mins)
- reset_timeout: timeout in milliseconds to reset the counters. 0 disables the reset (default: 0)
Constructors
Creates a new CachedCounters object.
public
CachedCounters()
Fields
Instance methods
BeginTiming
Begins measurement of execution time interval. It returns CounterTiming object which has to be called at CounterTiming.EndTiming to end the measurement and update the counter.
public
CounterTiming BeginTiming(string name)
- name: string - a counter name of Interval type.
- returns: CounterTiming - a callback object to end timing.
Clear
Clears (resets) a counter specified by its name.
public
void Clear(string name)
- name: string - a counter name to clear.
ClearAll
Clears (resets) all counters.
public
void ClearAll()
Configure
Configures component by passing configuration parameters.
public virtual
void Configure(ConfigParams config)
- config: ConfigParams - configuration parameters to be set.
Dump
Dumps (saves) the current values of counters.
public
void Dump()
EndTiming
Ends measurement of execution elapsed time and updates specified counter.
public
void EndTiming(string name, double elapsed)
- name: string - counter name
- elapsed: double - execution elapsed time in milliseconds to update the counter.
Get
Gets a counter specified by its name. It counter does not exist or its type doesn’t match the specified type it creates a new one.
public
Counter Get(string name, CounterType type)
- name: string - a counter name to retrieve.
- typ: CounterType - counter type.
- returns: Counter - existing or newly created counter of the specified type.
GetAll
Gets all captured counters.
public
IEnumerable<Counter> GetAll()
- returns: IEnumerable<Counter> - list with counters.
Increment
Increments counter by a given value.
public
void Increment(string name, int value)
- name: string - counter name of Increment type.
- value: int - value to add to the counter.
IncrementOne
Increments counter by 1.
public
void IncrementOne(string name)
- name: string - counter name of Increment type.
Last
Records the last calculated measurement value. Usually this method is used by metrics calculated externally.
public
Last(string name, float value)
- name: string - counter name of Last type.
- value: float - last value to record.
Stats
Calculates min/average/max statistics based on the current and previous values.
public
void Stats(string name, float value)
- name: string - counter name of Statistics type
- value: float - value to update statistics
Timestamp
Records the given timestamp.
public
void Timestamp(string name, DateTime value)
- name: string - counter’s name of Timestamp type.
- value: DateTime - timestamp to record.
TimestampNow
Records the current time as a timestamp.
public
void TimestampNow(string name)
- name: string - counter’s name of Timestamp type.
Update
Makes counter measurements as updated and dumps them when timeout expires.
protected
void Update()
Abstract methods
Save
Saves the current counters' measurements.
protected abstarct
void Save(IEnumerable<Counter> counters)
- counters: IEnumerable<Counter> - current counters' measurements to be saved.