AceCommon  1.4.6
Arduino library for low-level common functions and features with no external dependencies
Public Member Functions | List of all members
ace_common::GenericStats< T > Class Template Reference

Helper class to collect timing statistics such as min, max, average, and exponential-decay average. More...

#include <GenericStats.h>

Public Member Functions

 GenericStats ()
 Constructor. More...
 
 GenericStats (const GenericStats &)=default
 Default copy constructor.
 
GenericStatsoperator= (const GenericStats &)=default
 Default assignment operator.
 
void reset ()
 Reset the object to its initial state, except mCounter which is never reset.
 
getMax () const
 Return the maximum since the last reset().
 
getMin () const
 Return the minium since the last reset().
 
getAvg () const
 Return the average since the last reset(). More...
 
getExpDecayAvg () const
 An exponential decay average since the last reset().
 
uint16_t getCount () const
 Number of times update() was called since last reset().
 
uint16_t getCounter () const
 Number of times update() was called from the beginning of time. More...
 
void update (T value)
 Add the given value to the statistics.
 

Detailed Description

template<typename T>
class ace_common::GenericStats< T >

Helper class to collect timing statistics such as min, max, average, and exponential-decay average.

The internal sum variable is also a type T, so it is important to watch out for overflow of the sum. Keeping the number of samples relatively small helps with preventing overflows.

See also TimingStats which is the original version of this class, specialized to tracking a uint16_t quantity.

Template Parameters
Ttype of the quantity being gathered (e.g. uint32_t or float)

Definition at line 44 of file GenericStats.h.

Constructor & Destructor Documentation

◆ GenericStats()

template<typename T >
ace_common::GenericStats< T >::GenericStats ( )
inline

Constructor.

Calls reset().

Definition at line 47 of file GenericStats.h.

Member Function Documentation

◆ getAvg()

template<typename T >
T ace_common::GenericStats< T >::getAvg ( ) const
inline

Return the average since the last reset().

Returns 0 if update() has never been called.

Definition at line 82 of file GenericStats.h.

◆ getCounter()

template<typename T >
uint16_t ace_common::GenericStats< T >::getCounter ( ) const
inline

Number of times update() was called from the beginning of time.

Never reset. This is useful to determining how many times update() was called since it was last checked from the client code.

Definition at line 95 of file GenericStats.h.


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