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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/debug/trace_event.h"
#include "base/metrics/histogram.h"
#include "media/cast/logging/logging_impl.h"
#include "net/base/big_endian.h"
namespace media {
namespace cast {
LoggingImpl::LoggingImpl(scoped_refptr<base::TaskRunner> main_thread_proxy,
const CastLoggingConfig& config)
: main_thread_proxy_(main_thread_proxy),
config_(config),
raw_(),
stats_() {}
LoggingImpl::~LoggingImpl() {}
void LoggingImpl::InsertFrameEvent(const base::TimeTicks& time_of_event,
CastLoggingEvent event,
uint32 rtp_timestamp,
uint32 frame_id) {
DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread());
if (config_.enable_data_collection) {
raw_.InsertFrameEvent(time_of_event, event, rtp_timestamp, frame_id);
stats_.InsertFrameEvent(time_of_event, event, rtp_timestamp, frame_id);
}
if (config_.enable_tracing) {
std::string event_string = CastLoggingToString(event);
TRACE_EVENT_INSTANT2(event_string.c_str(), "FE",
TRACE_EVENT_SCOPE_THREAD, "rtp_timestamp", rtp_timestamp, "frame_id",
frame_id);
}
}
void LoggingImpl::InsertFrameEventWithSize(const base::TimeTicks& time_of_event,
CastLoggingEvent event,
uint32 rtp_timestamp,
uint32 frame_id,
int frame_size) {
DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread());
if (config_.enable_data_collection) {
raw_.InsertFrameEventWithSize(time_of_event, event, rtp_timestamp, frame_id,
frame_size);
stats_.InsertFrameEventWithSize(time_of_event, event, rtp_timestamp,
frame_id, frame_size);
}
if (config_.enable_uma_stats) {
UMA_HISTOGRAM_COUNTS(CastLoggingToString(event), frame_size);
}
if (config_.enable_tracing) {
std::string event_string = CastLoggingToString(event);
TRACE_EVENT_INSTANT2(event_string.c_str(), "FES",
TRACE_EVENT_SCOPE_THREAD, "rtp_timestamp", rtp_timestamp, "frame_size",
frame_size);
}
}
void LoggingImpl::InsertFrameEventWithDelay(
const base::TimeTicks& time_of_event,
CastLoggingEvent event,
uint32 rtp_timestamp,
uint32 frame_id,
base::TimeDelta delay) {
DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread());
if (config_.enable_data_collection) {
raw_.InsertFrameEventWithDelay(time_of_event, event, rtp_timestamp,
frame_id, delay);
stats_.InsertFrameEventWithDelay(time_of_event, event, rtp_timestamp,
frame_id, delay);
}
if (config_.enable_uma_stats) {
UMA_HISTOGRAM_TIMES(CastLoggingToString(event), delay);
}
if (config_.enable_tracing) {
std::string event_string = CastLoggingToString(event);
TRACE_EVENT_INSTANT2(event_string.c_str(), "FED",
TRACE_EVENT_SCOPE_THREAD, "rtp_timestamp", rtp_timestamp, "delay",
delay.InMilliseconds());
}
}
void LoggingImpl::InsertPacketListEvent(const base::TimeTicks& time_of_event,
CastLoggingEvent event,
const PacketList& packets) {
DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread());
for (unsigned int i = 0; i < packets.size(); ++i) {
const Packet& packet = packets[i];
// Parse basic properties.
uint32 rtp_timestamp;
uint16 packet_id, max_packet_id;
const uint8* packet_data = &packet[0];
net::BigEndianReader big_endian_reader(packet_data + 4, 4);
big_endian_reader.ReadU32(&rtp_timestamp);
net::BigEndianReader cast_big_endian_reader(packet_data + 12 + 2, 4);
cast_big_endian_reader.ReadU16(&packet_id);
cast_big_endian_reader.ReadU16(&max_packet_id);
// rtp_timestamp is enough - no need for frame_id as well.
InsertPacketEvent(time_of_event, event, rtp_timestamp, kFrameIdUnknown,
packet_id, max_packet_id, packet.size());
}
}
void LoggingImpl::InsertPacketEvent(const base::TimeTicks& time_of_event,
CastLoggingEvent event,
uint32 rtp_timestamp,
uint32 frame_id,
uint16 packet_id,
uint16 max_packet_id,
size_t size) {
DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread());
if (config_.enable_data_collection) {
raw_.InsertPacketEvent(time_of_event, event, rtp_timestamp, frame_id,
packet_id, max_packet_id, size);
stats_.InsertPacketEvent(time_of_event, event, rtp_timestamp, frame_id,
packet_id, max_packet_id, size);
}
if (config_.enable_tracing) {
std::string event_string = CastLoggingToString(event);
TRACE_EVENT_INSTANT2(event_string.c_str(), "PE",
TRACE_EVENT_SCOPE_THREAD, "rtp_timestamp", rtp_timestamp,
"packet_id", packet_id);
}
}
void LoggingImpl::InsertGenericEvent(const base::TimeTicks& time_of_event,
CastLoggingEvent event, int value) {
DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread());
if (config_.enable_data_collection) {
raw_.InsertGenericEvent(time_of_event, event, value);
stats_.InsertGenericEvent(time_of_event, event, value);
}
if (config_.enable_uma_stats) {
UMA_HISTOGRAM_COUNTS(CastLoggingToString(event), value);
}
if (config_.enable_tracing) {
std::string event_string = CastLoggingToString(event);
TRACE_EVENT_INSTANT1(event_string.c_str(), "GE",
TRACE_EVENT_SCOPE_THREAD, "value", value);
}
}
// should just get the entire class, would be much easier.
FrameRawMap LoggingImpl::GetFrameRawData() {
DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread());
return raw_.GetFrameData();
}
PacketRawMap LoggingImpl::GetPacketRawData() {
DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread());
return raw_.GetPacketData();
}
GenericRawMap LoggingImpl::GetGenericRawData() {
DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread());
return raw_.GetGenericData();
}
const FrameStatsMap* LoggingImpl::GetFrameStatsData(
const base::TimeTicks& now) {
DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread());
// Get stats data.
const FrameStatsMap* stats = stats_.GetFrameStatsData(now);
if (config_.enable_uma_stats) {
FrameStatsMap::const_iterator it;
for (it = stats->begin(); it != stats->end(); ++it) {
// Check for an active event.
if (it->second->framerate_fps > 0) {
std::string event_string = CastLoggingToString(it->first);
UMA_HISTOGRAM_COUNTS(event_string.append("_framerate_fps"),
it->second->framerate_fps);
} else {
// All active frame events trigger framerate computation.
continue;
}
if (it->second->bitrate_kbps > 0) {
std::string evnt_string = CastLoggingToString(it->first);
UMA_HISTOGRAM_COUNTS(evnt_string.append("_bitrate_kbps"),
it->second->framerate_fps);
}
if (it->second->avg_delay_ms > 0) {
std::string event_string = CastLoggingToString(it->first);
UMA_HISTOGRAM_COUNTS(event_string.append("_avg_delay_ms"),
it->second->avg_delay_ms);
UMA_HISTOGRAM_COUNTS(event_string.append("_min_delay_ms"),
it->second->min_delay_ms);
UMA_HISTOGRAM_COUNTS(event_string.append("_max_delay_ms"),
it->second->max_delay_ms);
}
}
}
return stats;
}
const PacketStatsMap* LoggingImpl::GetPacketStatsData(
const base::TimeTicks& now) {
DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread());
// Get stats data.
const PacketStatsMap* stats = stats_.GetPacketStatsData(now);
if (config_.enable_uma_stats) {
PacketStatsMap::const_iterator it;
for (it = stats->begin(); it != stats->end(); ++it) {
if (it->second > 0) {
std::string event_string = CastLoggingToString(it->first);
UMA_HISTOGRAM_COUNTS(event_string.append("_bitrate_kbps"), it->second);
}
}
}
return stats;
}
const GenericStatsMap* LoggingImpl::GetGenericStatsData() {
DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread());
// Get stats data.
const GenericStatsMap* stats = stats_.GetGenericStatsData();
if (config_.enable_uma_stats) {
GenericStatsMap::const_iterator it;
for (it = stats->begin(); it != stats->end(); ++it) {
if (it->second > 0) {
UMA_HISTOGRAM_COUNTS(CastLoggingToString(it->first), it->second);
}
}
}
return stats;
}
void LoggingImpl::Reset() {
DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread());
raw_.Reset();
stats_.Reset();
}
} // namespace cast
} // namespace media
|