-
Notifications
You must be signed in to change notification settings - Fork 17
/
stats.hh
198 lines (173 loc) · 5.5 KB
/
stats.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
* SPDX-License-Identifier: BSD-3-Clause-Clear
*
* Copyright (c) 2015 ARM Limited
* All rights reserved
* Created on: Oct 19, 2015
* Author: Matteo Andreozzi
*/
#ifndef _AMBA_TRAFFIC_PROFILE_STATS_HH_
#define _AMBA_TRAFFIC_PROFILE_STATS_HH_
#include <cstdint>
#include <string>
#include <cmath>
#include <limits>
#include "proto/tp_stats.pb.h"
using namespace std;
namespace TrafficProfiles {
/*!
*\brief Statistics collection class
*
* This class provides methods and storage to collect and store statistics
* at any level in the ATP hierarchy. It can also export recorded values
* as Google Protocol Buffer objects
*/
class Stats {
//! started flag : signals that the start time has been initialised
bool started;
public:
//! Start time since when stats are computed
uint64_t startTime;
//! Time scale factor: used to export time in seconds
uint64_t timeScale;
//! last time statistics were recorded
uint64_t time;
//! total packet sent counter
uint64_t sent;
//! total packet received counter
uint64_t received;
//! how many data have been generated
uint64_t dataSent;
//! how many data have been received
uint64_t dataReceived;
//! previous latency - used to compute jitter
double prevLatency;
//! cumulative response jitter
double jitter;
//! cumulative response latency
double latency;
//! FIFO buffer underruns
uint64_t underruns;
//! FIFO buffer overruns
uint64_t overruns;
//! Cumulative OT (CurTxn)
uint64_t ot;
//! Number of OT measurements
uint64_t otN;
//! Cumulative FIFO level (CurLvl)
uint64_t fifoLevel;
//! Number of FIFO level measurements
uint64_t fifoLevelN;
//! Default Constructor
Stats();
//! Default destructor
virtual ~Stats();
/*!
* records a send event
*\param t the time the event occurred
*\param data the amount of data sent
*\param o outstanding transactions
*/
void send (const uint64_t, const uint64_t, const uint64_t=0);
/*!
* records a receive event
*\param t the time the event occurred
*\param data the amount of data received
*\param l the latency measured for this data reception
*/
void receive (const uint64_t, const uint64_t, const double);
/*!
* records a FIFO update event
*\param l the FIFO level
*\param u whether the FIFO did underrun
*\param o whether the FIFO did overrun
*/
void fifoUpdate(const uint64_t, const bool, const bool);
//! resets all statistics counters
inline void reset() {started=false, startTime=numeric_limits<uint64_t>::max(), time=0,
sent=0, received=0, dataSent=0,
dataReceived=0, prevLatency=.0, jitter=.0, latency=.0,
underruns=0, overruns=0, ot=0, otN=0, fifoLevel=0,
fifoLevelN=0;}
/*!
* Starts the statistics from the given time,
* if not already started
*\param t start time
*/
inline void start(const uint64_t t) { if (!started) {started=true; startTime=t;}}
/*!
* Advances the time to a specific value
* going backwards in time is prevented
*\param t time to set
*/
void setTime(const uint64_t);
/*!
* Dumps statistics
*\return a formatted string with all statistics
*/
const string dump() const;
/*!
* Method to compute and get the rate for sent data
*\return the data rate
*/
inline double sendRate () const
{ return (time? (double)dataSent/((double)time - (double)startTime)*timeScale:0); }
/*!
* Method to compute and get the rate for received data
*\return the data rate
*/
inline double receiveRate () const
{ return (time? (double)dataReceived/((double)time - (double)startTime)*timeScale:0);}
/*
* Method to compute and get the average response latency
*\return the average response latency
*/
inline double avgLatency() const
{ return latency/(double)(timeScale * received); }
/*
* Method to compute and get the request to response jitter
*\return the computed response jitter
*/
inline double avgJitter() const
{ return jitter/(double)(timeScale); }
/*
* Method to compute and get the average OT
*\return the average OT count
*/
inline uint64_t avgOt() const { return otN ? ceil((double)ot/(double)otN) : 0;}
/*
* Method to compute and get the average FIFO level
*\return the average FIFO level
*/
inline uint64_t avgFifoLevel() const {return fifoLevelN ? (fifoLevel/fifoLevelN) : 0;}
/*!
* Method to compute and return the stats finish time
*\return the stats time in seconds
*/
inline double getTime() const {return (double)time/(double)timeScale;}
/*!
* Method to compute and return the stats start time
*\return the stats time in seconds
*/
inline double getStartTime() const {return (double)startTime/(double)timeScale;}
/*!
* Exports statistics as Google Protocol Buffer object
*\return a Google Protocol Buffer StatObject
*/
const StatObject* xport() const;
/*!
* Sum operator: merges two Stats objects
*\param s the Stats object to add
*\return the sum by value
*/
Stats operator+(const Stats&);
/*!
* Add operator: adds Stats objects
* fields to this one
*\param s the Stats object to add
*\return this object by reference
*/
Stats& operator+=(const Stats&);
};
} /* namespace TrafficProfiles */
#endif /* _AMBA_TRAFFIC_PROFILE_STATS_HH_ */