d522f9fb3d62dbccc7960380abab06dc6d0ed322
[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 prefix_ void senf::StatisticsBase::OutputEntry::consoleList(std::ostream & os)
86 {
87     for (boost::ptr_vector<TargetBase>::iterator i (targets_.begin());
88          i != targets_.end(); ++i)
89         if (! i->label.empty())
90             os << i->label << "\n";
91 }
92
93 //-/////////////////////////////////////////////////////////////////////////////////////////////////
94 // senf::StatisticsBase
95
96 prefix_ senf::StatisticsBase::StatisticsBase()
97     : min_ (0.0f), avg_ (0.0f), max_ (0.0f), dev_ (0.0f), maxQueueLen_ (0u)
98 {}
99
100 prefix_ senf::StatisticsBase::~StatisticsBase()
101 {}
102
103 prefix_ senf::StatisticsBase::CollectorRange senf::StatisticsBase::collectors()
104 {
105     return senf::make_transform_range(children_, Transform());
106 }
107
108 prefix_ float senf::StatisticsBase::min()
109     const
110 {
111     return min_;
112 }
113
114 prefix_ float senf::StatisticsBase::avg()
115     const
116 {
117     return avg_;
118 }
119
120 prefix_ float senf::StatisticsBase::max()
121     const
122 {
123     return max_;
124 }
125
126 prefix_ float senf::StatisticsBase::dev()
127     const
128 {
129     return dev_;
130 }
131
132 prefix_ unsigned senf::StatisticsBase::rank()
133     const
134 {
135     return 1;
136 }
137
138 prefix_ senf::Statistics & senf::StatisticsBase::base()
139 {
140     return v_base();
141 }
142
143 prefix_ std::string senf::StatisticsBase::path()
144     const
145 {
146     return v_path();
147 }
148
149 //-/////////////////////////////////////////////////////////////////////////////////////////////////
150 // senf::Collector
151
152 prefix_ senf::Collector::Collector(StatisticsBase * owner, unsigned rank)
153     : rank_ (rank), i_ (0u), accMin_ (FLT_MAX), accSum_ (0.0f), accSumSq_ (0.0f), accMax_ (-FLT_MAX),
154       owner_ (owner)
155 {}
156
157 prefix_ unsigned senf::Collector::rank()
158     const
159 {
160     return rank_;
161 }
162
163 prefix_ senf::StatisticsBase::OutputProxy<senf::Collector>
164 senf::Collector::output(unsigned n)
165 {
166
167     return StatisticsBase::OutputProxy<Collector>(this, StatisticsBase::output(n));
168 }
169
170 //-/////////////////////////////////////////////////////////////////////////////////////////////////
171 // senf::Statistics
172
173 prefix_ void senf::Statistics::operator()(unsigned n, float min, float avg, float max,
174                                           float dev)
175 {
176     enter(n, min, avg, max, dev);
177 }
178
179 prefix_ void senf::Statistics::operator()(float min, float avg, float max, float dev)
180 {
181     enter(1, min, avg, max, dev);
182 }
183
184 prefix_ void senf::Statistics::operator()(float value, float dev)
185 {
186     enter(1, value, value, value, dev);
187 }
188
189
190 prefix_ senf::StatisticsBase::OutputProxy<senf::Statistics>
191 senf::Statistics::output(unsigned n)
192 {
193     return StatisticsBase::OutputProxy<Statistics>(this, StatisticsBase::output(n));
194 }
195
196 //-/////////////////////////////////////////////////////////////////////////////////////////////////
197 #undef prefix_
198
199 \f
200 // Local Variables:
201 // mode: c++
202 // fill-column: 100
203 // comment-column: 40
204 // c-file-style: "senf"
205 // indent-tabs-mode: nil
206 // ispell-local-dictionary: "american"
207 // compile-command: "scons -u test"
208 // End: