3570
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
|
2 |
/*
|
|
3 |
* Copyright (c) 2008 Drexel University
|
|
4 |
*
|
|
5 |
* This program is free software; you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License version 2 as
|
|
7 |
* published by the Free Software Foundation;
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
15 |
* along with this program; if not, write to the Free Software
|
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
17 |
*
|
|
18 |
* Author: Joe Kopena (tjkopena@cs.drexel.edu)
|
|
19 |
*/
|
|
20 |
|
|
21 |
#ifndef __BASIC_DATA_CALCULATORS_H__
|
|
22 |
#define __BASIC_DATA_CALCULATORS_H__
|
|
23 |
|
|
24 |
#include "data-calculator.h"
|
|
25 |
#include "data-output-interface.h"
|
|
26 |
|
|
27 |
namespace ns3 {
|
|
28 |
|
|
29 |
//------------------------------------------------------------
|
|
30 |
//--------------------------------------------
|
|
31 |
template <typename T = uint32_t>
|
|
32 |
class MinMaxAvgTotalCalculator : public DataCalculator {
|
|
33 |
public:
|
|
34 |
MinMaxAvgTotalCalculator();
|
|
35 |
virtual ~MinMaxAvgTotalCalculator();
|
|
36 |
|
|
37 |
void Update(const T i);
|
|
38 |
|
|
39 |
virtual void Output(DataOutputCallback &callback) const;
|
|
40 |
|
|
41 |
protected:
|
|
42 |
virtual void DoDispose(void);
|
|
43 |
|
|
44 |
uint32_t m_count;
|
|
45 |
T m_total, m_min, m_max;
|
|
46 |
|
|
47 |
// end MinMaxAvgTotalCalculator
|
|
48 |
};
|
|
49 |
|
|
50 |
//----------------------------------------------
|
|
51 |
template <typename T>
|
|
52 |
MinMaxAvgTotalCalculator<T>::MinMaxAvgTotalCalculator()
|
|
53 |
{
|
|
54 |
m_count = 0;
|
|
55 |
m_total = 0;
|
|
56 |
m_min = ~0;
|
|
57 |
m_max = 0;
|
|
58 |
}
|
|
59 |
|
|
60 |
template <typename T>
|
|
61 |
MinMaxAvgTotalCalculator<T>::~MinMaxAvgTotalCalculator()
|
|
62 |
{
|
|
63 |
}
|
|
64 |
template <typename T>
|
|
65 |
void
|
|
66 |
MinMaxAvgTotalCalculator<T>::DoDispose(void)
|
|
67 |
{
|
|
68 |
DataCalculator::DoDispose();
|
|
69 |
// MinMaxAvgTotalCalculator::DoDispose
|
|
70 |
}
|
|
71 |
|
|
72 |
template <typename T>
|
|
73 |
void
|
|
74 |
MinMaxAvgTotalCalculator<T>::Update(const T i)
|
|
75 |
{
|
|
76 |
if (m_enabled) {
|
|
77 |
m_total += i;
|
|
78 |
|
|
79 |
if (i < m_min)
|
|
80 |
m_min = i;
|
|
81 |
|
|
82 |
if (i > m_max)
|
|
83 |
m_max = i;
|
|
84 |
|
|
85 |
m_count++;
|
|
86 |
}
|
|
87 |
// end MinMaxAvgTotalCalculator::Update
|
|
88 |
}
|
|
89 |
template <typename T>
|
|
90 |
void
|
|
91 |
MinMaxAvgTotalCalculator<T>::Output(DataOutputCallback &callback) const
|
|
92 |
{
|
|
93 |
callback.OutputSingleton(m_key, "count", m_count);
|
|
94 |
if (m_count > 0) {
|
|
95 |
callback.OutputSingleton(m_key, "total", m_total);
|
|
96 |
callback.OutputSingleton(m_key, "average", m_total/m_count);
|
|
97 |
callback.OutputSingleton(m_key, "max", m_max);
|
|
98 |
callback.OutputSingleton(m_key, "min", m_min);
|
|
99 |
}
|
|
100 |
// end MinMaxAvgTotalCalculator::Output
|
|
101 |
}
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
//------------------------------------------------------------
|
|
107 |
//--------------------------------------------
|
|
108 |
template <typename T = uint32_t>
|
|
109 |
class CounterCalculator : public DataCalculator {
|
|
110 |
public:
|
|
111 |
CounterCalculator();
|
|
112 |
virtual ~CounterCalculator();
|
|
113 |
|
|
114 |
void Update();
|
|
115 |
void Update(const T i);
|
|
116 |
|
|
117 |
T GetCount() const;
|
|
118 |
|
|
119 |
virtual void Output(DataOutputCallback &callback) const;
|
|
120 |
|
|
121 |
protected:
|
|
122 |
virtual void DoDispose(void);
|
|
123 |
|
|
124 |
T m_count;
|
|
125 |
|
|
126 |
// end CounterCalculator
|
|
127 |
};
|
|
128 |
|
|
129 |
|
|
130 |
//--------------------------------------------
|
|
131 |
template <typename T>
|
|
132 |
CounterCalculator<T>::CounterCalculator() :
|
|
133 |
m_count(0)
|
|
134 |
{
|
|
135 |
}
|
|
136 |
|
|
137 |
template <typename T>
|
|
138 |
CounterCalculator<T>::~CounterCalculator()
|
|
139 |
{
|
|
140 |
}
|
|
141 |
template <typename T>
|
|
142 |
void
|
|
143 |
CounterCalculator<T>::DoDispose(void)
|
|
144 |
{
|
|
145 |
DataCalculator::DoDispose();
|
|
146 |
// CounterCalculator::DoDispose
|
|
147 |
}
|
|
148 |
|
|
149 |
template <typename T>
|
|
150 |
void
|
|
151 |
CounterCalculator<T>::Update()
|
|
152 |
{
|
|
153 |
if (m_enabled) {
|
|
154 |
m_count++;
|
|
155 |
}
|
|
156 |
// end CounterCalculator::Update
|
|
157 |
}
|
|
158 |
|
|
159 |
template <typename T>
|
|
160 |
void
|
|
161 |
CounterCalculator<T>::Update(const T i)
|
|
162 |
{
|
|
163 |
if (m_enabled) {
|
|
164 |
m_count += i;
|
|
165 |
}
|
|
166 |
// end CounterCalculator::Update
|
|
167 |
}
|
|
168 |
|
|
169 |
template <typename T>
|
|
170 |
T
|
|
171 |
CounterCalculator<T>::GetCount() const
|
|
172 |
{
|
|
173 |
return m_count;
|
|
174 |
// end CounterCalculator::GetCount
|
|
175 |
}
|
|
176 |
|
|
177 |
template <typename T>
|
|
178 |
void
|
|
179 |
CounterCalculator<T>::Output(DataOutputCallback &callback) const
|
|
180 |
{
|
|
181 |
callback.OutputSingleton(m_key, "count", m_count);
|
|
182 |
// end CounterCalculator::Output
|
|
183 |
}
|
|
184 |
|
|
185 |
// end namespace ns3
|
|
186 |
};
|
|
187 |
|
|
188 |
|
|
189 |
#endif // __BASIC_DATA_CALCULATORS_H__
|