blob: 21768c92d1a01ade0713fa0dd1af49b263ed4a20 [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
Yves Gerey3e707812018-11-28 16:47:49 +010011#include <stdio.h>
12#include <string.h>
Jonas Olsson5b2eda42019-06-11 14:29:40 +020013
terelius54ce6802016-07-13 06:44:41 -070014#include <iostream>
Yves Gerey3e707812018-11-28 16:47:49 +010015#include <map>
16#include <memory>
17#include <string>
18#include <utility>
Mirko Bonadei4b091f42019-07-16 11:55:08 +020019#include <vector>
terelius54ce6802016-07-13 06:44:41 -070020
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +020021#include "absl/algorithm/container.h"
Mirko Bonadei4b091f42019-07-16 11:55:08 +020022#include "absl/flags/flag.h"
23#include "absl/flags/parse.h"
Mirko Bonadeif2d97b82019-07-24 15:29:47 +020024#include "absl/flags/usage.h"
25#include "absl/flags/usage_config.h"
26#include "absl/strings/match.h"
Ivo Creusen3ce44a32019-10-31 14:38:11 +010027#include "api/neteq/neteq.h"
Danil Chapovalov83bbe912019-08-07 12:24:53 +020028#include "api/rtc_event_log/rtc_event_log.h"
Sebastian Janssonb290a6d2019-01-03 14:46:23 +010029#include "logging/rtc_event_log/rtc_event_log_parser.h"
Yves Gerey3e707812018-11-28 16:47:49 +010030#include "modules/rtp_rtcp/source/rtcp_packet/report_block.h"
31#include "rtc_base/checks.h"
Björn Tereliusa06048a2019-11-01 14:31:46 +010032#include "rtc_base/logging.h"
Bjorn Terelius48b82792020-05-19 10:57:24 +020033#include "rtc_tools/rtc_event_log_visualizer/alerts.h"
Mirko Bonadei575998c2019-07-25 13:57:41 +020034#include "rtc_tools/rtc_event_log_visualizer/analyzer.h"
35#include "rtc_tools/rtc_event_log_visualizer/plot_base.h"
36#include "rtc_tools/rtc_event_log_visualizer/plot_protobuf.h"
37#include "rtc_tools/rtc_event_log_visualizer/plot_python.h"
Mirko Bonadei17f48782018-09-28 08:51:10 +020038#include "system_wrappers/include/field_trial.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020039#include "test/field_trial.h"
Steve Anton10542f22019-01-11 09:11:00 -080040#include "test/testsupport/file_utils.h"
terelius54ce6802016-07-13 06:44:41 -070041
Mirko Bonadei4b091f42019-07-16 11:55:08 +020042ABSL_FLAG(std::string,
43 plot,
44 "default",
Mirko Bonadeif2d97b82019-07-24 15:29:47 +020045 "A comma separated list of plot names. See --list_plots for valid "
46 "options.");
Bjorn Terelius1edfff92017-10-11 13:15:19 +020047
Mirko Bonadei4b091f42019-07-16 11:55:08 +020048ABSL_FLAG(
49 std::string,
stefan985d2802016-11-15 06:54:09 -080050 force_fieldtrials,
51 "",
52 "Field trials control experimental feature code which can be forced. "
53 "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enabled/"
54 " will assign the group Enabled to field trial WebRTC-FooFeature. Multiple "
55 "trials are separated by \"/\"");
Mirko Bonadei4b091f42019-07-16 11:55:08 +020056ABSL_FLAG(std::string,
57 wav_filename,
58 "",
59 "Path to wav file used for simulation of jitter buffer");
terelius54ce6802016-07-13 06:44:41 -070060
Mirko Bonadei4b091f42019-07-16 11:55:08 +020061ABSL_FLAG(bool,
62 show_detector_state,
63 false,
64 "Show the state of the delay based BWE detector on the total "
65 "bitrate graph");
terelius2ee076d2017-08-15 02:04:02 -070066
Mirko Bonadei4b091f42019-07-16 11:55:08 +020067ABSL_FLAG(bool,
68 show_alr_state,
69 false,
70 "Show the state ALR state on the total bitrate graph");
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +010071
Mirko Bonadei4b091f42019-07-16 11:55:08 +020072ABSL_FLAG(bool,
73 parse_unconfigured_header_extensions,
74 true,
75 "Attempt to parse unconfigured header extensions using the default "
76 "WebRTC mapping. This can give very misleading results if the "
77 "application negotiates a different mapping.");
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020078
Mirko Bonadei4b091f42019-07-16 11:55:08 +020079ABSL_FLAG(bool,
80 print_triage_alerts,
81 false,
82 "Print triage alerts, i.e. a list of potential problems.");
Bjorn Terelius2eb31882017-11-30 15:15:25 +010083
Mirko Bonadei4b091f42019-07-16 11:55:08 +020084ABSL_FLAG(bool,
85 normalize_time,
86 true,
87 "Normalize the log timestamps so that the call starts at time 0.");
Stefan Holmer1d4a2272018-05-24 13:48:09 +020088
Mirko Bonadei4b091f42019-07-16 11:55:08 +020089ABSL_FLAG(bool,
90 shared_xaxis,
91 false,
92 "Share x-axis between all plots so that zooming in one plot "
93 "updates all the others too. A downside is that certain "
94 "operations like panning become much slower.");
Bjorn Tereliusff8cce32019-04-11 18:34:01 +020095
Mirko Bonadei4b091f42019-07-16 11:55:08 +020096ABSL_FLAG(bool,
97 protobuf_output,
98 false,
99 "Output charts as protobuf instead of python code.");
Bjorn Tereliusef73f592018-09-10 20:11:49 +0200100
Mirko Bonadeif2d97b82019-07-24 15:29:47 +0200101ABSL_FLAG(bool,
102 list_plots,
103 false,
104 "List of registered plots (for use with the --plot flag)");
105
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200106using webrtc::Plot;
107
108namespace {
109std::vector<std::string> StrSplit(const std::string& s,
110 const std::string& delimiter) {
111 std::vector<std::string> v;
112 size_t pos = 0;
113 while (pos < s.length()) {
114 const std::string token = s.substr(pos, s.find(delimiter, pos) - pos);
115 pos += token.length() + delimiter.length();
116 v.push_back(token);
117 }
118 return v;
119}
120
121struct PlotDeclaration {
122 PlotDeclaration(const std::string& label, std::function<void(Plot*)> f)
123 : label(label), enabled(false), plot_func(f) {}
124 const std::string label;
125 bool enabled;
126 // TODO(terelius): Add a help text/explanation.
127 const std::function<void(Plot*)> plot_func;
128};
129
130class PlotMap {
131 public:
132 void RegisterPlot(const std::string& label, std::function<void(Plot*)> f) {
133 for (const auto& plot : plots_) {
134 RTC_DCHECK(plot.label != label)
135 << "Can't use the same label for multiple plots";
136 }
137 plots_.push_back({label, f});
138 }
139
140 bool EnablePlotsByFlags(
141 const std::vector<std::string>& flags,
142 const std::map<std::string, std::vector<std::string>>& flag_aliases) {
143 bool status = true;
144 for (const std::string& flag : flags) {
145 auto alias_it = flag_aliases.find(flag);
146 if (alias_it != flag_aliases.end()) {
147 const auto& replacements = alias_it->second;
148 for (const auto& replacement : replacements) {
149 status &= EnablePlotByFlag(replacement);
150 }
151 } else {
152 status &= EnablePlotByFlag(flag);
153 }
154 }
155 return status;
156 }
157
158 void EnableAllPlots() {
159 for (auto& plot : plots_) {
160 plot.enabled = true;
161 }
162 }
163
164 std::vector<PlotDeclaration>::iterator begin() { return plots_.begin(); }
165 std::vector<PlotDeclaration>::iterator end() { return plots_.end(); }
166
167 private:
168 bool EnablePlotByFlag(const std::string& flag) {
169 for (auto& plot : plots_) {
170 if (plot.label == flag) {
171 plot.enabled = true;
172 return true;
173 }
174 }
175 if (flag == "simulated_neteq_jitter_buffer_delay") {
176 // This flag is handled separately.
177 return true;
178 }
179 std::cerr << "Unrecognized plot name \'" << flag << "\'. Aborting."
180 << std::endl;
181 return false;
182 }
183
184 std::vector<PlotDeclaration> plots_;
185};
Mirko Bonadeif2d97b82019-07-24 15:29:47 +0200186
187bool ContainsHelppackageFlags(absl::string_view filename) {
188 return absl::EndsWith(filename, "main.cc");
189}
190
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200191} // namespace
terelius2ee076d2017-08-15 02:04:02 -0700192
terelius54ce6802016-07-13 06:44:41 -0700193int main(int argc, char* argv[]) {
Mirko Bonadeif2d97b82019-07-24 15:29:47 +0200194 absl::SetProgramUsageMessage(
terelius54ce6802016-07-13 06:44:41 -0700195 "A tool for visualizing WebRTC event logs.\n"
Mirko Bonadeif2d97b82019-07-24 15:29:47 +0200196 "Example usage:\n"
197 "./event_log_visualizer <logfile> | python\n");
Bjorn Terelius48b82792020-05-19 10:57:24 +0200198 absl::FlagsUsageConfig flag_config;
199 flag_config.contains_help_flags = &ContainsHelppackageFlags;
200 absl::SetFlagsUsageConfig(flag_config);
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200201 std::vector<char*> args = absl::ParseCommandLine(argc, argv);
202
Björn Tereliusa06048a2019-11-01 14:31:46 +0100203 // Print RTC_LOG warnings and errors even in release builds.
204 if (rtc::LogMessage::GetLogToDebug() > rtc::LS_WARNING) {
205 rtc::LogMessage::LogToDebug(rtc::LS_WARNING);
206 }
207 rtc::LogMessage::SetLogToStderr(true);
208
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200209 // Flag replacements
210 std::map<std::string, std::vector<std::string>> flag_aliases = {
211 {"default",
212 {"incoming_delay", "incoming_loss_rate", "incoming_bitrate",
Bjorn Terelius873a7a92019-06-13 16:01:17 +0200213 "outgoing_bitrate", "incoming_stream_bitrate",
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200214 "outgoing_stream_bitrate", "network_delay_feedback",
215 "fraction_loss_feedback"}},
216 {"sendside_bwe",
217 {"outgoing_packet_sizes", "outgoing_bitrate", "outgoing_stream_bitrate",
218 "simulated_sendside_bwe", "network_delay_feedback",
219 "fraction_loss_feedback"}},
220 {"receiveside_bwe",
221 {"incoming_packet_sizes", "incoming_delay", "incoming_loss_rate",
Bjorn Terelius873a7a92019-06-13 16:01:17 +0200222 "incoming_bitrate", "incoming_stream_bitrate",
223 "simulated_receiveside_bwe"}},
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200224 {"rtcp_details",
225 {"incoming_rtcp_fraction_lost", "outgoing_rtcp_fraction_lost",
Bjorn Terelius873a7a92019-06-13 16:01:17 +0200226 "incoming_rtcp_cumulative_lost", "outgoing_rtcp_cumulative_lost",
227 "incoming_rtcp_highest_seq_number", "outgoing_rtcp_highest_seq_number",
228 "incoming_rtcp_delay_since_last_sr",
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200229 "outgoing_rtcp_delay_since_last_sr"}},
230 {"simulated_neteq_stats",
231 {"simulated_neteq_jitter_buffer_delay",
Bjorn Terelius873a7a92019-06-13 16:01:17 +0200232 "simulated_neteq_preferred_buffer_size",
233 "simulated_neteq_concealment_events",
234 "simulated_neteq_packet_loss_rate", "simulated_neteq_preemptive_rate",
235 "simulated_neteq_accelerate_rate", "simulated_neteq_speech_expand_rate",
236 "simulated_neteq_expand_rate"}}};
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200237
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200238 std::vector<std::string> plot_flags =
239 StrSplit(absl::GetFlag(FLAGS_plot), ",");
kjellander4fa5be42017-05-16 00:01:23 -0700240
Bjorn Tereliusedab3012018-01-31 17:23:40 +0100241 // InitFieldTrialsFromString stores the char*, so the char array must outlive
242 // the application.
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200243 const std::string field_trials = absl::GetFlag(FLAGS_force_fieldtrials);
244 webrtc::field_trial::InitFieldTrialsFromString(field_trials.c_str());
stefan985d2802016-11-15 06:54:09 -0800245
Sebastian Janssonb290a6d2019-01-03 14:46:23 +0100246 webrtc::ParsedRtcEventLog::UnconfiguredHeaderExtensions header_extensions =
247 webrtc::ParsedRtcEventLog::UnconfiguredHeaderExtensions::kDontParse;
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200248 if (absl::GetFlag(FLAGS_parse_unconfigured_header_extensions)) {
Sebastian Janssonb290a6d2019-01-03 14:46:23 +0100249 header_extensions = webrtc::ParsedRtcEventLog::
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200250 UnconfiguredHeaderExtensions::kAttemptWebrtcDefaultConfig;
251 }
Björn Tereliusa06048a2019-11-01 14:31:46 +0100252 webrtc::ParsedRtcEventLog parsed_log(header_extensions,
253 /*allow_incomplete_logs*/ true);
terelius54ce6802016-07-13 06:44:41 -0700254
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200255 if (args.size() == 2) {
256 std::string filename = args[1];
Björn Tereliusa06048a2019-11-01 14:31:46 +0100257 auto status = parsed_log.ParseFile(filename);
258 if (!status.ok()) {
259 std::cerr << "Failed to parse " << filename << ": " << status.message()
260 << std::endl;
261 return -1;
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200262 }
terelius54ce6802016-07-13 06:44:41 -0700263 }
264
Bjorn Terelius48b82792020-05-19 10:57:24 +0200265 webrtc::AnalyzerConfig config;
266 config.window_duration_ = 250000;
267 config.step_ = 10000;
268 config.normalize_time_ = absl::GetFlag(FLAGS_normalize_time);
269 config.begin_time_ = parsed_log.first_timestamp();
270 config.end_time_ = parsed_log.last_timestamp();
271 if (config.end_time_ < config.begin_time_) {
272 RTC_LOG(LS_WARNING) << "Log end time " << config.end_time_
273 << " not after begin time " << config.begin_time_
274 << ". Nothing to analyze. Is the log broken?";
275 return -1;
276 }
277
278 webrtc::EventLogAnalyzer analyzer(parsed_log, config);
Bjorn Tereliusef73f592018-09-10 20:11:49 +0200279 std::unique_ptr<webrtc::PlotCollection> collection;
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200280 if (absl::GetFlag(FLAGS_protobuf_output)) {
Bjorn Tereliusef73f592018-09-10 20:11:49 +0200281 collection.reset(new webrtc::ProtobufPlotCollection());
282 } else {
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200283 collection.reset(
284 new webrtc::PythonPlotCollection(absl::GetFlag(FLAGS_shared_xaxis)));
Bjorn Tereliusef73f592018-09-10 20:11:49 +0200285 }
terelius54ce6802016-07-13 06:44:41 -0700286
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200287 PlotMap plots;
288 plots.RegisterPlot("incoming_packet_sizes", [&](Plot* plot) {
289 analyzer.CreatePacketGraph(webrtc::kIncomingPacket, plot);
290 });
291
292 plots.RegisterPlot("outgoing_packet_sizes", [&](Plot* plot) {
293 analyzer.CreatePacketGraph(webrtc::kOutgoingPacket, plot);
294 });
295 plots.RegisterPlot("incoming_rtcp_types", [&](Plot* plot) {
296 analyzer.CreateRtcpTypeGraph(webrtc::kIncomingPacket, plot);
297 });
298 plots.RegisterPlot("outgoing_rtcp_types", [&](Plot* plot) {
299 analyzer.CreateRtcpTypeGraph(webrtc::kOutgoingPacket, plot);
300 });
301 plots.RegisterPlot("incoming_packet_count", [&](Plot* plot) {
302 analyzer.CreateAccumulatedPacketsGraph(webrtc::kIncomingPacket, plot);
303 });
304 plots.RegisterPlot("outgoing_packet_count", [&](Plot* plot) {
305 analyzer.CreateAccumulatedPacketsGraph(webrtc::kOutgoingPacket, plot);
306 });
Kristoffer Erlandsson283c1062020-03-30 13:01:37 +0200307 plots.RegisterPlot("incoming_packet_rate", [&](Plot* plot) {
308 analyzer.CreatePacketRateGraph(webrtc::kIncomingPacket, plot);
309 });
310 plots.RegisterPlot("outgoing_packet_rate", [&](Plot* plot) {
311 analyzer.CreatePacketRateGraph(webrtc::kOutgoingPacket, plot);
312 });
Kristoffer Erlandssona2ce4232020-04-01 14:33:30 +0200313 plots.RegisterPlot("total_incoming_packet_rate", [&](Plot* plot) {
314 analyzer.CreateTotalPacketRateGraph(webrtc::kIncomingPacket, plot);
315 });
316 plots.RegisterPlot("total_outgoing_packet_rate", [&](Plot* plot) {
317 analyzer.CreateTotalPacketRateGraph(webrtc::kOutgoingPacket, plot);
318 });
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200319 plots.RegisterPlot("audio_playout",
320 [&](Plot* plot) { analyzer.CreatePlayoutGraph(plot); });
321 plots.RegisterPlot("incoming_audio_level", [&](Plot* plot) {
322 analyzer.CreateAudioLevelGraph(webrtc::kIncomingPacket, plot);
323 });
324 plots.RegisterPlot("outgoing_audio_level", [&](Plot* plot) {
325 analyzer.CreateAudioLevelGraph(webrtc::kOutgoingPacket, plot);
326 });
327 plots.RegisterPlot("incoming_sequence_number_delta", [&](Plot* plot) {
328 analyzer.CreateSequenceNumberGraph(plot);
329 });
330 plots.RegisterPlot("incoming_delay", [&](Plot* plot) {
331 analyzer.CreateIncomingDelayGraph(plot);
332 });
333 plots.RegisterPlot("incoming_loss_rate", [&](Plot* plot) {
334 analyzer.CreateIncomingPacketLossGraph(plot);
335 });
336 plots.RegisterPlot("incoming_bitrate", [&](Plot* plot) {
337 analyzer.CreateTotalIncomingBitrateGraph(plot);
338 });
339 plots.RegisterPlot("outgoing_bitrate", [&](Plot* plot) {
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200340 analyzer.CreateTotalOutgoingBitrateGraph(
341 plot, absl::GetFlag(FLAGS_show_detector_state),
342 absl::GetFlag(FLAGS_show_alr_state));
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200343 });
344 plots.RegisterPlot("incoming_stream_bitrate", [&](Plot* plot) {
345 analyzer.CreateStreamBitrateGraph(webrtc::kIncomingPacket, plot);
346 });
347 plots.RegisterPlot("outgoing_stream_bitrate", [&](Plot* plot) {
348 analyzer.CreateStreamBitrateGraph(webrtc::kOutgoingPacket, plot);
349 });
350 plots.RegisterPlot("incoming_layer_bitrate_allocation", [&](Plot* plot) {
351 analyzer.CreateBitrateAllocationGraph(webrtc::kIncomingPacket, plot);
352 });
353 plots.RegisterPlot("outgoing_layer_bitrate_allocation", [&](Plot* plot) {
354 analyzer.CreateBitrateAllocationGraph(webrtc::kOutgoingPacket, plot);
355 });
356 plots.RegisterPlot("simulated_receiveside_bwe", [&](Plot* plot) {
357 analyzer.CreateReceiveSideBweSimulationGraph(plot);
358 });
359 plots.RegisterPlot("simulated_sendside_bwe", [&](Plot* plot) {
360 analyzer.CreateSendSideBweSimulationGraph(plot);
361 });
362 plots.RegisterPlot("simulated_goog_cc", [&](Plot* plot) {
363 analyzer.CreateGoogCcSimulationGraph(plot);
364 });
365 plots.RegisterPlot("network_delay_feedback", [&](Plot* plot) {
366 analyzer.CreateNetworkDelayFeedbackGraph(plot);
367 });
368 plots.RegisterPlot("fraction_loss_feedback", [&](Plot* plot) {
369 analyzer.CreateFractionLossGraph(plot);
370 });
371 plots.RegisterPlot("incoming_timestamps", [&](Plot* plot) {
372 analyzer.CreateTimestampGraph(webrtc::kIncomingPacket, plot);
373 });
374 plots.RegisterPlot("outgoing_timestamps", [&](Plot* plot) {
375 analyzer.CreateTimestampGraph(webrtc::kOutgoingPacket, plot);
376 });
377
378 auto GetFractionLost = [](const webrtc::rtcp::ReportBlock& block) -> float {
379 return static_cast<double>(block.fraction_lost()) / 256 * 100;
380 };
381 plots.RegisterPlot("incoming_rtcp_fraction_lost", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200382 analyzer.CreateSenderAndReceiverReportPlot(
383 webrtc::kIncomingPacket, GetFractionLost,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200384 "Fraction lost (incoming RTCP)", "Loss rate (percent)", plot);
385 });
386 plots.RegisterPlot("outgoing_rtcp_fraction_lost", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200387 analyzer.CreateSenderAndReceiverReportPlot(
388 webrtc::kOutgoingPacket, GetFractionLost,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200389 "Fraction lost (outgoing RTCP)", "Loss rate (percent)", plot);
390 });
391 auto GetCumulativeLost = [](const webrtc::rtcp::ReportBlock& block) -> float {
392 return block.cumulative_lost_signed();
393 };
394 plots.RegisterPlot("incoming_rtcp_cumulative_lost", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200395 analyzer.CreateSenderAndReceiverReportPlot(
396 webrtc::kIncomingPacket, GetCumulativeLost,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200397 "Cumulative lost packets (incoming RTCP)", "Packets", plot);
398 });
399 plots.RegisterPlot("outgoing_rtcp_cumulative_lost", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200400 analyzer.CreateSenderAndReceiverReportPlot(
401 webrtc::kOutgoingPacket, GetCumulativeLost,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200402 "Cumulative lost packets (outgoing RTCP)", "Packets", plot);
403 });
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200404
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200405 auto GetHighestSeqNumber =
406 [](const webrtc::rtcp::ReportBlock& block) -> float {
407 return block.extended_high_seq_num();
408 };
409 plots.RegisterPlot("incoming_rtcp_highest_seq_number", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200410 analyzer.CreateSenderAndReceiverReportPlot(
411 webrtc::kIncomingPacket, GetHighestSeqNumber,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200412 "Highest sequence number (incoming RTCP)", "Sequence number", plot);
413 });
414 plots.RegisterPlot("outgoing_rtcp_highest_seq_number", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200415 analyzer.CreateSenderAndReceiverReportPlot(
416 webrtc::kOutgoingPacket, GetHighestSeqNumber,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200417 "Highest sequence number (outgoing RTCP)", "Sequence number", plot);
418 });
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200419
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200420 auto DelaySinceLastSr = [](const webrtc::rtcp::ReportBlock& block) -> float {
421 return static_cast<double>(block.delay_since_last_sr()) / 65536;
422 };
423 plots.RegisterPlot("incoming_rtcp_delay_since_last_sr", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200424 analyzer.CreateSenderAndReceiverReportPlot(
425 webrtc::kIncomingPacket, DelaySinceLastSr,
426 "Delay since last received sender report (incoming RTCP)", "Time (s)",
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200427 plot);
428 });
429 plots.RegisterPlot("outgoing_rtcp_delay_since_last_sr", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200430 analyzer.CreateSenderAndReceiverReportPlot(
431 webrtc::kOutgoingPacket, DelaySinceLastSr,
432 "Delay since last received sender report (outgoing RTCP)", "Time (s)",
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200433 plot);
434 });
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200435
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200436 plots.RegisterPlot("pacer_delay",
437 [&](Plot* plot) { analyzer.CreatePacerDelayGraph(plot); });
438 plots.RegisterPlot("audio_encoder_bitrate", [&](Plot* plot) {
439 analyzer.CreateAudioEncoderTargetBitrateGraph(plot);
440 });
441 plots.RegisterPlot("audio_encoder_frame_length", [&](Plot* plot) {
442 analyzer.CreateAudioEncoderFrameLengthGraph(plot);
443 });
444 plots.RegisterPlot("audio_encoder_packet_loss", [&](Plot* plot) {
445 analyzer.CreateAudioEncoderPacketLossGraph(plot);
446 });
447 plots.RegisterPlot("audio_encoder_fec", [&](Plot* plot) {
448 analyzer.CreateAudioEncoderEnableFecGraph(plot);
449 });
450 plots.RegisterPlot("audio_encoder_dtx", [&](Plot* plot) {
451 analyzer.CreateAudioEncoderEnableDtxGraph(plot);
452 });
453 plots.RegisterPlot("audio_encoder_num_channels", [&](Plot* plot) {
454 analyzer.CreateAudioEncoderNumChannelsGraph(plot);
455 });
456
457 plots.RegisterPlot("ice_candidate_pair_config", [&](Plot* plot) {
458 analyzer.CreateIceCandidatePairConfigGraph(plot);
459 });
460 plots.RegisterPlot("ice_connectivity_check", [&](Plot* plot) {
461 analyzer.CreateIceConnectivityCheckGraph(plot);
462 });
463 plots.RegisterPlot("dtls_transport_state", [&](Plot* plot) {
464 analyzer.CreateDtlsTransportStateGraph(plot);
465 });
466 plots.RegisterPlot("dtls_writable_state", [&](Plot* plot) {
467 analyzer.CreateDtlsWritableStateGraph(plot);
468 });
469
470 std::string wav_path;
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200471 if (!absl::GetFlag(FLAGS_wav_filename).empty()) {
472 wav_path = absl::GetFlag(FLAGS_wav_filename);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200473 } else {
474 wav_path = webrtc::test::ResourcePath(
475 "audio_processing/conversational_speech/EN_script2_F_sp2_B1", "wav");
Bjorn Terelius0295a962017-10-25 17:42:41 +0200476 }
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200477 absl::optional<webrtc::EventLogAnalyzer::NetEqStatsGetterMap> neteq_stats;
478
479 plots.RegisterPlot("simulated_neteq_expand_rate", [&](Plot* plot) {
480 if (!neteq_stats) {
481 neteq_stats = analyzer.SimulateNetEq(wav_path, 48000);
Minyue Li45fc6df2018-06-21 11:47:14 +0200482 }
Minyue Lic9ac93f2018-06-26 13:01:32 +0200483 analyzer.CreateNetEqNetworkStatsGraph(
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200484 *neteq_stats,
Minyue Li27e2b7d2018-05-07 15:20:24 +0200485 [](const webrtc::NetEqNetworkStatistics& stats) {
486 return stats.expand_rate / 16384.f;
487 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200488 "Expand rate", plot);
489 });
490
491 plots.RegisterPlot("simulated_neteq_speech_expand_rate", [&](Plot* plot) {
492 if (!neteq_stats) {
493 neteq_stats = analyzer.SimulateNetEq(wav_path, 48000);
494 }
Minyue Lic9ac93f2018-06-26 13:01:32 +0200495 analyzer.CreateNetEqNetworkStatsGraph(
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200496 *neteq_stats,
Minyue Li27e2b7d2018-05-07 15:20:24 +0200497 [](const webrtc::NetEqNetworkStatistics& stats) {
498 return stats.speech_expand_rate / 16384.f;
499 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200500 "Speech expand rate", plot);
501 });
502
503 plots.RegisterPlot("simulated_neteq_accelerate_rate", [&](Plot* plot) {
504 if (!neteq_stats) {
505 neteq_stats = analyzer.SimulateNetEq(wav_path, 48000);
506 }
Minyue Lic9ac93f2018-06-26 13:01:32 +0200507 analyzer.CreateNetEqNetworkStatsGraph(
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200508 *neteq_stats,
Minyue Li27e2b7d2018-05-07 15:20:24 +0200509 [](const webrtc::NetEqNetworkStatistics& stats) {
510 return stats.accelerate_rate / 16384.f;
511 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200512 "Accelerate rate", plot);
513 });
514
515 plots.RegisterPlot("simulated_neteq_preemptive_rate", [&](Plot* plot) {
516 if (!neteq_stats) {
517 neteq_stats = analyzer.SimulateNetEq(wav_path, 48000);
518 }
Minyue Lic9ac93f2018-06-26 13:01:32 +0200519 analyzer.CreateNetEqNetworkStatsGraph(
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200520 *neteq_stats,
Minyue Li27e2b7d2018-05-07 15:20:24 +0200521 [](const webrtc::NetEqNetworkStatistics& stats) {
Jakob Ivarsson21f6fd72019-04-04 10:15:02 +0200522 return stats.preemptive_rate / 16384.f;
523 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200524 "Preemptive rate", plot);
525 });
526
527 plots.RegisterPlot("simulated_neteq_packet_loss_rate", [&](Plot* plot) {
528 if (!neteq_stats) {
529 neteq_stats = analyzer.SimulateNetEq(wav_path, 48000);
530 }
Jakob Ivarsson21f6fd72019-04-04 10:15:02 +0200531 analyzer.CreateNetEqNetworkStatsGraph(
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200532 *neteq_stats,
Jakob Ivarsson21f6fd72019-04-04 10:15:02 +0200533 [](const webrtc::NetEqNetworkStatistics& stats) {
Minyue Li27e2b7d2018-05-07 15:20:24 +0200534 return stats.packet_loss_rate / 16384.f;
535 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200536 "Packet loss rate", plot);
537 });
538
539 plots.RegisterPlot("simulated_neteq_concealment_events", [&](Plot* plot) {
540 if (!neteq_stats) {
541 neteq_stats = analyzer.SimulateNetEq(wav_path, 48000);
542 }
Minyue Lic9ac93f2018-06-26 13:01:32 +0200543 analyzer.CreateNetEqLifetimeStatsGraph(
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200544 *neteq_stats,
Minyue Lic9ac93f2018-06-26 13:01:32 +0200545 [](const webrtc::NetEqLifetimeStatistics& stats) {
546 return static_cast<float>(stats.concealment_events);
547 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200548 "Concealment events", plot);
549 });
550
551 plots.RegisterPlot("simulated_neteq_preferred_buffer_size", [&](Plot* plot) {
552 if (!neteq_stats) {
553 neteq_stats = analyzer.SimulateNetEq(wav_path, 48000);
554 }
Jakob Ivarsson21f6fd72019-04-04 10:15:02 +0200555 analyzer.CreateNetEqNetworkStatsGraph(
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200556 *neteq_stats,
Jakob Ivarsson21f6fd72019-04-04 10:15:02 +0200557 [](const webrtc::NetEqNetworkStatistics& stats) {
558 return stats.preferred_buffer_size_ms;
559 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200560 "Preferred buffer size (ms)", plot);
561 });
562
563 if (absl::c_find(plot_flags, "all") != plot_flags.end()) {
564 plots.EnableAllPlots();
565 // Treated separately since it isn't registered like the other plots.
566 plot_flags.push_back("simulated_neteq_jitter_buffer_delay");
567 } else {
568 bool success = plots.EnablePlotsByFlags(plot_flags, flag_aliases);
569 if (!success) {
570 return 1;
571 }
henrik.lundin3c938fc2017-06-14 06:09:58 -0700572 }
573
Mirko Bonadeif2d97b82019-07-24 15:29:47 +0200574 if (absl::GetFlag(FLAGS_list_plots)) {
575 std::cerr << "List of registered plots (for use with the --plot flag):"
576 << std::endl;
577 for (const auto& plot : plots) {
578 // TODO(terelius): Also print a help text.
579 std::cerr << " " << plot.label << std::endl;
580 }
581 // The following flag doesn't fit the model used for the other plots.
582 std::cerr << "simulated_neteq_jitter_buffer_delay" << std::endl;
583 std::cerr << "List of plot aliases (for use with the --plot flag):"
584 << std::endl;
585 std::cerr << " all = every registered plot" << std::endl;
586 for (const auto& alias : flag_aliases) {
587 std::cerr << " " << alias.first << " = ";
588 for (const auto& replacement : alias.second) {
589 std::cerr << replacement << ",";
590 }
591 std::cerr << std::endl;
592 }
593 return 0;
594 }
595 if (args.size() != 2) {
596 // Print usage information.
597 std::cerr << absl::ProgramUsageMessage();
598 return 1;
599 }
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800600
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200601 for (const auto& plot : plots) {
602 if (plot.enabled) {
603 Plot* output = collection->AppendNewPlot();
604 plot.plot_func(output);
605 output->SetId(plot.label);
606 }
Zach Stein10a58012018-12-07 12:26:28 -0800607 }
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200608
609 // The model we use for registering plots assumes that the each plot label
610 // can be mapped to a lambda that will produce exactly one plot. The
611 // simulated_neteq_jitter_buffer_delay plot doesn't fit this model since it
612 // creates multiple plots, and would need some state kept between the lambda
613 // calls.
614 if (absl::c_find(plot_flags, "simulated_neteq_jitter_buffer_delay") !=
615 plot_flags.end()) {
616 if (!neteq_stats) {
617 neteq_stats = analyzer.SimulateNetEq(wav_path, 48000);
618 }
619 for (webrtc::EventLogAnalyzer::NetEqStatsGetterMap::const_iterator it =
620 neteq_stats->cbegin();
621 it != neteq_stats->cend(); ++it) {
622 analyzer.CreateAudioJitterBufferGraph(it->first, it->second.get(),
623 collection->AppendNewPlot());
624 }
Zach Stein10a58012018-12-07 12:26:28 -0800625 }
626
tereliusdc35dcd2016-08-01 12:03:27 -0700627 collection->Draw();
terelius54ce6802016-07-13 06:44:41 -0700628
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200629 if (absl::GetFlag(FLAGS_print_triage_alerts)) {
Bjorn Terelius48b82792020-05-19 10:57:24 +0200630 webrtc::TriageHelper triage_alerts(config);
631 triage_alerts.AnalyzeLog(parsed_log);
632 triage_alerts.Print(stderr);
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100633 }
634
terelius54ce6802016-07-13 06:44:41 -0700635 return 0;
636}