blob: 35a44b903ff96a7d1e42ecb1bd6d6d5331cc5e27 [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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef RTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_
12#define RTC_TOOLS_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
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020021#include "logging/rtc_event_log/rtc_event_log_parser_new.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 Bonadei92ea95e2017-09-15 06:47:31 +020024#include "rtc_tools/event_log_visualizer/plot_base.h"
Bjorn Terelius2eb31882017-11-30 15:15:25 +010025#include "rtc_tools/event_log_visualizer/triage_notifications.h"
terelius54ce6802016-07-13 06:44:41 -070026
27namespace webrtc {
michaelt6e5b2192017-02-22 07:33:27 -080028
terelius54ce6802016-07-13 06:44:41 -070029class EventLogAnalyzer {
30 public:
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020031 // The EventLogAnalyzer keeps a reference to the ParsedRtcEventLogNew for the
32 // duration of its lifetime. The ParsedRtcEventLogNew must not be destroyed or
terelius54ce6802016-07-13 06:44:41 -070033 // modified while the EventLogAnalyzer is being used.
Stefan Holmer1d4a2272018-05-24 13:48:09 +020034 EventLogAnalyzer(const ParsedRtcEventLogNew& log, bool normalize_time);
terelius54ce6802016-07-13 06:44:41 -070035
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020036 void CreatePacketGraph(PacketDirection direction, Plot* plot);
terelius54ce6802016-07-13 06:44:41 -070037
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020038 void CreateAccumulatedPacketsGraph(PacketDirection direction, Plot* plot);
philipelccd74892016-09-05 02:46:25 -070039
terelius54ce6802016-07-13 06:44:41 -070040 void CreatePlayoutGraph(Plot* plot);
41
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020042 void CreateAudioLevelGraph(PacketDirection direction, Plot* plot);
ivocaac9d6f2016-09-22 07:01:47 -070043
terelius54ce6802016-07-13 06:44:41 -070044 void CreateSequenceNumberGraph(Plot* plot);
45
Stefan Holmer99f8e082016-09-09 13:37:50 +020046 void CreateIncomingPacketLossGraph(Plot* plot);
47
terelius2ee076d2017-08-15 02:04:02 -070048 void CreateIncomingDelayGraph(Plot* plot);
terelius54ce6802016-07-13 06:44:41 -070049
tereliusf736d232016-08-04 10:00:11 -070050 void CreateFractionLossGraph(Plot* plot);
51
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020052 void CreateTotalIncomingBitrateGraph(Plot* plot);
53 void CreateTotalOutgoingBitrateGraph(Plot* plot,
54 bool show_detector_state = false,
55 bool show_alr_state = false);
terelius54ce6802016-07-13 06:44:41 -070056
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020057 void CreateStreamBitrateGraph(PacketDirection direction, Plot* plot);
terelius54ce6802016-07-13 06:44:41 -070058
Bjorn Terelius28db2662017-10-04 14:22:43 +020059 void CreateSendSideBweSimulationGraph(Plot* plot);
60 void CreateReceiveSideBweSimulationGraph(Plot* plot);
Stefan Holmer13181032016-07-29 14:48:54 +020061
tereliuse34c19c2016-08-15 08:47:14 -070062 void CreateNetworkDelayFeedbackGraph(Plot* plot);
Bjorn Terelius0295a962017-10-25 17:42:41 +020063 void CreatePacerDelayGraph(Plot* plot);
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020064
65 void CreateTimestampGraph(PacketDirection direction, Plot* plot);
Bjorn Tereliusb1222c22018-07-24 13:45:31 +020066 void CreateSenderAndReceiverReportPlot(
67 PacketDirection direction,
68 rtc::FunctionView<float(const rtcp::ReportBlock&)> fy,
69 std::string title,
70 std::string yaxis_label,
71 Plot* plot);
stefanc3de0332016-08-02 07:22:17 -070072
michaelt6e5b2192017-02-22 07:33:27 -080073 void CreateAudioEncoderTargetBitrateGraph(Plot* plot);
74 void CreateAudioEncoderFrameLengthGraph(Plot* plot);
terelius2ee076d2017-08-15 02:04:02 -070075 void CreateAudioEncoderPacketLossGraph(Plot* plot);
michaelt6e5b2192017-02-22 07:33:27 -080076 void CreateAudioEncoderEnableFecGraph(Plot* plot);
77 void CreateAudioEncoderEnableDtxGraph(Plot* plot);
78 void CreateAudioEncoderNumChannelsGraph(Plot* plot);
Minyue Lic6ff7572018-05-04 09:46:44 +020079
80 using NetEqStatsGetterMap =
81 std::map<uint32_t, std::unique_ptr<test::NetEqStatsGetter>>;
82 NetEqStatsGetterMap SimulateNetEq(const std::string& replacement_file_name,
83 int file_sample_rate_hz) const;
Minyue Lic9ac93f2018-06-26 13:01:32 +020084
Minyue Li01d2a672018-06-21 21:17:19 +020085 void CreateAudioJitterBufferGraph(uint32_t ssrc,
86 const test::NetEqStatsGetter* stats_getter,
87 Plot* plot) const;
Minyue Lic9ac93f2018-06-26 13:01:32 +020088 void CreateNetEqNetworkStatsGraph(
Minyue Li27e2b7d2018-05-07 15:20:24 +020089 const NetEqStatsGetterMap& neteq_stats_getters,
90 rtc::FunctionView<float(const NetEqNetworkStatistics&)> stats_extractor,
91 const std::string& plot_name,
92 Plot* plot) const;
Minyue Lic9ac93f2018-06-26 13:01:32 +020093 void CreateNetEqLifetimeStatsGraph(
94 const NetEqStatsGetterMap& neteq_stats_getters,
95 rtc::FunctionView<float(const NetEqLifetimeStatistics&)> stats_extractor,
96 const std::string& plot_name,
97 Plot* plot) const;
michaelt6e5b2192017-02-22 07:33:27 -080098
Qingsi Wang8eca1ff2018-02-02 11:49:44 -080099 void CreateIceCandidatePairConfigGraph(Plot* plot);
100 void CreateIceConnectivityCheckGraph(Plot* plot);
101
Zach Stein10a58012018-12-07 12:26:28 -0800102 void CreateDtlsTransportStateGraph(Plot* plot);
103 void CreateDtlsWritableStateGraph(Plot* plot);
104
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100105 void CreateTriageNotifications();
106 void PrintNotifications(FILE* file);
107
terelius54ce6802016-07-13 06:44:41 -0700108 private:
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200109 bool IsRtxSsrc(PacketDirection direction, uint32_t ssrc) const {
110 if (direction == kIncomingPacket) {
111 return parsed_log_.incoming_rtx_ssrcs().find(ssrc) !=
112 parsed_log_.incoming_rtx_ssrcs().end();
113 } else {
114 return parsed_log_.outgoing_rtx_ssrcs().find(ssrc) !=
115 parsed_log_.outgoing_rtx_ssrcs().end();
terelius0740a202016-08-08 10:21:04 -0700116 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200117 }
118
119 bool IsVideoSsrc(PacketDirection direction, uint32_t ssrc) const {
120 if (direction == kIncomingPacket) {
121 return parsed_log_.incoming_video_ssrcs().find(ssrc) !=
122 parsed_log_.incoming_video_ssrcs().end();
123 } else {
124 return parsed_log_.outgoing_video_ssrcs().find(ssrc) !=
125 parsed_log_.outgoing_video_ssrcs().end();
terelius0740a202016-08-08 10:21:04 -0700126 }
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200127 }
terelius88e64e52016-07-19 01:51:06 -0700128
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200129 bool IsAudioSsrc(PacketDirection direction, uint32_t ssrc) const {
130 if (direction == kIncomingPacket) {
131 return parsed_log_.incoming_audio_ssrcs().find(ssrc) !=
132 parsed_log_.incoming_audio_ssrcs().end();
133 } else {
134 return parsed_log_.outgoing_audio_ssrcs().find(ssrc) !=
135 parsed_log_.outgoing_audio_ssrcs().end();
136 }
137 }
terelius88e64e52016-07-19 01:51:06 -0700138
Minyue Lic9ac93f2018-06-26 13:01:32 +0200139 template <typename NetEqStatsType>
140 void CreateNetEqStatsGraphInternal(
141 const NetEqStatsGetterMap& neteq_stats,
142 rtc::FunctionView<const std::vector<std::pair<int64_t, NetEqStatsType>>*(
143 const test::NetEqStatsGetter*)> data_extractor,
144 rtc::FunctionView<float(const NetEqStatsType&)> stats_extractor,
145 const std::string& plot_name,
146 Plot* plot) const;
147
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200148 template <typename IterableType>
149 void CreateAccumulatedPacketsTimeSeries(Plot* plot,
150 const IterableType& packets,
151 const std::string& label);
philipelccd74892016-09-05 02:46:25 -0700152
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200153 void CreateStreamGapAlerts(PacketDirection direction);
154 void CreateTransmissionGapAlerts(PacketDirection direction);
terelius0740a202016-08-08 10:21:04 -0700155
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200156 std::string GetStreamName(PacketDirection direction, uint32_t ssrc) const {
157 char buffer[200];
158 rtc::SimpleStringBuilder name(buffer);
159 if (IsAudioSsrc(direction, ssrc)) {
160 name << "Audio ";
161 } else if (IsVideoSsrc(direction, ssrc)) {
162 name << "Video ";
163 } else {
164 name << "Unknown ";
165 }
166 if (IsRtxSsrc(direction, ssrc)) {
167 name << "RTX ";
168 }
169 if (direction == kIncomingPacket)
170 name << "(In) ";
171 else
172 name << "(Out) ";
173 name << "SSRC " << ssrc;
174 return name.str();
175 }
terelius0740a202016-08-08 10:21:04 -0700176
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200177 int64_t ToCallTimeUs(int64_t timestamp) const;
178 float ToCallTimeSec(int64_t timestamp) const;
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100179
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200180 void Alert_RtpLogTimeGap(PacketDirection direction,
181 float time_seconds,
182 int64_t duration) {
183 if (direction == kIncomingPacket) {
184 incoming_rtp_recv_time_gaps_.emplace_back(time_seconds, duration);
185 } else {
186 outgoing_rtp_send_time_gaps_.emplace_back(time_seconds, duration);
187 }
188 }
189
190 void Alert_RtcpLogTimeGap(PacketDirection direction,
191 float time_seconds,
192 int64_t duration) {
193 if (direction == kIncomingPacket) {
194 incoming_rtcp_recv_time_gaps_.emplace_back(time_seconds, duration);
195 } else {
196 outgoing_rtcp_send_time_gaps_.emplace_back(time_seconds, duration);
197 }
198 }
199
200 void Alert_SeqNumJump(PacketDirection direction,
201 float time_seconds,
202 uint32_t ssrc) {
203 if (direction == kIncomingPacket) {
204 incoming_seq_num_jumps_.emplace_back(time_seconds, ssrc);
205 } else {
206 outgoing_seq_num_jumps_.emplace_back(time_seconds, ssrc);
207 }
208 }
209
210 void Alert_CaptureTimeJump(PacketDirection direction,
211 float time_seconds,
212 uint32_t ssrc) {
213 if (direction == kIncomingPacket) {
214 incoming_capture_time_jumps_.emplace_back(time_seconds, ssrc);
215 } else {
216 outgoing_capture_time_jumps_.emplace_back(time_seconds, ssrc);
217 }
218 }
219
220 void Alert_OutgoingHighLoss(double avg_loss_fraction) {
221 outgoing_high_loss_alerts_.emplace_back(avg_loss_fraction);
222 }
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100223
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800224 std::string GetCandidatePairLogDescriptionFromId(uint32_t candidate_pair_id);
225
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200226 const ParsedRtcEventLogNew& parsed_log_;
terelius54ce6802016-07-13 06:44:41 -0700227
228 // A list of SSRCs we are interested in analysing.
229 // If left empty, all SSRCs will be considered relevant.
230 std::vector<uint32_t> desired_ssrc_;
231
henrik.lundin3c938fc2017-06-14 06:09:58 -0700232 // Stores the timestamps for all log segments, in the form of associated start
233 // and end events.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200234 std::vector<std::pair<int64_t, int64_t>> log_segments_;
henrik.lundin3c938fc2017-06-14 06:09:58 -0700235
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200236 std::vector<IncomingRtpReceiveTimeGap> incoming_rtp_recv_time_gaps_;
237 std::vector<IncomingRtcpReceiveTimeGap> incoming_rtcp_recv_time_gaps_;
238 std::vector<OutgoingRtpSendTimeGap> outgoing_rtp_send_time_gaps_;
239 std::vector<OutgoingRtcpSendTimeGap> outgoing_rtcp_send_time_gaps_;
240 std::vector<IncomingSeqNumJump> incoming_seq_num_jumps_;
241 std::vector<IncomingCaptureTimeJump> incoming_capture_time_jumps_;
242 std::vector<OutgoingSeqNoJump> outgoing_seq_num_jumps_;
243 std::vector<OutgoingCaptureTimeJump> outgoing_capture_time_jumps_;
244 std::vector<OutgoingHighLoss> outgoing_high_loss_alerts_;
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800245
246 std::map<uint32_t, std::string> candidate_pair_desc_by_id_;
247
terelius54ce6802016-07-13 06:44:41 -0700248 // Window and step size used for calculating moving averages, e.g. bitrate.
249 // The generated data points will be |step_| microseconds apart.
250 // Only events occuring at most |window_duration_| microseconds before the
251 // current data point will be part of the average.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200252 int64_t window_duration_;
253 int64_t step_;
terelius54ce6802016-07-13 06:44:41 -0700254
255 // First and last events of the log.
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200256 int64_t begin_time_;
257 int64_t end_time_;
Stefan Holmer1d4a2272018-05-24 13:48:09 +0200258 const bool normalize_time_;
tereliusdc35dcd2016-08-01 12:03:27 -0700259
260 // Duration (in seconds) of log file.
261 float call_duration_s_;
terelius54ce6802016-07-13 06:44:41 -0700262};
263
terelius54ce6802016-07-13 06:44:41 -0700264} // namespace webrtc
265
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200266#endif // RTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_