diff options
author | Tim King <taking@cs.nyu.edu> | 2010-11-03 01:07:09 +0000 |
---|---|---|
committer | Tim King <taking@cs.nyu.edu> | 2010-11-03 01:07:09 +0000 |
commit | a7f99ba2844707d1b405e1cd3c01404c9e43850a (patch) | |
tree | adb6be28f09ebe69be438cb547190d888b89b61a /src | |
parent | e4c89b3d2d1f036ec6aff07575a074ea30a30747 (diff) |
Adds AverageStat to stats.h.
Diffstat (limited to 'src')
-rw-r--r-- | src/util/stats.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/util/stats.h b/src/util/stats.h index d6b463e65..02b642939 100644 --- a/src/util/stats.h +++ b/src/util/stats.h @@ -263,6 +263,32 @@ public: };/* class IntStat */ +/** + * The value for an AverageStat is the running average of (e1, e_2, ..., e_n), + * (e1 + e_2 + ... + e_n)/n, + * where e_i is an entry added by an addEntry(e_i) call. + * The value is initially always 0. + * (This is to avoid making parsers confused.) + */ +class AverageStat : public BackedStat<double> { +private: + uint32_t n; + +public: + AverageStat(const std::string& s) : + BackedStat<double>(s, 0.0 ), n(0) { + } + + void addEntry(double e){ + double oldSum = n*getData(); + ++n; + double newSum = oldSum + e; + setData(newSum / n); + } + +};/* class AverageStat */ + + // some utility functions for ::timespec inline ::timespec& operator+=(::timespec& a, const ::timespec& b) { // assumes a.tv_nsec and b.tv_nsec are in range |