Click
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
RateEWMAX< P > Class Template Reference

An exponentially weighted moving average used to measure a rate. More...

#include <click/ewma.hh>

Inherits P.

Public Types

typedef P::value_type value_type
 
typedef P::signed_value_type signed_value_type
 

Public Member Functions

 RateEWMAX ()
 Create a rate EWMA with initial value(s) 0.
 
signed_value_type scaled_average (unsigned ratenum=0) const
 Return the current scaled moving average.
 
unsigned scale (unsigned ratenum=0) const
 Returns one of the average's scaling factors (bits of fraction).
 
int rate (unsigned ratenum=0) const
 Return the current rate in samples per second.
 
void update (signed_value_type delta, unsigned ratenum=0)
 Update the sample count for the current epoch.
 
String unparse_rate (unsigned ratenum=0) const
 Unparse the current average into a String.
 

Detailed Description

template<typename P>
class RateEWMAX< P >

An exponentially weighted moving average used to measure a rate.

The RateEWMAX template class represents an exponentially weighted moving average that measures a rate: a count of events per unit time. The average starts out with value 0.

RateEWMAX adds to DirectEWMAX a concept of epochs, which are periods of time. A RateEWMAX object collects samples over the current epoch. When the epoch closes, the collected sample count is used to update the moving average. Thus, the moving average is measured in samples per epoch. The rate() and unparse_rate() member functions return the rate in samples per second, rather than per epoch. These functions use the epoch frequency to translate between epochs and seconds.

Note that it often makes sense to call update() before calling scaled_average(), rate(), or unparse_rate(), in case an epoch or two has passed and the average should take account of passing time.

The template parameter P defines the EWMA parameters required by DirectEWMAX, and three others: a rate count, an epoch measurement, and an epoch frequency.

The rate count is the number of rates measured per object. Usually it is 1.

The epoch measurement is a function that returns the current epoch as an unsigned number. Epochs should increase monotonically.

The epoch frequency is the number of epochs per second, and is only used by rate() and unparse_rate().

These are defined by:

P::rate_count

The rate count, as a static constant (for example, defined by an enum).

unsigned P::epoch()

This function returns the current epoch number.

unsigned P::epoch_frequency()
This function returns the number of epochs per second.

Since RateEWMAX inherits from an object of type P, these members are also directly available to callers.

The RateEWMAXParameters type is a good template argument for RateEWMAX.

See also
DirectEWMAX

Constructor & Destructor Documentation

◆ RateEWMAX()

template<typename P >
RateEWMAX< P >::RateEWMAX ( )
inline

Create a rate EWMA with initial value(s) 0.

Member Function Documentation

◆ scaled_average()

template<typename P >
signed_value_type RateEWMAX< P >::scaled_average ( unsigned  ratenum = 0) const
inline

Return the current scaled moving average.

Parameters
ratenumrate index (0 <= ratenum < rate_count)
Note
The returned value has scale() bits of fraction.
scaled_average() does not check the current epoch. If an epoch might have passed since the last update(), you should call update(0, ratenum) before calling this function.

◆ scale()

template<typename P >
unsigned RateEWMAX< P >::scale ( unsigned  ratenum = 0) const
inline

Returns one of the average's scaling factors (bits of fraction).

◆ rate()

template<typename P >
int RateEWMAX< P >::rate ( unsigned  ratenum = 0) const
inline

Return the current rate in samples per second.

Parameters
ratenumrate index (0 <= ratenum < rate_count)
Note
The returned value is unscaled.
rate() does not check the current epoch. If an epoch might have passed since the last update(), you should call update(0, ratenum) before calling this function.

◆ update()

template<typename P >
void RateEWMAX< P >::update ( signed_value_type  delta,
unsigned  ratenum = 0 
)
inline

Update the sample count for the current epoch.

Parameters
deltaincrement for current epoch sample count
ratenumrate index (0 <= ratenum < rate_count)
Note
If the epoch has changed since the last update(), this function applies the last epoch's sample count (if any) to the relevant moving average, accounts for any passage of time (in case one or more epochs have passed with no samples), and clears the sample count for the new epoch.

◆ unparse_rate()

template<typename P >
String RateEWMAX< P >::unparse_rate ( unsigned  ratenum = 0) const
inline

Unparse the current average into a String.

Parameters
ratenumrate index (0 <= ratenum < rate_count)
Note
The returned value is unscaled, but may contain a fractional part.
unparse_rate() does not check the current epoch. If an epoch might have passed since the last update(), you should call update(0, ratenum) before calling this function.

The documentation for this class was generated from the following file: