-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathstatistics.hpp
187 lines (160 loc) · 7.6 KB
/
statistics.hpp
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
//
// statistics.hpp
// ndnrtc
//
// Copyright 2013 Regents of the University of California
// For licensing details see the LICENSE file.
//
// Author: Peter Gusev
// Created: 8/21/13
//
#ifndef ndnrtc_statistics_h
#define ndnrtc_statistics_h
#include <string>
#include <map>
#include <stdexcept>
#include <iostream>
#include <iomanip>
#include <boost/shared_ptr.hpp>
namespace ndnrtc {
namespace statistics {
enum class Indicator {
// general
Timestamp, // NDN-RTC timestamp when statistics were captured
// consumer
// buffer
AcquiredNum, // PlaybackQueue
AcquiredKeyNum, // PlaybackQueue
DroppedNum, // Buffer
DroppedKeyNum, // Buffer
AssembledNum, // Buffer
AssembledKeyNum, // Buffer
RecoveredNum, // VideoPlayout
RecoveredKeyNum, // VideoPlayout
RescuedNum, // VideoPlayout
RescuedKeyNum, // VideoPlayout
IncompleteNum, // Buffer
IncompleteKeyNum, // Buffer
BufferTargetSize, // RemoteStreamImpl
BufferPlayableSize, // PlaybackQueue
BufferReservedSize, // PlaybackQueue
CurrentProducerFramerate, // BufferControl
VerifySuccess, // SampleValidator
VerifyFailure, // SampleValidator
LatencyControlStable, // LatencyControl
LatencyControlCommand, // LatencyControl
FrameFetchAvgDelta, // Buffer
FrameFetchAvgKey, // Buffer
// playout
LastPlayedNo, // VideoPlayout
LastPlayedDeltaNo, // VideoPlayout
LastPlayedKeyNo, // VideoPlayout
PlayedNum, // VideoPlayout
PlayedKeyNum, // VideoPlayout
SkippedNum, // VideoPlayout
LatencyEstimated,
// pipeliner
SegmentsDeltaAvgNum, // SampleEstimator
SegmentsKeyAvgNum, // SampleEstimator
SegmentsDeltaParityAvgNum, // SampleEstimator
SegmentsKeyParityAvgNum, // SampleEstimator
RtxNum,
RebufferingsNum, // PipelineControlStateMachine
RequestedNum, // Pipeliner
RequestedKeyNum, // Pipeliner
DW, // InterestControl
W, // InterestControl
SegmentsReceivedNum, // SegmentController
TimeoutsNum, // SegmentController
NacksNum, // SegmentController
AppNackNum, // SegmentController
Darr, // LatencyControl
BytesReceived, // SegmentController
RawBytesReceived, // SegmentController
State, // PipelineControlStateMachine
DoubleRtFrames, // Pipeliner
DoubleRtFramesKey, // Pipeliner
// DRD estimator
DrdOriginalEstimation, // BufferControl
DrdCachedEstimation, // BufferControl
// interest queue
QueueSize, // InterestQueue
InterestsSentNum, // InterestQueue
// producer
//media thread
BytesPublished,
RawBytesPublished,
PublishedSegmentsNum,
ProcessedNum,
PublishedNum,
PublishedKeyNum,
InterestsReceivedNum,
SignNum,
// encoder
// DroppedNum, // borrowed from buffer (above)
EncodedNum,
// capturer
CapturedNum
};
class StatisticsStorage {
public:
typedef std::map<Indicator, double> StatRepo;
static const std::map<Indicator, std::string> IndicatorNames;
static const std::map<Indicator, std::string> IndicatorKeywords;
static StatisticsStorage*
createConsumerStatistics()
{ return new StatisticsStorage(StatisticsStorage::ConsumerStatRepo); }
static StatisticsStorage*
createProducerStatistics()
{ return new StatisticsStorage(StatisticsStorage::ProducerStatRepo); }
StatisticsStorage(const StatisticsStorage& statisticsStorage):
inidicatorNames_(StatisticsStorage::IndicatorNames),
indicators_(statisticsStorage.getIndicators()){}
~StatisticsStorage(){}
// may throw an exception if indicator is not present in the repo
void
updateIndicator(const statistics::Indicator& indicator,
const double& value) throw(std::out_of_range);
StatRepo
getIndicators() const;
StatisticsStorage&
operator=(const StatisticsStorage& other)
{
indicators_ = other.getIndicators();
return *this;
}
double&
operator[](const statistics::Indicator& indicator)
{ return indicators_.at(indicator); }
friend std::ostream& operator<<(std::ostream& os,
const StatisticsStorage& storage)
{
for (auto& it:storage.indicators_)
{
try {
os << std::fixed
<< storage.inidicatorNames_.at(it.first) << "\t"
<< std::setprecision(2) << it.second << std::endl;
}
catch (...) {
}
}
return os;
}
private:
StatisticsStorage(const StatRepo& indicators):indicators_(indicators){}
const std::map<Indicator, std::string> inidicatorNames_;
static const StatRepo ConsumerStatRepo;
static const StatRepo ProducerStatRepo;
StatRepo indicators_;
};
class StatObject {
public:
StatObject(const boost::shared_ptr<StatisticsStorage>& statStorage):statStorage_(statStorage){}
virtual ~StatObject(){}
protected:
boost::shared_ptr<StatisticsStorage> statStorage_;
};
};
}
#endif