762aa0d5cdca000980f1ce06745df8a2f023b361
[senf.git] / senf / Utils / Statistics.cci
1 // $Id$
2 //
3 // Copyright (C) 2008
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief Statistics inline non-template implementation */
25
26 //#include "Statistics.ih"
27
28 // Custom includes
29 #include <float.h>
30 #include "Range.hh"
31
32 #define prefix_ inline
33 //-/////////////////////////////////////////////////////////////////////////////////////////////////
34
35 //-/////////////////////////////////////////////////////////////////////////////////////////////////
36 // senf::StatisticsBase::Transform
37
38 prefix_ senf::StatisticsBase::Transform::result_type
39 senf::StatisticsBase::Transform::operator()(first_argument_type i)
40     const
41 {
42     return i.second;
43 }
44
45 //-/////////////////////////////////////////////////////////////////////////////////////////////////
46 // senf::StatisticsBase::OutputEntry
47
48 prefix_ senf::StatisticsBase::OutputEntry::OutputEntry()
49     : n(), min(), avg(), max(), dev()
50 {
51     initDir();
52 }
53
54 prefix_ senf::StatisticsBase::OutputEntry::OutputEntry(unsigned n_)
55     : n(n_), min(), avg(), max(), dev()
56 {
57     initDir();
58 }
59
60 prefix_ senf::StatisticsBase::OutputEntry::OutputEntry(const OutputEntry& other)
61     : n(other.n), min(other.min), avg(other.avg), max(other.max), dev(other.dev)
62 {
63     initDir();
64 }
65
66 prefix_ void senf::StatisticsBase::OutputEntry::initDir()
67 {
68     namespace fty = senf::console::factory;
69
70     dir.add("list", fty::Command(&OutputEntry::consoleList, this)
71             .doc("List all known connected targets. This list might not be complete.") );
72 }
73
74 prefix_ senf::StatisticsBase::OutputEntry &
75 senf::StatisticsBase::OutputEntry::operator=(const OutputEntry& other)
76 {
77     n = other.n;
78     min = other.min;
79     avg = other.avg;
80     max = other.max;
81     dev = other.dev;
82     return *this;
83 }
84
85 //-/////////////////////////////////////////////////////////////////////////////////////////////////
86 // senf::StatisticsBase
87
88 prefix_ senf::StatisticsBase::StatisticsBase()
89     : min_ (0.0f), avg_ (0.0f), max_ (0.0f), dev_ (0.0f), maxQueueLen_ (0u)
90 {}
91
92 prefix_ senf::StatisticsBase::~StatisticsBase()
93 {}
94
95 prefix_ senf::StatisticsBase::CollectorRange senf::StatisticsBase::collectors()
96 {
97     return senf::make_transform_range(children_, Transform());
98 }
99
100 prefix_ float senf::StatisticsBase::min()
101     const
102 {
103     return min_;
104 }
105
106 prefix_ float senf::StatisticsBase::avg()
107     const
108 {
109     return avg_;
110 }
111
112 prefix_ float senf::StatisticsBase::max()
113     const
114 {
115     return max_;
116 }
117
118 prefix_ float senf::StatisticsBase::dev()
119     const
120 {
121     return dev_;
122 }
123
124 prefix_ unsigned senf::StatisticsBase::rank()
125     const
126 {
127     return 1;
128 }
129
130 prefix_ senf::Statistics & senf::StatisticsBase::base()
131 {
132     return v_base();
133 }
134
135 prefix_ std::string senf::StatisticsBase::path()
136     const
137 {
138     return v_path();
139 }
140
141 //-/////////////////////////////////////////////////////////////////////////////////////////////////
142 // senf::Collector
143
144 prefix_ senf::Collector::Collector(StatisticsBase * owner, unsigned rank)
145     : rank_ (rank), i_ (0u), accMin_ (FLT_MAX), accSum_ (0.0f), accSumSq_ (0.0f), accMax_ (-FLT_MAX),
146       owner_ (owner)
147 {}
148
149 prefix_ unsigned senf::Collector::rank()
150     const
151 {
152     return rank_;
153 }
154
155 prefix_ senf::StatisticsBase::OutputProxy<senf::Collector>
156 senf::Collector::output(unsigned n)
157 {
158
159     return StatisticsBase::OutputProxy<Collector>(this, StatisticsBase::output(n));
160 }
161
162 //-/////////////////////////////////////////////////////////////////////////////////////////////////
163 // senf::Statistics
164
165 prefix_ void senf::Statistics::operator()(unsigned n, float min, float avg, float max,
166                                           float dev)
167 {
168     enter(n, min, avg, max, dev);
169 }
170
171 prefix_ void senf::Statistics::operator()(float min, float avg, float max, float dev)
172 {
173     enter(1, min, avg, max, dev);
174 }
175
176 prefix_ void senf::Statistics::operator()(StatisticsData const & data)
177 {
178   enter(1, data.min, data.avg, data.max, data.stddev);
179 }
180
181 prefix_ void senf::Statistics::operator()(float value, float dev)
182 {
183     enter(1, value, value, value, dev);
184 }
185
186
187 prefix_ senf::StatisticsBase::OutputProxy<senf::Statistics>
188 senf::Statistics::output(unsigned n)
189 {
190     return StatisticsBase::OutputProxy<Statistics>(this, StatisticsBase::output(n));
191 }
192
193 //-/////////////////////////////////////////////////////////////////////////////////////////////////
194 #undef prefix_
195
196 \f
197 // Local Variables:
198 // mode: c++
199 // fill-column: 100
200 // comment-column: 40
201 // c-file-style: "senf"
202 // indent-tabs-mode: nil
203 // ispell-local-dictionary: "american"
204 // compile-command: "scons -u test"
205 // End: