summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/util/stats.h26
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
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback