blob: c4f722069b9a296b21fd9a9bb7eb9f3fe3dd94ed [file] [log] [blame]
terelius54ce6802016-07-13 06:44:41 -07001/*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei575998c2019-07-25 13:57:41 +020011#ifndef RTC_TOOLS_RTC_EVENT_LOG_VISUALIZER_ANALYZER_H_
12#define RTC_TOOLS_RTC_EVENT_LOG_VISUALIZER_ANALYZER_H_
terelius54ce6802016-07-13 06:44:41 -070013
terelius88e64e52016-07-19 01:51:06 -070014#include <map>
Stefan Holmer13181032016-07-29 14:48:54 +020015#include <memory>
terelius0740a202016-08-08 10:21:04 -070016#include <set>
philipelccd74892016-09-05 02:46:25 -070017#include <string>
Stefan Holmer13181032016-07-29 14:48:54 +020018#include <utility>
philipelccd74892016-09-05 02:46:25 -070019#include <vector>
terelius54ce6802016-07-13 06:44:41 -070020
Sebastian Janssonb290a6d2019-01-03 14:46:23 +010021#include "logging/rtc_event_log/rtc_event_log_parser.h"
Minyue Lic6ff7572018-05-04 09:46:44 +020022#include "modules/audio_coding/neteq/tools/neteq_stats_getter.h"
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020023#include "rtc_base/strings/string_builder.h"
Mirko Bonadei575998c2019-07-25 13:57:41 +020024#include "rtc_tools/rtc_event_log_visualizer/plot_base.h"
25#include "rtc_tools/rtc_event_log_visualizer/triage_notifications.h"
terelius54ce6802016-07-13 06:44:41 -070026
27namespace webrtc {
michaelt6e5b2192017-02-22 07:33:27 -080028
Bjorn Terelius068fc352019-02-13 22:38:25 +010029class AnalyzerConfig {
30 public:
31 float GetCallTimeSec(int64_t timestamp_us) const {
32 int64_t offset = normalize_time_ ? begin_time_ : 0;
33 return static_cast<float>(timestamp_us - offset) / 1000000;
34 }
35
36 float CallBeginTimeSec() const { return GetCallTimeSec(begin_time_); }
37
38 float CallEndTimeSec() const { return GetCallTimeSec(end_time_); }
39
40 // Window and step size used for calculating moving averages, e.g. bitrate.
41 // The generated data points will be |step_| microseconds apart.
Mirko Bonadei604e75c2019-07-25 11:55:47 +020042 // Only events occurring at most |window_duration_| microseconds before the
Bjorn Terelius068fc352019-02-13 22:38:25 +010043 // current data point will be part of the average.
44 int64_t window_duration_;
45 int64_t step_;
46
47 // First and last events of the log.
48 int64_t begin_time_;
49 int64_t end_time_;
50 bool normalize_time_;
51};
52
terelius54ce6802016-07-13 06:44:41 -070053class EventLogAnalyzer {
54 public:
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020055 // The EventLogAnalyzer keeps a reference to the ParsedRtcEventLogNew for the
56 // duration of its lifetime. The ParsedRtcEventLogNew must not be destroyed or
terelius54ce6802016-07-13 06:44:41 -070057 // modified while the EventLogAnalyzer is being used.
Sebastian Janssonb290a6d2019-01-03 14:46:23 +010058 EventLogAnalyzer(const ParsedRtcEventLog& log, bool normalize_time);
terelius54ce6802016-07-13 06:44:41 -070059
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020060 void CreatePacketGraph(PacketDirection direction, Plot* plot);
terelius54ce6802016-07-13 06:44:41 -070061
Bjorn Terelius7c974e62019-02-15 17:20:12 +010062 void CreateRtcpTypeGraph(PacketDirection direction, Plot* plot);
63
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020064 void CreateAccumulatedPacketsGraph(PacketDirection direction, Plot* plot);
philipelccd74892016-09-05 02:46:25 -070065
terelius54ce6802016-07-13 06:44:41 -070066 void CreatePlayoutGraph(Plot* plot);
67
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020068 void CreateAudioLevelGraph(PacketDirection direction, Plot* plot);
ivocaac9d6f2016-09-22 07:01:47 -070069
terelius54ce6802016-07-13 06:44:41 -070070 void CreateSequenceNumberGraph(Plot* plot);
71
Stefan Holmer99f8e082016-09-09 13:37:50 +020072 void CreateIncomingPacketLossGraph(Plot* plot);
73
terelius2ee076d2017-08-15 02:04:02 -070074 void CreateIncomingDelayGraph(Plot* plot);
terelius54ce6802016-07-13 06:44:41 -070075
tereliusf736d232016-08-04 10:00:11 -070076 void CreateFractionLossGraph(Plot* plot);
77
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020078 void CreateTotalIncomingBitrateGraph(Plot* plot);
79 void CreateTotalOutgoingBitrateGraph(Plot* plot,
80 bool show_detector_state = false,
81 bool show_alr_state = false);
terelius54ce6802016-07-13 06:44:41 -070082
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020083 void CreateStreamBitrateGraph(PacketDirection direction, Plot* plot);
Bjorn Terelius9775a582019-02-15 17:29:58 +010084 void CreateBitrateAllocationGraph(PacketDirection direction, Plot* plot);
terelius54ce6802016-07-13 06:44:41 -070085
Sebastian Jansson1175ae02019-03-13 08:56:58 +010086 void CreateGoogCcSimulationGraph(Plot* plot);
Bjorn Terelius28db2662017-10-04 14:22:43 +020087 void CreateSendSideBweSimulationGraph(Plot* plot);
88 void CreateReceiveSideBweSimulationGraph(Plot* plot);
Stefan Holmer13181032016-07-29 14:48:54 +020089
tereliuse34c19c2016-08-15 08:47:14 -070090 void CreateNetworkDelayFeedbackGraph(Plot* plot);
Bjorn Terelius0295a962017-10-25 17:42:41 +020091 void CreatePacerDelayGraph(Plot* plot);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020092
93 void CreateTimestampGraph(PacketDirection direction, Plot* plot);
Bjorn Tereliusb1222c22018-07-24 13:45:31 +020094 void CreateSenderAndReceiverReportPlot(
95 PacketDirection direction,
96 rtc::FunctionView<float(const rtcp::ReportBlock&)> fy,
97 std::string title,
98 std::string yaxis_label,
99 Plot* plot);
stefanc3de0332016-08-02 07:22:17 -0700100
michaelt6e5b2192017-02-22 07:33:27 -0800101 void CreateAudioEncoderTargetBitrateGraph(Plot* plot);
102 void CreateAudioEncoderFrameLengthGraph(Plot* plot);
terelius2ee076d2017-08-15 02:04:02 -0700103 void CreateAudioEncoderPacketLossGraph(Plot* plot);
michaelt6e5b2192017-02-22 07:33:27 -0800104 void CreateAudioEncoderEnableFecGraph(Plot* plot);
105 void CreateAudioEncoderEnableDtxGraph(Plot* plot);
106 void CreateAudioEncoderNumChannelsGraph(Plot* plot);
Minyue Lic6ff7572018-05-04 09:46:44 +0200107
108 using NetEqStatsGetterMap =
109 std::map<uint32_t, std::unique_ptr<test::NetEqStatsGetter>>;
110 NetEqStatsGetterMap SimulateNetEq(const std::string& replacement_file_name,
111 int file_sample_rate_hz) const;
Minyue Lic9ac93f2018-06-26 13:01:32 +0200112
Minyue Li01d2a672018-06-21 21:17:19 +0200113 void CreateAudioJitterBufferGraph(uint32_t ssrc,
114 const test::NetEqStatsGetter* stats_getter,
115 Plot* plot) const;
Minyue Lic9ac93f2018-06-26 13:01:32 +0200116 void CreateNetEqNetworkStatsGraph(
Minyue Li27e2b7d2018-05-07 15:20:24 +0200117 const NetEqStatsGetterMap& neteq_stats_getters,
118 rtc::FunctionView<float(const NetEqNetworkStatistics&)> stats_extractor,
119 const std::string& plot_name,
120 Plot* plot) const;
Minyue Lic9ac93f2018-06-26 13:01:32 +0200121 void CreateNetEqLifetimeStatsGraph(
122 const NetEqStatsGetterMap& neteq_stats_getters,
123 rtc::FunctionView<float(const NetEqLifetimeStatistics&)> stats_extractor,
124 const std::string& plot_name,
125 Plot* plot) const;
michaelt6e5b2192017-02-22 07:33:27 -0800126
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800127 void CreateIceCandidatePairConfigGraph(Plot* plot);
128 void CreateIceConnectivityCheckGraph(Plot* plot);
129
Zach Stein10a58012018-12-07 12:26:28 -0800130 void CreateDtlsTransportStateGraph(Plot* plot);
131 void CreateDtlsWritableStateGraph(Plot* plot);
132
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100133 void CreateTriageNotifications();
134 void PrintNotifications(FILE* file);
135
terelius54ce6802016-07-13 06:44:41 -0700136 private:
Bjorn Terelius9775a582019-02-15 17:29:58 +0100137 struct LayerDescription {
138 LayerDescription(uint32_t ssrc,
139 uint8_t spatial_layer,
140 uint8_t temporal_layer)
141 : ssrc(ssrc),
142 spatial_layer(spatial_layer),
143 temporal_layer(temporal_layer) {}
144 bool operator<(const LayerDescription& other) const {
145 if (ssrc != other.ssrc)
146 return ssrc < other.ssrc;
147 if (spatial_layer != other.spatial_layer)
148 return spatial_layer < other.spatial_layer;
149 return temporal_layer < other.temporal_layer;
150 }
151 uint32_t ssrc;
152 uint8_t spatial_layer;
153 uint8_t temporal_layer;
154 };
155
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200156 bool IsRtxSsrc(PacketDirection direction, uint32_t ssrc) const {
157 if (direction == kIncomingPacket) {
158 return parsed_log_.incoming_rtx_ssrcs().find(ssrc) !=
159 parsed_log_.incoming_rtx_ssrcs().end();
160 } else {
161 return parsed_log_.outgoing_rtx_ssrcs().find(ssrc) !=
162 parsed_log_.outgoing_rtx_ssrcs().end();
terelius0740a202016-08-08 10:21:04 -0700163 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200164 }
165
166 bool IsVideoSsrc(PacketDirection direction, uint32_t ssrc) const {
167 if (direction == kIncomingPacket) {
168 return parsed_log_.incoming_video_ssrcs().find(ssrc) !=
169 parsed_log_.incoming_video_ssrcs().end();
170 } else {
171 return parsed_log_.outgoing_video_ssrcs().find(ssrc) !=
172 parsed_log_.outgoing_video_ssrcs().end();
terelius0740a202016-08-08 10:21:04 -0700173 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200174 }
terelius88e64e52016-07-19 01:51:06 -0700175
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200176 bool IsAudioSsrc(PacketDirection direction, uint32_t ssrc) const {
177 if (direction == kIncomingPacket) {
178 return parsed_log_.incoming_audio_ssrcs().find(ssrc) !=
179 parsed_log_.incoming_audio_ssrcs().end();
180 } else {
181 return parsed_log_.outgoing_audio_ssrcs().find(ssrc) !=
182 parsed_log_.outgoing_audio_ssrcs().end();
183 }
184 }
terelius88e64e52016-07-19 01:51:06 -0700185
Minyue Lic9ac93f2018-06-26 13:01:32 +0200186 template <typename NetEqStatsType>
187 void CreateNetEqStatsGraphInternal(
188 const NetEqStatsGetterMap& neteq_stats,
189 rtc::FunctionView<const std::vector<std::pair<int64_t, NetEqStatsType>>*(
190 const test::NetEqStatsGetter*)> data_extractor,
191 rtc::FunctionView<float(const NetEqStatsType&)> stats_extractor,
192 const std::string& plot_name,
193 Plot* plot) const;
194
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200195 template <typename IterableType>
196 void CreateAccumulatedPacketsTimeSeries(Plot* plot,
197 const IterableType& packets,
198 const std::string& label);
philipelccd74892016-09-05 02:46:25 -0700199
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200200 void CreateStreamGapAlerts(PacketDirection direction);
201 void CreateTransmissionGapAlerts(PacketDirection direction);
terelius0740a202016-08-08 10:21:04 -0700202
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200203 std::string GetStreamName(PacketDirection direction, uint32_t ssrc) const {
204 char buffer[200];
205 rtc::SimpleStringBuilder name(buffer);
206 if (IsAudioSsrc(direction, ssrc)) {
207 name << "Audio ";
208 } else if (IsVideoSsrc(direction, ssrc)) {
209 name << "Video ";
210 } else {
211 name << "Unknown ";
212 }
213 if (IsRtxSsrc(direction, ssrc)) {
214 name << "RTX ";
215 }
216 if (direction == kIncomingPacket)
217 name << "(In) ";
218 else
219 name << "(Out) ";
220 name << "SSRC " << ssrc;
221 return name.str();
222 }
terelius0740a202016-08-08 10:21:04 -0700223
Bjorn Terelius9775a582019-02-15 17:29:58 +0100224 std::string GetLayerName(LayerDescription layer) const {
225 char buffer[100];
226 rtc::SimpleStringBuilder name(buffer);
227 name << "SSRC " << layer.ssrc << " sl " << layer.spatial_layer << ", tl "
228 << layer.temporal_layer;
229 return name.str();
230 }
231
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200232 void Alert_RtpLogTimeGap(PacketDirection direction,
233 float time_seconds,
234 int64_t duration) {
235 if (direction == kIncomingPacket) {
236 incoming_rtp_recv_time_gaps_.emplace_back(time_seconds, duration);
237 } else {
238 outgoing_rtp_send_time_gaps_.emplace_back(time_seconds, duration);
239 }
240 }
241
242 void Alert_RtcpLogTimeGap(PacketDirection direction,
243 float time_seconds,
244 int64_t duration) {
245 if (direction == kIncomingPacket) {
246 incoming_rtcp_recv_time_gaps_.emplace_back(time_seconds, duration);
247 } else {
248 outgoing_rtcp_send_time_gaps_.emplace_back(time_seconds, duration);
249 }
250 }
251
252 void Alert_SeqNumJump(PacketDirection direction,
253 float time_seconds,
254 uint32_t ssrc) {
255 if (direction == kIncomingPacket) {
256 incoming_seq_num_jumps_.emplace_back(time_seconds, ssrc);
257 } else {
258 outgoing_seq_num_jumps_.emplace_back(time_seconds, ssrc);
259 }
260 }
261
262 void Alert_CaptureTimeJump(PacketDirection direction,
263 float time_seconds,
264 uint32_t ssrc) {
265 if (direction == kIncomingPacket) {
266 incoming_capture_time_jumps_.emplace_back(time_seconds, ssrc);
267 } else {
268 outgoing_capture_time_jumps_.emplace_back(time_seconds, ssrc);
269 }
270 }
271
272 void Alert_OutgoingHighLoss(double avg_loss_fraction) {
273 outgoing_high_loss_alerts_.emplace_back(avg_loss_fraction);
274 }
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100275
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800276 std::string GetCandidatePairLogDescriptionFromId(uint32_t candidate_pair_id);
277
Sebastian Janssonb290a6d2019-01-03 14:46:23 +0100278 const ParsedRtcEventLog& parsed_log_;
terelius54ce6802016-07-13 06:44:41 -0700279
280 // A list of SSRCs we are interested in analysing.
281 // If left empty, all SSRCs will be considered relevant.
282 std::vector<uint32_t> desired_ssrc_;
283
henrik.lundin3c938fc2017-06-14 06:09:58 -0700284 // Stores the timestamps for all log segments, in the form of associated start
285 // and end events.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200286 std::vector<std::pair<int64_t, int64_t>> log_segments_;
henrik.lundin3c938fc2017-06-14 06:09:58 -0700287
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200288 std::vector<IncomingRtpReceiveTimeGap> incoming_rtp_recv_time_gaps_;
289 std::vector<IncomingRtcpReceiveTimeGap> incoming_rtcp_recv_time_gaps_;
290 std::vector<OutgoingRtpSendTimeGap> outgoing_rtp_send_time_gaps_;
291 std::vector<OutgoingRtcpSendTimeGap> outgoing_rtcp_send_time_gaps_;
292 std::vector<IncomingSeqNumJump> incoming_seq_num_jumps_;
293 std::vector<IncomingCaptureTimeJump> incoming_capture_time_jumps_;
294 std::vector<OutgoingSeqNoJump> outgoing_seq_num_jumps_;
295 std::vector<OutgoingCaptureTimeJump> outgoing_capture_time_jumps_;
296 std::vector<OutgoingHighLoss> outgoing_high_loss_alerts_;
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800297
298 std::map<uint32_t, std::string> candidate_pair_desc_by_id_;
299
Bjorn Terelius068fc352019-02-13 22:38:25 +0100300 AnalyzerConfig config_;
terelius54ce6802016-07-13 06:44:41 -0700301};
302
terelius54ce6802016-07-13 06:44:41 -0700303} // namespace webrtc
304
Mirko Bonadei575998c2019-07-25 13:57:41 +0200305#endif // RTC_TOOLS_RTC_EVENT_LOG_VISUALIZER_ANALYZER_H_