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