StatisticAccumulator.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 #ifndef HH_SENF_Utils_StatisticAccumulator_
18 #define HH_SENF_Utils_StatisticAccumulator_ 1
19 
20 // Custom includes
21 #include <math.h>
22 #include <iosfwd>
23 #include <boost/operators.hpp>
24 #include <boost/property_tree/json_parser.hpp>
25 
27 namespace senf {
28 
30  : public boost::less_than_comparable<StatisticsData>
31  {
33  StatisticsData(float min_, float avg_, float max_, float stddev_, unsigned cnt_);
34  StatisticsData(float singleValue);
35 
36  void clear();
37 
38  explicit operator bool() const;
39  bool operator<(StatisticsData const & other) const;
40 
41  boost::property_tree::ptree asPTree() const;
42 
43  float min;
44  float avg;
45  float max;
46  float stddev;
47  unsigned cnt;
48  };
49 
50  std::ostream & operator<<(std::ostream & os, StatisticsData const & _data);
51 
52 
67  template <class T>
69  {
70  public:
72  StatisticAccumulator(T const & value);
73  StatisticAccumulator(T const & sum, T const & sumSquared, T const & min, T const & max, unsigned count);
75 
76  void clear();
77 
78  void accumulate(T const & value);
79 
82  T min() const;
83 
85  T max() const;
86 
88  T sum() const;
89 
91  T sum2() const;
92 
94  float avg() const;
95 
97  float rms() const;
98 
100  float stddev() const;
101 
103  unsigned count() const;
104 
106  void data(StatisticsData & data_) const;
108 
110  StatisticsData data() const;
111 
114  explicit operator bool() const;
115 
117  StatisticAccumulator<T> operator +=(StatisticAccumulator<T> const & other);
118  StatisticAccumulator<T> operator*=(const float & scale);
119 
120  private:
121  T sum_;
122  T sum_squared_;
123  T min_;
124  T max_;
125  unsigned cnt_;
126  };
127 
128  template <class T>
130  : public boost::less_than_comparable<StatisticsEWMA<T>>
131  {
132  public:
133  StatisticsEWMA(float alpha = 0.25f, T const & value = T());
134 
135  void clear(T const & value = T());
136 
137  void accumulate(T const & value);
138  void accumulateWithLoss(T const & value, unsigned numLost);
139 
140  bool operator<(StatisticsEWMA<T> const & other) const;
141 
142  explicit operator bool() const;
143 
145  unsigned count() const;
146 
148  T const & ewma() const;
149 
150  float const & alpha() const;
151 
152  private:
153  T ewma_;
154  float alpha_;
155  unsigned cnt_;
156  };
157 
158 }
159 
161 #include "StatisticAccumulator.cci"
162 #include "StatisticAccumulator.ct"
163 #include "StatisticAccumulator.cti"
164 #endif
165 
Accumulate measurement values.
bool operator<(StatisticsData const &other) const
u8 data[SPECTRAL_HT20_NUM_BINS]
std::uint64_t sum2
std::ostream & operator<<(std::ostream &os, CpuStat const &cs)
Definition: CpuStat.cc:103
std::uint32_t count
std::int32_t sum
boost::property_tree::ptree asPTree() const