StatisticAccumulator.cc
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 
14 #include "StatisticAccumulator.hh"
15 
16 // Custom includes
17 #include <ostream>
18 #include "Format.hh"
19 
20 #define prefix_
21 //-/////////////////////////////////////////////////////////////////////////////////////////////////
22 
24 {
25  min = max = NAN;
26  avg = stddev = NAN;
27  cnt = 0;
28 }
29 
30 std::ostream & senf::operator<<(std::ostream & os, senf::StatisticsData const & _data)
31 {
32  if (_data.cnt > 0) {
33  os << "(" << "#" << _data.cnt;
34  os << ";" << format::eng(_data.min).setprecision(5);
35  os << ";" << format::eng(_data.avg, _data.stddev).setprecision(5);
36  os << ";" << format::eng(_data.max).setprecision(5);
37  os << ")";
38  } else {
39  os << "(no-data)";
40  }
41  return os;
42 };
43 
44 prefix_ boost::property_tree::ptree senf::StatisticsData::asPTree()
45  const
46 {
47  boost::property_tree::ptree localelement;
48  if (cnt > 0) {
49  localelement.put("avg", avg);
50  localelement.put("stddev", stddev);
51  localelement.put("min", min);
52  localelement.put("max", max);
53  localelement.put("cnt", cnt);
54  } else {
55  localelement.put("avg", "NaN");
56  localelement.put("stddev", "NaN");
57  localelement.put("min", "NaN");
58  localelement.put("max", "NaN");
59  localelement.put("cnt", 0u);
60  }
61  return localelement;
62 }
63 
64 //-/////////////////////////////////////////////////////////////////////////////////////////////////
65 #undef prefix_
Format public header.
StatisticAccumulator public header.
streamable_type eng(float v, float d=NAN)
Format value in engineering representation.
std::ostream & operator<<(std::ostream &os, CpuStat const &cs)
Definition: CpuStat.cc:103
#define prefix_
boost::property_tree::ptree asPTree() const