blob: e59e7b45ab1e6468e8f0bc57f33d839f0ee3c610 [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
Kristoffer Erlandsson283c1062020-03-30 13:01:37 +020066 void CreatePacketRateGraph(PacketDirection direction, Plot* plot);
67
terelius54ce6802016-07-13 06:44:41 -070068 void CreatePlayoutGraph(Plot* plot);
69
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020070 void CreateAudioLevelGraph(PacketDirection direction, Plot* plot);
ivocaac9d6f2016-09-22 07:01:47 -070071
terelius54ce6802016-07-13 06:44:41 -070072 void CreateSequenceNumberGraph(Plot* plot);
73
Stefan Holmer99f8e082016-09-09 13:37:50 +020074 void CreateIncomingPacketLossGraph(Plot* plot);
75
terelius2ee076d2017-08-15 02:04:02 -070076 void CreateIncomingDelayGraph(Plot* plot);
terelius54ce6802016-07-13 06:44:41 -070077
tereliusf736d232016-08-04 10:00:11 -070078 void CreateFractionLossGraph(Plot* plot);
79
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020080 void CreateTotalIncomingBitrateGraph(Plot* plot);
81 void CreateTotalOutgoingBitrateGraph(Plot* plot,
82 bool show_detector_state = false,
83 bool show_alr_state = false);
terelius54ce6802016-07-13 06:44:41 -070084
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020085 void CreateStreamBitrateGraph(PacketDirection direction, Plot* plot);
Bjorn Terelius9775a582019-02-15 17:29:58 +010086 void CreateBitrateAllocationGraph(PacketDirection direction, Plot* plot);
terelius54ce6802016-07-13 06:44:41 -070087
Sebastian Jansson1175ae02019-03-13 08:56:58 +010088 void CreateGoogCcSimulationGraph(Plot* plot);
Bjorn Terelius28db2662017-10-04 14:22:43 +020089 void CreateSendSideBweSimulationGraph(Plot* plot);
90 void CreateReceiveSideBweSimulationGraph(Plot* plot);
Stefan Holmer13181032016-07-29 14:48:54 +020091
tereliuse34c19c2016-08-15 08:47:14 -070092 void CreateNetworkDelayFeedbackGraph(Plot* plot);
Bjorn Terelius0295a962017-10-25 17:42:41 +020093 void CreatePacerDelayGraph(Plot* plot);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020094
95 void CreateTimestampGraph(PacketDirection direction, Plot* plot);
Bjorn Tereliusb1222c22018-07-24 13:45:31 +020096 void CreateSenderAndReceiverReportPlot(
97 PacketDirection direction,
98 rtc::FunctionView<float(const rtcp::ReportBlock&)> fy,
99 std::string title,
100 std::string yaxis_label,
101 Plot* plot);
stefanc3de0332016-08-02 07:22:17 -0700102
michaelt6e5b2192017-02-22 07:33:27 -0800103 void CreateAudioEncoderTargetBitrateGraph(Plot* plot);
104 void CreateAudioEncoderFrameLengthGraph(Plot* plot);
terelius2ee076d2017-08-15 02:04:02 -0700105 void CreateAudioEncoderPacketLossGraph(Plot* plot);
michaelt6e5b2192017-02-22 07:33:27 -0800106 void CreateAudioEncoderEnableFecGraph(Plot* plot);
107 void CreateAudioEncoderEnableDtxGraph(Plot* plot);
108 void CreateAudioEncoderNumChannelsGraph(Plot* plot);
Minyue Lic6ff7572018-05-04 09:46:44 +0200109
110 using NetEqStatsGetterMap =
111 std::map<uint32_t, std::unique_ptr<test::NetEqStatsGetter>>;
112 NetEqStatsGetterMap SimulateNetEq(const std::string& replacement_file_name,
113 int file_sample_rate_hz) const;
Minyue Lic9ac93f2018-06-26 13:01:32 +0200114
Minyue Li01d2a672018-06-21 21:17:19 +0200115 void CreateAudioJitterBufferGraph(uint32_t ssrc,
116 const test::NetEqStatsGetter* stats_getter,
117 Plot* plot) const;
Minyue Lic9ac93f2018-06-26 13:01:32 +0200118 void CreateNetEqNetworkStatsGraph(
Minyue Li27e2b7d2018-05-07 15:20:24 +0200119 const NetEqStatsGetterMap& neteq_stats_getters,
120 rtc::FunctionView<float(const NetEqNetworkStatistics&)> stats_extractor,
121 const std::string& plot_name,
122 Plot* plot) const;
Minyue Lic9ac93f2018-06-26 13:01:32 +0200123 void CreateNetEqLifetimeStatsGraph(
124 const NetEqStatsGetterMap& neteq_stats_getters,
125 rtc::FunctionView<float(const NetEqLifetimeStatistics&)> stats_extractor,
126 const std::string& plot_name,
127 Plot* plot) const;
michaelt6e5b2192017-02-22 07:33:27 -0800128
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800129 void CreateIceCandidatePairConfigGraph(Plot* plot);
130 void CreateIceConnectivityCheckGraph(Plot* plot);
131
Zach Stein10a58012018-12-07 12:26:28 -0800132 void CreateDtlsTransportStateGraph(Plot* plot);
133 void CreateDtlsWritableStateGraph(Plot* plot);
134
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100135 void CreateTriageNotifications();
136 void PrintNotifications(FILE* file);
137
terelius54ce6802016-07-13 06:44:41 -0700138 private:
Bjorn Terelius9775a582019-02-15 17:29:58 +0100139 struct LayerDescription {
140 LayerDescription(uint32_t ssrc,
141 uint8_t spatial_layer,
142 uint8_t temporal_layer)
143 : ssrc(ssrc),
144 spatial_layer(spatial_layer),
145 temporal_layer(temporal_layer) {}
146 bool operator<(const LayerDescription& other) const {
147 if (ssrc != other.ssrc)
148 return ssrc < other.ssrc;
149 if (spatial_layer != other.spatial_layer)
150 return spatial_layer < other.spatial_layer;
151 return temporal_layer < other.temporal_layer;
152 }
153 uint32_t ssrc;
154 uint8_t spatial_layer;
155 uint8_t temporal_layer;
156 };
157
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200158 bool IsRtxSsrc(PacketDirection direction, uint32_t ssrc) const {
159 if (direction == kIncomingPacket) {
160 return parsed_log_.incoming_rtx_ssrcs().find(ssrc) !=
161 parsed_log_.incoming_rtx_ssrcs().end();
162 } else {
163 return parsed_log_.outgoing_rtx_ssrcs().find(ssrc) !=
164 parsed_log_.outgoing_rtx_ssrcs().end();
terelius0740a202016-08-08 10:21:04 -0700165 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200166 }
167
168 bool IsVideoSsrc(PacketDirection direction, uint32_t ssrc) const {
169 if (direction == kIncomingPacket) {
170 return parsed_log_.incoming_video_ssrcs().find(ssrc) !=
171 parsed_log_.incoming_video_ssrcs().end();
172 } else {
173 return parsed_log_.outgoing_video_ssrcs().find(ssrc) !=
174 parsed_log_.outgoing_video_ssrcs().end();
terelius0740a202016-08-08 10:21:04 -0700175 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200176 }
terelius88e64e52016-07-19 01:51:06 -0700177
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200178 bool IsAudioSsrc(PacketDirection direction, uint32_t ssrc) const {
179 if (direction == kIncomingPacket) {
180 return parsed_log_.incoming_audio_ssrcs().find(ssrc) !=
181 parsed_log_.incoming_audio_ssrcs().end();
182 } else {
183 return parsed_log_.outgoing_audio_ssrcs().find(ssrc) !=
184 parsed_log_.outgoing_audio_ssrcs().end();
185 }
186 }
terelius88e64e52016-07-19 01:51:06 -0700187
Minyue Lic9ac93f2018-06-26 13:01:32 +0200188 template <typename NetEqStatsType>
189 void CreateNetEqStatsGraphInternal(
190 const NetEqStatsGetterMap& neteq_stats,
191 rtc::FunctionView<const std::vector<std::pair<int64_t, NetEqStatsType>>*(
192 const test::NetEqStatsGetter*)> data_extractor,
193 rtc::FunctionView<float(const NetEqStatsType&)> stats_extractor,
194 const std::string& plot_name,
195 Plot* plot) const;
196
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200197 template <typename IterableType>
198 void CreateAccumulatedPacketsTimeSeries(Plot* plot,
199 const IterableType& packets,
200 const std::string& label);
philipelccd74892016-09-05 02:46:25 -0700201
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200202 void CreateStreamGapAlerts(PacketDirection direction);
203 void CreateTransmissionGapAlerts(PacketDirection direction);
terelius0740a202016-08-08 10:21:04 -0700204
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200205 std::string GetStreamName(PacketDirection direction, uint32_t ssrc) const {
206 char buffer[200];
207 rtc::SimpleStringBuilder name(buffer);
208 if (IsAudioSsrc(direction, ssrc)) {
209 name << "Audio ";
210 } else if (IsVideoSsrc(direction, ssrc)) {
211 name << "Video ";
212 } else {
213 name << "Unknown ";
214 }
215 if (IsRtxSsrc(direction, ssrc)) {
216 name << "RTX ";
217 }
218 if (direction == kIncomingPacket)
219 name << "(In) ";
220 else
221 name << "(Out) ";
222 name << "SSRC " << ssrc;
223 return name.str();
224 }
terelius0740a202016-08-08 10:21:04 -0700225
Bjorn Terelius9775a582019-02-15 17:29:58 +0100226 std::string GetLayerName(LayerDescription layer) const {
227 char buffer[100];
228 rtc::SimpleStringBuilder name(buffer);
229 name << "SSRC " << layer.ssrc << " sl " << layer.spatial_layer << ", tl "
230 << layer.temporal_layer;
231 return name.str();
232 }
233
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200234 void Alert_RtpLogTimeGap(PacketDirection direction,
235 float time_seconds,
236 int64_t duration) {
237 if (direction == kIncomingPacket) {
238 incoming_rtp_recv_time_gaps_.emplace_back(time_seconds, duration);
239 } else {
240 outgoing_rtp_send_time_gaps_.emplace_back(time_seconds, duration);
241 }
242 }
243
244 void Alert_RtcpLogTimeGap(PacketDirection direction,
245 float time_seconds,
246 int64_t duration) {
247 if (direction == kIncomingPacket) {
248 incoming_rtcp_recv_time_gaps_.emplace_back(time_seconds, duration);
249 } else {
250 outgoing_rtcp_send_time_gaps_.emplace_back(time_seconds, duration);
251 }
252 }
253
254 void Alert_SeqNumJump(PacketDirection direction,
255 float time_seconds,
256 uint32_t ssrc) {
257 if (direction == kIncomingPacket) {
258 incoming_seq_num_jumps_.emplace_back(time_seconds, ssrc);
259 } else {
260 outgoing_seq_num_jumps_.emplace_back(time_seconds, ssrc);
261 }
262 }
263
264 void Alert_CaptureTimeJump(PacketDirection direction,
265 float time_seconds,
266 uint32_t ssrc) {
267 if (direction == kIncomingPacket) {
268 incoming_capture_time_jumps_.emplace_back(time_seconds, ssrc);
269 } else {
270 outgoing_capture_time_jumps_.emplace_back(time_seconds, ssrc);
271 }
272 }
273
274 void Alert_OutgoingHighLoss(double avg_loss_fraction) {
275 outgoing_high_loss_alerts_.emplace_back(avg_loss_fraction);
276 }
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100277
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800278 std::string GetCandidatePairLogDescriptionFromId(uint32_t candidate_pair_id);
279
Sebastian Janssonb290a6d2019-01-03 14:46:23 +0100280 const ParsedRtcEventLog& parsed_log_;
terelius54ce6802016-07-13 06:44:41 -0700281
282 // A list of SSRCs we are interested in analysing.
283 // If left empty, all SSRCs will be considered relevant.
284 std::vector<uint32_t> desired_ssrc_;
285
henrik.lundin3c938fc2017-06-14 06:09:58 -0700286 // Stores the timestamps for all log segments, in the form of associated start
287 // and end events.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200288 std::vector<std::pair<int64_t, int64_t>> log_segments_;
henrik.lundin3c938fc2017-06-14 06:09:58 -0700289
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200290 std::vector<IncomingRtpReceiveTimeGap> incoming_rtp_recv_time_gaps_;
291 std::vector<IncomingRtcpReceiveTimeGap> incoming_rtcp_recv_time_gaps_;
292 std::vector<OutgoingRtpSendTimeGap> outgoing_rtp_send_time_gaps_;
293 std::vector<OutgoingRtcpSendTimeGap> outgoing_rtcp_send_time_gaps_;
294 std::vector<IncomingSeqNumJump> incoming_seq_num_jumps_;
295 std::vector<IncomingCaptureTimeJump> incoming_capture_time_jumps_;
296 std::vector<OutgoingSeqNoJump> outgoing_seq_num_jumps_;
297 std::vector<OutgoingCaptureTimeJump> outgoing_capture_time_jumps_;
298 std::vector<OutgoingHighLoss> outgoing_high_loss_alerts_;
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800299
300 std::map<uint32_t, std::string> candidate_pair_desc_by_id_;
301
Bjorn Terelius068fc352019-02-13 22:38:25 +0100302 AnalyzerConfig config_;
terelius54ce6802016-07-13 06:44:41 -0700303};
304
terelius54ce6802016-07-13 06:44:41 -0700305} // namespace webrtc
306
Mirko Bonadei575998c2019-07-25 13:57:41 +0200307#endif // RTC_TOOLS_RTC_EVENT_LOG_VISUALIZER_ANALYZER_H_