Statistics.cci
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 /** \file
15  \brief Statistics inline non-template implementation */
16 
17 //#include "Statistics.ih"
18 
19 // Custom includes
20 #include <float.h>
21 #include <senf/Utils/Console/ParsedCommand.hh>
22 #include "Range.hh"
23 
24 #define prefix_ inline
25 //-/////////////////////////////////////////////////////////////////////////////////////////////////
26 
27 //-/////////////////////////////////////////////////////////////////////////////////////////////////
28 // senf::StatisticsBase::Transform
29 
30 prefix_ senf::StatisticsBase::Transform::result_type
31 senf::StatisticsBase::Transform::operator()(first_argument_type i)
32  const
33 {
34  return i.second;
35 }
36 
37 prefix_ senf::StatisticsBase::ConstTransform::result_type
38 senf::StatisticsBase::ConstTransform::operator()(first_argument_type i)
39  const
40 {
41  return i.second;
42 }
43 
44 //-/////////////////////////////////////////////////////////////////////////////////////////////////
45 // senf::StatisticsBase::OutputEntry
46 
47 prefix_ senf::StatisticsBase::OutputEntry::OutputEntry()
48  : n(), cnt(), min(), avg(), max(), dev()
49 {
50  initDir();
51 }
52 
53 prefix_ senf::StatisticsBase::OutputEntry::OutputEntry(unsigned n_)
54  : n(n_), cnt(), min(), avg(), max(), dev()
55 {
56  initDir();
57 }
58 
59 prefix_ senf::StatisticsBase::OutputEntry::OutputEntry(const OutputEntry& other)
60  : n(other.n), cnt(other.cnt), min(other.min), avg(other.avg), max(other.max), dev(other.dev)
61 {
62  initDir();
63 }
64 
65 prefix_ void senf::StatisticsBase::OutputEntry::initDir()
66 {
67  dir.add("list", console::factory::Command(&OutputEntry::consoleList, this)
68  .doc("List all known connected targets. This list might not be complete.") );
69 }
70 
71 prefix_ senf::StatisticsBase::OutputEntry &
72 senf::StatisticsBase::OutputEntry::operator=(const OutputEntry& other)
73 {
74  n = other.n;
75  cnt = other.cnt;
76  min = other.min;
77  avg = other.avg;
78  max = other.max;
79  dev = other.dev;
80  return *this;
81 }
82 
83 //-/////////////////////////////////////////////////////////////////////////////////////////////////
84 // senf::StatisticsBase
85 
86 prefix_ senf::StatisticsBase::StatisticsBase()
87  : cnt_(0), min_ (0.0f), avg_ (0.0f), max_ (0.0f), dev_ (0.0f), maxQueueLen_ (0u)
88 {}
89 
90 prefix_ senf::StatisticsBase::~StatisticsBase()
91 {}
92 
93 prefix_ senf::StatisticsBase::const_CollectorRange senf::StatisticsBase::collectors()
94  const
95 {
96  return senf::make_transform_range(children_, ConstTransform());
97 }
98 
99 prefix_ senf::StatisticsBase::CollectorRange senf::StatisticsBase::collectors()
100 {
101  return senf::make_transform_range(children_, Transform());
102 }
103 
104 prefix_ unsigned senf::StatisticsBase::cnt()
105  const
106 {
107  return cnt_;
108 }
109 
110 prefix_ float senf::StatisticsBase::min()
111  const
112 {
113  return min_;
114 }
115 
116 prefix_ float senf::StatisticsBase::avg()
117  const
118 {
119  return avg_;
120 }
121 
122 prefix_ float senf::StatisticsBase::max()
123  const
124 {
125  return max_;
126 }
127 
128 prefix_ float senf::StatisticsBase::dev()
129  const
130 {
131  return dev_;
132 }
133 
134 prefix_ unsigned senf::StatisticsBase::rank()
135  const
136 {
137  return 1;
138 }
139 
140 prefix_ senf::Statistics & senf::StatisticsBase::base()
141 {
142  return v_base();
143 }
144 
145 prefix_ senf::Statistics const & senf::StatisticsBase::base()
146  const
147 {
148  return const_cast<StatisticsBase *>(this)->v_base();
149 }
150 
151 prefix_ std::string senf::StatisticsBase::path()
152  const
153 {
154  return v_path();
155 }
156 
157 prefix_ senf::StatisticsData senf::StatisticsBase::data()
158  const
159 {
160  return StatisticsData(min_, avg_, max_, dev_, cnt_);
161 }
162 
163 //-/////////////////////////////////////////////////////////////////////////////////////////////////
164 // senf::Collector
165 
166 prefix_ senf::Collector::Collector(StatisticsBase * owner, unsigned rank)
167  : rank_ (rank), i_ (0u), l_(0u), accCnt_(0), accMin_ (FLT_MAX), accSum_ (0.0f), accSumSq_ (0.0f), accMax_ (-FLT_MAX),
168  owner_ (owner), updated_(false)
169 {}
170 
171 prefix_ unsigned senf::Collector::rank()
172  const
173 {
174  return rank_;
175 }
176 
177 prefix_ bool senf::Collector::updated()
178  const
179 {
180  return updated_;
181 }
182 
183 
184 prefix_ senf::StatisticsBase::OutputProxy<senf::Collector>
185 senf::Collector::output(unsigned n)
186 {
187 
188  return StatisticsBase::OutputProxy<Collector>(this, StatisticsBase::output(n));
189 }
190 
191 //-/////////////////////////////////////////////////////////////////////////////////////////////////
192 // senf::Statistics
193 
194 prefix_ void senf::Statistics::operator()(unsigned n, unsigned cnt, float min, float avg, float max,
195  float dev)
196 {
197  enter(n, cnt, min, avg, max, dev);
198 }
199 
200 prefix_ void senf::Statistics::operator()(unsigned cnt, float min, float avg, float max, float dev)
201 {
202  enter(1, cnt, min, avg, max, dev);
203 }
204 
205 prefix_ void senf::Statistics::operator()(StatisticsData const & data)
206 {
207  enter(1, data.cnt, data.min, data.avg, data.max, data.stddev);
208 }
209 
210 prefix_ void senf::Statistics::operator()(unsigned cnt, float value, float dev)
211 {
212  enter(1, cnt, value, value, value, dev);
213 }
214 
215 
216 prefix_ senf::StatisticsBase::OutputProxy<senf::Statistics>
217 senf::Statistics::output(unsigned n)
218 {
219  return StatisticsBase::OutputProxy<Statistics>(this, StatisticsBase::output(n));
220 }
221 
222 //-/////////////////////////////////////////////////////////////////////////////////////////////////
223 #undef prefix_
224 
225 
226 // Local Variables:
227 // mode: c++
228 // fill-column: 100
229 // comment-column: 40
230 // c-file-style: "senf"
231 // indent-tabs-mode: nil
232 // ispell-local-dictionary: "american"
233 // compile-command: "scons -u test"
234 // End: