blob: 2e6a97b8c0dcade9e3d8e69d7908ee66413c3961 [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"
Yves Gerey3e707812018-11-28 16:47:49 +010024#include "logging/rtc_event_log/rtc_event_log.h"
Sebastian Janssonb290a6d2019-01-03 14:46:23 +010025#include "logging/rtc_event_log/rtc_event_log_parser.h"
Yves Gerey3e707812018-11-28 16:47:49 +010026#include "modules/audio_coding/neteq/include/neteq.h"
27#include "modules/rtp_rtcp/source/rtcp_packet/report_block.h"
28#include "rtc_base/checks.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020029#include "rtc_tools/event_log_visualizer/analyzer.h"
30#include "rtc_tools/event_log_visualizer/plot_base.h"
Bjorn Tereliusef73f592018-09-10 20:11:49 +020031#include "rtc_tools/event_log_visualizer/plot_protobuf.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020032#include "rtc_tools/event_log_visualizer/plot_python.h"
Mirko Bonadei17f48782018-09-28 08:51:10 +020033#include "system_wrappers/include/field_trial.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020034#include "test/field_trial.h"
Steve Anton10542f22019-01-11 09:11:00 -080035#include "test/testsupport/file_utils.h"
terelius54ce6802016-07-13 06:44:41 -070036
Mirko Bonadei4b091f42019-07-16 11:55:08 +020037ABSL_FLAG(std::string,
38 plot,
39 "default",
40 "A comma separated list of plot names. See below for valid options.");
Bjorn Terelius1edfff92017-10-11 13:15:19 +020041
Mirko Bonadei4b091f42019-07-16 11:55:08 +020042ABSL_FLAG(
43 std::string,
stefan985d2802016-11-15 06:54:09 -080044 force_fieldtrials,
45 "",
46 "Field trials control experimental feature code which can be forced. "
47 "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enabled/"
48 " will assign the group Enabled to field trial WebRTC-FooFeature. Multiple "
49 "trials are separated by \"/\"");
Mirko Bonadei4b091f42019-07-16 11:55:08 +020050ABSL_FLAG(std::string,
51 wav_filename,
52 "",
53 "Path to wav file used for simulation of jitter buffer");
terelius54ce6802016-07-13 06:44:41 -070054
Mirko Bonadei4b091f42019-07-16 11:55:08 +020055ABSL_FLAG(bool,
56 show_detector_state,
57 false,
58 "Show the state of the delay based BWE detector on the total "
59 "bitrate graph");
terelius2ee076d2017-08-15 02:04:02 -070060
Mirko Bonadei4b091f42019-07-16 11:55:08 +020061ABSL_FLAG(bool,
62 show_alr_state,
63 false,
64 "Show the state ALR state on the total bitrate graph");
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +010065
Mirko Bonadei4b091f42019-07-16 11:55:08 +020066ABSL_FLAG(bool,
67 parse_unconfigured_header_extensions,
68 true,
69 "Attempt to parse unconfigured header extensions using the default "
70 "WebRTC mapping. This can give very misleading results if the "
71 "application negotiates a different mapping.");
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020072
Mirko Bonadei4b091f42019-07-16 11:55:08 +020073ABSL_FLAG(bool,
74 print_triage_alerts,
75 false,
76 "Print triage alerts, i.e. a list of potential problems.");
Bjorn Terelius2eb31882017-11-30 15:15:25 +010077
Mirko Bonadei4b091f42019-07-16 11:55:08 +020078ABSL_FLAG(bool,
79 normalize_time,
80 true,
81 "Normalize the log timestamps so that the call starts at time 0.");
Stefan Holmer1d4a2272018-05-24 13:48:09 +020082
Mirko Bonadei4b091f42019-07-16 11:55:08 +020083ABSL_FLAG(bool,
84 shared_xaxis,
85 false,
86 "Share x-axis between all plots so that zooming in one plot "
87 "updates all the others too. A downside is that certain "
88 "operations like panning become much slower.");
Bjorn Tereliusff8cce32019-04-11 18:34:01 +020089
Mirko Bonadei4b091f42019-07-16 11:55:08 +020090ABSL_FLAG(bool,
91 protobuf_output,
92 false,
93 "Output charts as protobuf instead of python code.");
Bjorn Tereliusef73f592018-09-10 20:11:49 +020094
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +020095using webrtc::Plot;
96
97namespace {
98std::vector<std::string> StrSplit(const std::string& s,
99 const std::string& delimiter) {
100 std::vector<std::string> v;
101 size_t pos = 0;
102 while (pos < s.length()) {
103 const std::string token = s.substr(pos, s.find(delimiter, pos) - pos);
104 pos += token.length() + delimiter.length();
105 v.push_back(token);
106 }
107 return v;
108}
109
110struct PlotDeclaration {
111 PlotDeclaration(const std::string& label, std::function<void(Plot*)> f)
112 : label(label), enabled(false), plot_func(f) {}
113 const std::string label;
114 bool enabled;
115 // TODO(terelius): Add a help text/explanation.
116 const std::function<void(Plot*)> plot_func;
117};
118
119class PlotMap {
120 public:
121 void RegisterPlot(const std::string& label, std::function<void(Plot*)> f) {
122 for (const auto& plot : plots_) {
123 RTC_DCHECK(plot.label != label)
124 << "Can't use the same label for multiple plots";
125 }
126 plots_.push_back({label, f});
127 }
128
129 bool EnablePlotsByFlags(
130 const std::vector<std::string>& flags,
131 const std::map<std::string, std::vector<std::string>>& flag_aliases) {
132 bool status = true;
133 for (const std::string& flag : flags) {
134 auto alias_it = flag_aliases.find(flag);
135 if (alias_it != flag_aliases.end()) {
136 const auto& replacements = alias_it->second;
137 for (const auto& replacement : replacements) {
138 status &= EnablePlotByFlag(replacement);
139 }
140 } else {
141 status &= EnablePlotByFlag(flag);
142 }
143 }
144 return status;
145 }
146
147 void EnableAllPlots() {
148 for (auto& plot : plots_) {
149 plot.enabled = true;
150 }
151 }
152
153 std::vector<PlotDeclaration>::iterator begin() { return plots_.begin(); }
154 std::vector<PlotDeclaration>::iterator end() { return plots_.end(); }
155
156 private:
157 bool EnablePlotByFlag(const std::string& flag) {
158 for (auto& plot : plots_) {
159 if (plot.label == flag) {
160 plot.enabled = true;
161 return true;
162 }
163 }
164 if (flag == "simulated_neteq_jitter_buffer_delay") {
165 // This flag is handled separately.
166 return true;
167 }
168 std::cerr << "Unrecognized plot name \'" << flag << "\'. Aborting."
169 << std::endl;
170 return false;
171 }
172
173 std::vector<PlotDeclaration> plots_;
174};
175} // namespace
terelius2ee076d2017-08-15 02:04:02 -0700176
terelius54ce6802016-07-13 06:44:41 -0700177int main(int argc, char* argv[]) {
178 std::string program_name = argv[0];
179 std::string usage =
180 "A tool for visualizing WebRTC event logs.\n"
181 "Example usage:\n" +
182 program_name + " <logfile> | python\n" + "Run " + program_name +
183 " --help for a list of command line options\n";
terelius2ee076d2017-08-15 02:04:02 -0700184
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200185 std::vector<char*> args = absl::ParseCommandLine(argc, argv);
186
187 // TODO(bugs.webrtc.org/10616): Add program usage message when Abseil
188 // flags supports it.
189 if (args.size() != 2) {
190 std::cerr << "TODO(bugs.webrtc.org/10616): Print flag list again when "
191 "Abseil supports it.\n";
192 }
terelius2ee076d2017-08-15 02:04:02 -0700193
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200194 // Flag replacements
195 std::map<std::string, std::vector<std::string>> flag_aliases = {
196 {"default",
197 {"incoming_delay", "incoming_loss_rate", "incoming_bitrate",
Bjorn Terelius873a7a92019-06-13 16:01:17 +0200198 "outgoing_bitrate", "incoming_stream_bitrate",
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200199 "outgoing_stream_bitrate", "network_delay_feedback",
200 "fraction_loss_feedback"}},
201 {"sendside_bwe",
202 {"outgoing_packet_sizes", "outgoing_bitrate", "outgoing_stream_bitrate",
203 "simulated_sendside_bwe", "network_delay_feedback",
204 "fraction_loss_feedback"}},
205 {"receiveside_bwe",
206 {"incoming_packet_sizes", "incoming_delay", "incoming_loss_rate",
Bjorn Terelius873a7a92019-06-13 16:01:17 +0200207 "incoming_bitrate", "incoming_stream_bitrate",
208 "simulated_receiveside_bwe"}},
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200209 {"rtcp_details",
210 {"incoming_rtcp_fraction_lost", "outgoing_rtcp_fraction_lost",
Bjorn Terelius873a7a92019-06-13 16:01:17 +0200211 "incoming_rtcp_cumulative_lost", "outgoing_rtcp_cumulative_lost",
212 "incoming_rtcp_highest_seq_number", "outgoing_rtcp_highest_seq_number",
213 "incoming_rtcp_delay_since_last_sr",
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200214 "outgoing_rtcp_delay_since_last_sr"}},
215 {"simulated_neteq_stats",
216 {"simulated_neteq_jitter_buffer_delay",
Bjorn Terelius873a7a92019-06-13 16:01:17 +0200217 "simulated_neteq_preferred_buffer_size",
218 "simulated_neteq_concealment_events",
219 "simulated_neteq_packet_loss_rate", "simulated_neteq_preemptive_rate",
220 "simulated_neteq_accelerate_rate", "simulated_neteq_speech_expand_rate",
221 "simulated_neteq_expand_rate"}}};
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200222
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200223 std::vector<std::string> plot_flags =
224 StrSplit(absl::GetFlag(FLAGS_plot), ",");
kjellander4fa5be42017-05-16 00:01:23 -0700225
Bjorn Tereliusedab3012018-01-31 17:23:40 +0100226 // InitFieldTrialsFromString stores the char*, so the char array must outlive
227 // the application.
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200228 const std::string field_trials = absl::GetFlag(FLAGS_force_fieldtrials);
229 webrtc::field_trial::InitFieldTrialsFromString(field_trials.c_str());
stefan985d2802016-11-15 06:54:09 -0800230
Sebastian Janssonb290a6d2019-01-03 14:46:23 +0100231 webrtc::ParsedRtcEventLog::UnconfiguredHeaderExtensions header_extensions =
232 webrtc::ParsedRtcEventLog::UnconfiguredHeaderExtensions::kDontParse;
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200233 if (absl::GetFlag(FLAGS_parse_unconfigured_header_extensions)) {
Sebastian Janssonb290a6d2019-01-03 14:46:23 +0100234 header_extensions = webrtc::ParsedRtcEventLog::
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200235 UnconfiguredHeaderExtensions::kAttemptWebrtcDefaultConfig;
236 }
Sebastian Janssonb290a6d2019-01-03 14:46:23 +0100237 webrtc::ParsedRtcEventLog parsed_log(header_extensions);
terelius54ce6802016-07-13 06:44:41 -0700238
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200239 if (args.size() == 2) {
240 std::string filename = args[1];
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200241 if (!parsed_log.ParseFile(filename)) {
242 std::cerr << "Could not parse the entire log file." << std::endl;
243 std::cerr << "Only the parsable events will be analyzed." << std::endl;
244 }
terelius54ce6802016-07-13 06:44:41 -0700245 }
246
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200247 webrtc::EventLogAnalyzer analyzer(parsed_log,
248 absl::GetFlag(FLAGS_normalize_time));
Bjorn Tereliusef73f592018-09-10 20:11:49 +0200249 std::unique_ptr<webrtc::PlotCollection> collection;
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200250 if (absl::GetFlag(FLAGS_protobuf_output)) {
Bjorn Tereliusef73f592018-09-10 20:11:49 +0200251 collection.reset(new webrtc::ProtobufPlotCollection());
252 } else {
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200253 collection.reset(
254 new webrtc::PythonPlotCollection(absl::GetFlag(FLAGS_shared_xaxis)));
Bjorn Tereliusef73f592018-09-10 20:11:49 +0200255 }
terelius54ce6802016-07-13 06:44:41 -0700256
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200257 PlotMap plots;
258 plots.RegisterPlot("incoming_packet_sizes", [&](Plot* plot) {
259 analyzer.CreatePacketGraph(webrtc::kIncomingPacket, plot);
260 });
261
262 plots.RegisterPlot("outgoing_packet_sizes", [&](Plot* plot) {
263 analyzer.CreatePacketGraph(webrtc::kOutgoingPacket, plot);
264 });
265 plots.RegisterPlot("incoming_rtcp_types", [&](Plot* plot) {
266 analyzer.CreateRtcpTypeGraph(webrtc::kIncomingPacket, plot);
267 });
268 plots.RegisterPlot("outgoing_rtcp_types", [&](Plot* plot) {
269 analyzer.CreateRtcpTypeGraph(webrtc::kOutgoingPacket, plot);
270 });
271 plots.RegisterPlot("incoming_packet_count", [&](Plot* plot) {
272 analyzer.CreateAccumulatedPacketsGraph(webrtc::kIncomingPacket, plot);
273 });
274 plots.RegisterPlot("outgoing_packet_count", [&](Plot* plot) {
275 analyzer.CreateAccumulatedPacketsGraph(webrtc::kOutgoingPacket, plot);
276 });
277 plots.RegisterPlot("audio_playout",
278 [&](Plot* plot) { analyzer.CreatePlayoutGraph(plot); });
279 plots.RegisterPlot("incoming_audio_level", [&](Plot* plot) {
280 analyzer.CreateAudioLevelGraph(webrtc::kIncomingPacket, plot);
281 });
282 plots.RegisterPlot("outgoing_audio_level", [&](Plot* plot) {
283 analyzer.CreateAudioLevelGraph(webrtc::kOutgoingPacket, plot);
284 });
285 plots.RegisterPlot("incoming_sequence_number_delta", [&](Plot* plot) {
286 analyzer.CreateSequenceNumberGraph(plot);
287 });
288 plots.RegisterPlot("incoming_delay", [&](Plot* plot) {
289 analyzer.CreateIncomingDelayGraph(plot);
290 });
291 plots.RegisterPlot("incoming_loss_rate", [&](Plot* plot) {
292 analyzer.CreateIncomingPacketLossGraph(plot);
293 });
294 plots.RegisterPlot("incoming_bitrate", [&](Plot* plot) {
295 analyzer.CreateTotalIncomingBitrateGraph(plot);
296 });
297 plots.RegisterPlot("outgoing_bitrate", [&](Plot* plot) {
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200298 analyzer.CreateTotalOutgoingBitrateGraph(
299 plot, absl::GetFlag(FLAGS_show_detector_state),
300 absl::GetFlag(FLAGS_show_alr_state));
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200301 });
302 plots.RegisterPlot("incoming_stream_bitrate", [&](Plot* plot) {
303 analyzer.CreateStreamBitrateGraph(webrtc::kIncomingPacket, plot);
304 });
305 plots.RegisterPlot("outgoing_stream_bitrate", [&](Plot* plot) {
306 analyzer.CreateStreamBitrateGraph(webrtc::kOutgoingPacket, plot);
307 });
308 plots.RegisterPlot("incoming_layer_bitrate_allocation", [&](Plot* plot) {
309 analyzer.CreateBitrateAllocationGraph(webrtc::kIncomingPacket, plot);
310 });
311 plots.RegisterPlot("outgoing_layer_bitrate_allocation", [&](Plot* plot) {
312 analyzer.CreateBitrateAllocationGraph(webrtc::kOutgoingPacket, plot);
313 });
314 plots.RegisterPlot("simulated_receiveside_bwe", [&](Plot* plot) {
315 analyzer.CreateReceiveSideBweSimulationGraph(plot);
316 });
317 plots.RegisterPlot("simulated_sendside_bwe", [&](Plot* plot) {
318 analyzer.CreateSendSideBweSimulationGraph(plot);
319 });
320 plots.RegisterPlot("simulated_goog_cc", [&](Plot* plot) {
321 analyzer.CreateGoogCcSimulationGraph(plot);
322 });
323 plots.RegisterPlot("network_delay_feedback", [&](Plot* plot) {
324 analyzer.CreateNetworkDelayFeedbackGraph(plot);
325 });
326 plots.RegisterPlot("fraction_loss_feedback", [&](Plot* plot) {
327 analyzer.CreateFractionLossGraph(plot);
328 });
329 plots.RegisterPlot("incoming_timestamps", [&](Plot* plot) {
330 analyzer.CreateTimestampGraph(webrtc::kIncomingPacket, plot);
331 });
332 plots.RegisterPlot("outgoing_timestamps", [&](Plot* plot) {
333 analyzer.CreateTimestampGraph(webrtc::kOutgoingPacket, plot);
334 });
335
336 auto GetFractionLost = [](const webrtc::rtcp::ReportBlock& block) -> float {
337 return static_cast<double>(block.fraction_lost()) / 256 * 100;
338 };
339 plots.RegisterPlot("incoming_rtcp_fraction_lost", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200340 analyzer.CreateSenderAndReceiverReportPlot(
341 webrtc::kIncomingPacket, GetFractionLost,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200342 "Fraction lost (incoming RTCP)", "Loss rate (percent)", plot);
343 });
344 plots.RegisterPlot("outgoing_rtcp_fraction_lost", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200345 analyzer.CreateSenderAndReceiverReportPlot(
346 webrtc::kOutgoingPacket, GetFractionLost,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200347 "Fraction lost (outgoing RTCP)", "Loss rate (percent)", plot);
348 });
349 auto GetCumulativeLost = [](const webrtc::rtcp::ReportBlock& block) -> float {
350 return block.cumulative_lost_signed();
351 };
352 plots.RegisterPlot("incoming_rtcp_cumulative_lost", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200353 analyzer.CreateSenderAndReceiverReportPlot(
354 webrtc::kIncomingPacket, GetCumulativeLost,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200355 "Cumulative lost packets (incoming RTCP)", "Packets", plot);
356 });
357 plots.RegisterPlot("outgoing_rtcp_cumulative_lost", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200358 analyzer.CreateSenderAndReceiverReportPlot(
359 webrtc::kOutgoingPacket, GetCumulativeLost,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200360 "Cumulative lost packets (outgoing RTCP)", "Packets", plot);
361 });
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200362
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200363 auto GetHighestSeqNumber =
364 [](const webrtc::rtcp::ReportBlock& block) -> float {
365 return block.extended_high_seq_num();
366 };
367 plots.RegisterPlot("incoming_rtcp_highest_seq_number", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200368 analyzer.CreateSenderAndReceiverReportPlot(
369 webrtc::kIncomingPacket, GetHighestSeqNumber,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200370 "Highest sequence number (incoming RTCP)", "Sequence number", plot);
371 });
372 plots.RegisterPlot("outgoing_rtcp_highest_seq_number", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200373 analyzer.CreateSenderAndReceiverReportPlot(
374 webrtc::kOutgoingPacket, GetHighestSeqNumber,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200375 "Highest sequence number (outgoing RTCP)", "Sequence number", plot);
376 });
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200377
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200378 auto DelaySinceLastSr = [](const webrtc::rtcp::ReportBlock& block) -> float {
379 return static_cast<double>(block.delay_since_last_sr()) / 65536;
380 };
381 plots.RegisterPlot("incoming_rtcp_delay_since_last_sr", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200382 analyzer.CreateSenderAndReceiverReportPlot(
383 webrtc::kIncomingPacket, DelaySinceLastSr,
384 "Delay since last received sender report (incoming RTCP)", "Time (s)",
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200385 plot);
386 });
387 plots.RegisterPlot("outgoing_rtcp_delay_since_last_sr", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200388 analyzer.CreateSenderAndReceiverReportPlot(
389 webrtc::kOutgoingPacket, DelaySinceLastSr,
390 "Delay since last received sender report (outgoing RTCP)", "Time (s)",
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200391 plot);
392 });
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200393
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200394 plots.RegisterPlot("pacer_delay",
395 [&](Plot* plot) { analyzer.CreatePacerDelayGraph(plot); });
396 plots.RegisterPlot("audio_encoder_bitrate", [&](Plot* plot) {
397 analyzer.CreateAudioEncoderTargetBitrateGraph(plot);
398 });
399 plots.RegisterPlot("audio_encoder_frame_length", [&](Plot* plot) {
400 analyzer.CreateAudioEncoderFrameLengthGraph(plot);
401 });
402 plots.RegisterPlot("audio_encoder_packet_loss", [&](Plot* plot) {
403 analyzer.CreateAudioEncoderPacketLossGraph(plot);
404 });
405 plots.RegisterPlot("audio_encoder_fec", [&](Plot* plot) {
406 analyzer.CreateAudioEncoderEnableFecGraph(plot);
407 });
408 plots.RegisterPlot("audio_encoder_dtx", [&](Plot* plot) {
409 analyzer.CreateAudioEncoderEnableDtxGraph(plot);
410 });
411 plots.RegisterPlot("audio_encoder_num_channels", [&](Plot* plot) {
412 analyzer.CreateAudioEncoderNumChannelsGraph(plot);
413 });
414
415 plots.RegisterPlot("ice_candidate_pair_config", [&](Plot* plot) {
416 analyzer.CreateIceCandidatePairConfigGraph(plot);
417 });
418 plots.RegisterPlot("ice_connectivity_check", [&](Plot* plot) {
419 analyzer.CreateIceConnectivityCheckGraph(plot);
420 });
421 plots.RegisterPlot("dtls_transport_state", [&](Plot* plot) {
422 analyzer.CreateDtlsTransportStateGraph(plot);
423 });
424 plots.RegisterPlot("dtls_writable_state", [&](Plot* plot) {
425 analyzer.CreateDtlsWritableStateGraph(plot);
426 });
427
428 std::string wav_path;
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200429 if (!absl::GetFlag(FLAGS_wav_filename).empty()) {
430 wav_path = absl::GetFlag(FLAGS_wav_filename);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200431 } else {
432 wav_path = webrtc::test::ResourcePath(
433 "audio_processing/conversational_speech/EN_script2_F_sp2_B1", "wav");
Bjorn Terelius0295a962017-10-25 17:42:41 +0200434 }
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200435 absl::optional<webrtc::EventLogAnalyzer::NetEqStatsGetterMap> neteq_stats;
436
437 plots.RegisterPlot("simulated_neteq_expand_rate", [&](Plot* plot) {
438 if (!neteq_stats) {
439 neteq_stats = analyzer.SimulateNetEq(wav_path, 48000);
Minyue Li45fc6df2018-06-21 11:47:14 +0200440 }
Minyue Lic9ac93f2018-06-26 13:01:32 +0200441 analyzer.CreateNetEqNetworkStatsGraph(
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200442 *neteq_stats,
Minyue Li27e2b7d2018-05-07 15:20:24 +0200443 [](const webrtc::NetEqNetworkStatistics& stats) {
444 return stats.expand_rate / 16384.f;
445 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200446 "Expand rate", plot);
447 });
448
449 plots.RegisterPlot("simulated_neteq_speech_expand_rate", [&](Plot* plot) {
450 if (!neteq_stats) {
451 neteq_stats = analyzer.SimulateNetEq(wav_path, 48000);
452 }
Minyue Lic9ac93f2018-06-26 13:01:32 +0200453 analyzer.CreateNetEqNetworkStatsGraph(
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200454 *neteq_stats,
Minyue Li27e2b7d2018-05-07 15:20:24 +0200455 [](const webrtc::NetEqNetworkStatistics& stats) {
456 return stats.speech_expand_rate / 16384.f;
457 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200458 "Speech expand rate", plot);
459 });
460
461 plots.RegisterPlot("simulated_neteq_accelerate_rate", [&](Plot* plot) {
462 if (!neteq_stats) {
463 neteq_stats = analyzer.SimulateNetEq(wav_path, 48000);
464 }
Minyue Lic9ac93f2018-06-26 13:01:32 +0200465 analyzer.CreateNetEqNetworkStatsGraph(
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200466 *neteq_stats,
Minyue Li27e2b7d2018-05-07 15:20:24 +0200467 [](const webrtc::NetEqNetworkStatistics& stats) {
468 return stats.accelerate_rate / 16384.f;
469 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200470 "Accelerate rate", plot);
471 });
472
473 plots.RegisterPlot("simulated_neteq_preemptive_rate", [&](Plot* plot) {
474 if (!neteq_stats) {
475 neteq_stats = analyzer.SimulateNetEq(wav_path, 48000);
476 }
Minyue Lic9ac93f2018-06-26 13:01:32 +0200477 analyzer.CreateNetEqNetworkStatsGraph(
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200478 *neteq_stats,
Minyue Li27e2b7d2018-05-07 15:20:24 +0200479 [](const webrtc::NetEqNetworkStatistics& stats) {
Jakob Ivarsson21f6fd72019-04-04 10:15:02 +0200480 return stats.preemptive_rate / 16384.f;
481 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200482 "Preemptive rate", plot);
483 });
484
485 plots.RegisterPlot("simulated_neteq_packet_loss_rate", [&](Plot* plot) {
486 if (!neteq_stats) {
487 neteq_stats = analyzer.SimulateNetEq(wav_path, 48000);
488 }
Jakob Ivarsson21f6fd72019-04-04 10:15:02 +0200489 analyzer.CreateNetEqNetworkStatsGraph(
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200490 *neteq_stats,
Jakob Ivarsson21f6fd72019-04-04 10:15:02 +0200491 [](const webrtc::NetEqNetworkStatistics& stats) {
Minyue Li27e2b7d2018-05-07 15:20:24 +0200492 return stats.packet_loss_rate / 16384.f;
493 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200494 "Packet loss rate", plot);
495 });
496
497 plots.RegisterPlot("simulated_neteq_concealment_events", [&](Plot* plot) {
498 if (!neteq_stats) {
499 neteq_stats = analyzer.SimulateNetEq(wav_path, 48000);
500 }
Minyue Lic9ac93f2018-06-26 13:01:32 +0200501 analyzer.CreateNetEqLifetimeStatsGraph(
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200502 *neteq_stats,
Minyue Lic9ac93f2018-06-26 13:01:32 +0200503 [](const webrtc::NetEqLifetimeStatistics& stats) {
504 return static_cast<float>(stats.concealment_events);
505 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200506 "Concealment events", plot);
507 });
508
509 plots.RegisterPlot("simulated_neteq_preferred_buffer_size", [&](Plot* plot) {
510 if (!neteq_stats) {
511 neteq_stats = analyzer.SimulateNetEq(wav_path, 48000);
512 }
Jakob Ivarsson21f6fd72019-04-04 10:15:02 +0200513 analyzer.CreateNetEqNetworkStatsGraph(
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200514 *neteq_stats,
Jakob Ivarsson21f6fd72019-04-04 10:15:02 +0200515 [](const webrtc::NetEqNetworkStatistics& stats) {
516 return stats.preferred_buffer_size_ms;
517 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200518 "Preferred buffer size (ms)", plot);
519 });
520
521 if (absl::c_find(plot_flags, "all") != plot_flags.end()) {
522 plots.EnableAllPlots();
523 // Treated separately since it isn't registered like the other plots.
524 plot_flags.push_back("simulated_neteq_jitter_buffer_delay");
525 } else {
526 bool success = plots.EnablePlotsByFlags(plot_flags, flag_aliases);
527 if (!success) {
528 return 1;
529 }
henrik.lundin3c938fc2017-06-14 06:09:58 -0700530 }
531
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200532 // if (argc != 2) {
533 // // Print usage information.
534 // std::cerr << usage;
535 // if (FLAG_help) {
536 // rtc::FlagList::Print(nullptr, false);
537 // std::cerr << "List of registered plots (for use with the --plot flag):"
538 // << std::endl;
539 // for (const auto& plot : plots) {
540 // // TODO(terelius): Also print a help text.
541 // std::cerr << " " << plot.label << std::endl;
542 // }
543 // // The following flag doesn't fit the model used for the other plots.
544 // std::cerr << "simulated_neteq_jitter_buffer_delay" << std::endl;
545 // std::cerr << "List of plot aliases (for use with the --plot flag):"
546 // << std::endl;
547 // std::cerr << " all = every registered plot" << std::endl;
548 // for (const auto& alias : flag_aliases) {
549 // std::cerr << " " << alias.first << " = ";
550 // for (const auto& replacement : alias.second) {
551 // std::cerr << replacement << ",";
552 // }
553 // std::cerr << std::endl;
554 // }
555 // }
556 // return 0;
557 // }
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800558
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200559 for (const auto& plot : plots) {
560 if (plot.enabled) {
561 Plot* output = collection->AppendNewPlot();
562 plot.plot_func(output);
563 output->SetId(plot.label);
564 }
Zach Stein10a58012018-12-07 12:26:28 -0800565 }
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200566
567 // The model we use for registering plots assumes that the each plot label
568 // can be mapped to a lambda that will produce exactly one plot. The
569 // simulated_neteq_jitter_buffer_delay plot doesn't fit this model since it
570 // creates multiple plots, and would need some state kept between the lambda
571 // calls.
572 if (absl::c_find(plot_flags, "simulated_neteq_jitter_buffer_delay") !=
573 plot_flags.end()) {
574 if (!neteq_stats) {
575 neteq_stats = analyzer.SimulateNetEq(wav_path, 48000);
576 }
577 for (webrtc::EventLogAnalyzer::NetEqStatsGetterMap::const_iterator it =
578 neteq_stats->cbegin();
579 it != neteq_stats->cend(); ++it) {
580 analyzer.CreateAudioJitterBufferGraph(it->first, it->second.get(),
581 collection->AppendNewPlot());
582 }
Zach Stein10a58012018-12-07 12:26:28 -0800583 }
584
tereliusdc35dcd2016-08-01 12:03:27 -0700585 collection->Draw();
terelius54ce6802016-07-13 06:44:41 -0700586
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200587 if (absl::GetFlag(FLAGS_print_triage_alerts)) {
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100588 analyzer.CreateTriageNotifications();
589 analyzer.PrintNotifications(stderr);
590 }
591
terelius54ce6802016-07-13 06:44:41 -0700592 return 0;
593}