blob: 4988808cabdb6954500d33c86ae5042fd381729e [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
Mirko Bonadei6183a0f2022-07-05 19:19:43 +000014#include <cstdio>
15#include <fstream>
terelius54ce6802016-07-13 06:44:41 -070016#include <iostream>
Yves Gerey3e707812018-11-28 16:47:49 +010017#include <map>
18#include <memory>
19#include <string>
20#include <utility>
Mirko Bonadei4b091f42019-07-16 11:55:08 +020021#include <vector>
terelius54ce6802016-07-13 06:44:41 -070022
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +020023#include "absl/algorithm/container.h"
Mirko Bonadei4b091f42019-07-16 11:55:08 +020024#include "absl/flags/flag.h"
25#include "absl/flags/parse.h"
Mirko Bonadeif2d97b82019-07-24 15:29:47 +020026#include "absl/flags/usage.h"
27#include "absl/flags/usage_config.h"
28#include "absl/strings/match.h"
Ivo Creusen3ce44a32019-10-31 14:38:11 +010029#include "api/neteq/neteq.h"
Danil Chapovalov83bbe912019-08-07 12:24:53 +020030#include "api/rtc_event_log/rtc_event_log.h"
Sebastian Janssonb290a6d2019-01-03 14:46:23 +010031#include "logging/rtc_event_log/rtc_event_log_parser.h"
Yves Gerey3e707812018-11-28 16:47:49 +010032#include "modules/rtp_rtcp/source/rtcp_packet/report_block.h"
33#include "rtc_base/checks.h"
Björn Tereliusa06048a2019-11-01 14:31:46 +010034#include "rtc_base/logging.h"
Bjorn Terelius48b82792020-05-19 10:57:24 +020035#include "rtc_tools/rtc_event_log_visualizer/alerts.h"
Bjorn Tereliusc186e142020-06-05 10:47:19 +020036#include "rtc_tools/rtc_event_log_visualizer/analyze_audio.h"
Mirko Bonadei575998c2019-07-25 13:57:41 +020037#include "rtc_tools/rtc_event_log_visualizer/analyzer.h"
Mirko Bonadei6183a0f2022-07-05 19:19:43 +000038#include "rtc_tools/rtc_event_log_visualizer/conversational_speech_en.h"
Mirko Bonadei575998c2019-07-25 13:57:41 +020039#include "rtc_tools/rtc_event_log_visualizer/plot_base.h"
Mirko Bonadei17f48782018-09-28 08:51:10 +020040#include "system_wrappers/include/field_trial.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,
Diep Bui38b3cf02022-07-19 14:09:45 +020073 show_link_capacity,
74 true,
75 "Show the lower and upper link capacity on the outgoing bitrate "
76 "graph");
77
78ABSL_FLAG(bool,
Mirko Bonadei4b091f42019-07-16 11:55:08 +020079 parse_unconfigured_header_extensions,
80 true,
81 "Attempt to parse unconfigured header extensions using the default "
82 "WebRTC mapping. This can give very misleading results if the "
83 "application negotiates a different mapping.");
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020084
Mirko Bonadei4b091f42019-07-16 11:55:08 +020085ABSL_FLAG(bool,
86 print_triage_alerts,
Bjorn Tereliusadef7982020-05-19 13:12:01 +020087 true,
Mirko Bonadei4b091f42019-07-16 11:55:08 +020088 "Print triage alerts, i.e. a list of potential problems.");
Bjorn Terelius2eb31882017-11-30 15:15:25 +010089
Mirko Bonadei4b091f42019-07-16 11:55:08 +020090ABSL_FLAG(bool,
91 normalize_time,
92 true,
93 "Normalize the log timestamps so that the call starts at time 0.");
Stefan Holmer1d4a2272018-05-24 13:48:09 +020094
Mirko Bonadei4b091f42019-07-16 11:55:08 +020095ABSL_FLAG(bool,
96 shared_xaxis,
97 false,
98 "Share x-axis between all plots so that zooming in one plot "
99 "updates all the others too. A downside is that certain "
100 "operations like panning become much slower.");
Bjorn Tereliusff8cce32019-04-11 18:34:01 +0200101
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200102ABSL_FLAG(bool,
103 protobuf_output,
104 false,
105 "Output charts as protobuf instead of python code.");
Bjorn Tereliusef73f592018-09-10 20:11:49 +0200106
Mirko Bonadeif2d97b82019-07-24 15:29:47 +0200107ABSL_FLAG(bool,
108 list_plots,
109 false,
110 "List of registered plots (for use with the --plot flag)");
111
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200112using webrtc::Plot;
113
114namespace {
115std::vector<std::string> StrSplit(const std::string& s,
116 const std::string& delimiter) {
117 std::vector<std::string> v;
118 size_t pos = 0;
119 while (pos < s.length()) {
120 const std::string token = s.substr(pos, s.find(delimiter, pos) - pos);
121 pos += token.length() + delimiter.length();
122 v.push_back(token);
123 }
124 return v;
125}
126
127struct PlotDeclaration {
128 PlotDeclaration(const std::string& label, std::function<void(Plot*)> f)
129 : label(label), enabled(false), plot_func(f) {}
130 const std::string label;
131 bool enabled;
132 // TODO(terelius): Add a help text/explanation.
133 const std::function<void(Plot*)> plot_func;
134};
135
136class PlotMap {
137 public:
138 void RegisterPlot(const std::string& label, std::function<void(Plot*)> f) {
139 for (const auto& plot : plots_) {
140 RTC_DCHECK(plot.label != label)
141 << "Can't use the same label for multiple plots";
142 }
143 plots_.push_back({label, f});
144 }
145
146 bool EnablePlotsByFlags(
147 const std::vector<std::string>& flags,
148 const std::map<std::string, std::vector<std::string>>& flag_aliases) {
149 bool status = true;
150 for (const std::string& flag : flags) {
151 auto alias_it = flag_aliases.find(flag);
152 if (alias_it != flag_aliases.end()) {
153 const auto& replacements = alias_it->second;
154 for (const auto& replacement : replacements) {
155 status &= EnablePlotByFlag(replacement);
156 }
157 } else {
158 status &= EnablePlotByFlag(flag);
159 }
160 }
161 return status;
162 }
163
164 void EnableAllPlots() {
165 for (auto& plot : plots_) {
166 plot.enabled = true;
167 }
168 }
169
170 std::vector<PlotDeclaration>::iterator begin() { return plots_.begin(); }
171 std::vector<PlotDeclaration>::iterator end() { return plots_.end(); }
172
173 private:
174 bool EnablePlotByFlag(const std::string& flag) {
175 for (auto& plot : plots_) {
176 if (plot.label == flag) {
177 plot.enabled = true;
178 return true;
179 }
180 }
181 if (flag == "simulated_neteq_jitter_buffer_delay") {
182 // This flag is handled separately.
183 return true;
184 }
185 std::cerr << "Unrecognized plot name \'" << flag << "\'. Aborting."
186 << std::endl;
187 return false;
188 }
189
190 std::vector<PlotDeclaration> plots_;
191};
Mirko Bonadeif2d97b82019-07-24 15:29:47 +0200192
193bool ContainsHelppackageFlags(absl::string_view filename) {
194 return absl::EndsWith(filename, "main.cc");
195}
196
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200197} // namespace
terelius2ee076d2017-08-15 02:04:02 -0700198
terelius54ce6802016-07-13 06:44:41 -0700199int main(int argc, char* argv[]) {
Mirko Bonadeif2d97b82019-07-24 15:29:47 +0200200 absl::SetProgramUsageMessage(
terelius54ce6802016-07-13 06:44:41 -0700201 "A tool for visualizing WebRTC event logs.\n"
Mirko Bonadeif2d97b82019-07-24 15:29:47 +0200202 "Example usage:\n"
203 "./event_log_visualizer <logfile> | python\n");
Bjorn Terelius48b82792020-05-19 10:57:24 +0200204 absl::FlagsUsageConfig flag_config;
205 flag_config.contains_help_flags = &ContainsHelppackageFlags;
206 absl::SetFlagsUsageConfig(flag_config);
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200207 std::vector<char*> args = absl::ParseCommandLine(argc, argv);
208
Björn Tereliusa06048a2019-11-01 14:31:46 +0100209 // Print RTC_LOG warnings and errors even in release builds.
210 if (rtc::LogMessage::GetLogToDebug() > rtc::LS_WARNING) {
211 rtc::LogMessage::LogToDebug(rtc::LS_WARNING);
212 }
213 rtc::LogMessage::SetLogToStderr(true);
214
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200215 // Flag replacements
216 std::map<std::string, std::vector<std::string>> flag_aliases = {
217 {"default",
218 {"incoming_delay", "incoming_loss_rate", "incoming_bitrate",
Bjorn Terelius873a7a92019-06-13 16:01:17 +0200219 "outgoing_bitrate", "incoming_stream_bitrate",
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200220 "outgoing_stream_bitrate", "network_delay_feedback",
221 "fraction_loss_feedback"}},
222 {"sendside_bwe",
223 {"outgoing_packet_sizes", "outgoing_bitrate", "outgoing_stream_bitrate",
224 "simulated_sendside_bwe", "network_delay_feedback",
225 "fraction_loss_feedback"}},
226 {"receiveside_bwe",
227 {"incoming_packet_sizes", "incoming_delay", "incoming_loss_rate",
Bjorn Terelius873a7a92019-06-13 16:01:17 +0200228 "incoming_bitrate", "incoming_stream_bitrate",
229 "simulated_receiveside_bwe"}},
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200230 {"rtcp_details",
231 {"incoming_rtcp_fraction_lost", "outgoing_rtcp_fraction_lost",
Bjorn Terelius873a7a92019-06-13 16:01:17 +0200232 "incoming_rtcp_cumulative_lost", "outgoing_rtcp_cumulative_lost",
233 "incoming_rtcp_highest_seq_number", "outgoing_rtcp_highest_seq_number",
234 "incoming_rtcp_delay_since_last_sr",
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200235 "outgoing_rtcp_delay_since_last_sr"}},
236 {"simulated_neteq_stats",
237 {"simulated_neteq_jitter_buffer_delay",
Bjorn Terelius873a7a92019-06-13 16:01:17 +0200238 "simulated_neteq_preferred_buffer_size",
Jakob Ivarssonddd41912020-11-03 13:28:52 +0100239 "simulated_neteq_concealment_events", "simulated_neteq_preemptive_rate",
Bjorn Terelius873a7a92019-06-13 16:01:17 +0200240 "simulated_neteq_accelerate_rate", "simulated_neteq_speech_expand_rate",
241 "simulated_neteq_expand_rate"}}};
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200242
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200243 std::vector<std::string> plot_flags =
244 StrSplit(absl::GetFlag(FLAGS_plot), ",");
kjellander4fa5be42017-05-16 00:01:23 -0700245
Bjorn Tereliusedab3012018-01-31 17:23:40 +0100246 // InitFieldTrialsFromString stores the char*, so the char array must outlive
247 // the application.
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200248 const std::string field_trials = absl::GetFlag(FLAGS_force_fieldtrials);
249 webrtc::field_trial::InitFieldTrialsFromString(field_trials.c_str());
stefan985d2802016-11-15 06:54:09 -0800250
Sebastian Janssonb290a6d2019-01-03 14:46:23 +0100251 webrtc::ParsedRtcEventLog::UnconfiguredHeaderExtensions header_extensions =
252 webrtc::ParsedRtcEventLog::UnconfiguredHeaderExtensions::kDontParse;
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200253 if (absl::GetFlag(FLAGS_parse_unconfigured_header_extensions)) {
Sebastian Janssonb290a6d2019-01-03 14:46:23 +0100254 header_extensions = webrtc::ParsedRtcEventLog::
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200255 UnconfiguredHeaderExtensions::kAttemptWebrtcDefaultConfig;
256 }
Björn Tereliusa06048a2019-11-01 14:31:46 +0100257 webrtc::ParsedRtcEventLog parsed_log(header_extensions,
258 /*allow_incomplete_logs*/ true);
terelius54ce6802016-07-13 06:44:41 -0700259
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200260 if (args.size() == 2) {
261 std::string filename = args[1];
Björn Tereliusa06048a2019-11-01 14:31:46 +0100262 auto status = parsed_log.ParseFile(filename);
263 if (!status.ok()) {
264 std::cerr << "Failed to parse " << filename << ": " << status.message()
265 << std::endl;
266 return -1;
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200267 }
terelius54ce6802016-07-13 06:44:41 -0700268 }
269
Bjorn Terelius48b82792020-05-19 10:57:24 +0200270 webrtc::AnalyzerConfig config;
Björn Tereliuscb241582022-02-25 08:22:38 +0000271 config.window_duration_ = webrtc::TimeDelta::Millis(250);
272 config.step_ = webrtc::TimeDelta::Millis(10);
273 if (!parsed_log.start_log_events().empty()) {
274 config.rtc_to_utc_offset_ = parsed_log.start_log_events()[0].utc_time() -
275 parsed_log.start_log_events()[0].log_time();
276 }
Bjorn Terelius48b82792020-05-19 10:57:24 +0200277 config.normalize_time_ = absl::GetFlag(FLAGS_normalize_time);
278 config.begin_time_ = parsed_log.first_timestamp();
279 config.end_time_ = parsed_log.last_timestamp();
280 if (config.end_time_ < config.begin_time_) {
281 RTC_LOG(LS_WARNING) << "Log end time " << config.end_time_
282 << " not after begin time " << config.begin_time_
283 << ". Nothing to analyze. Is the log broken?";
284 return -1;
285 }
286
287 webrtc::EventLogAnalyzer analyzer(parsed_log, config);
Bjorn Terelius8a89b5b2020-06-09 17:17:21 +0200288 webrtc::PlotCollection collection;
Björn Tereliuscb241582022-02-25 08:22:38 +0000289 collection.SetCallTimeToUtcOffsetMs(config.CallTimeToUtcOffsetMs());
terelius54ce6802016-07-13 06:44:41 -0700290
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200291 PlotMap plots;
292 plots.RegisterPlot("incoming_packet_sizes", [&](Plot* plot) {
293 analyzer.CreatePacketGraph(webrtc::kIncomingPacket, plot);
294 });
295
296 plots.RegisterPlot("outgoing_packet_sizes", [&](Plot* plot) {
297 analyzer.CreatePacketGraph(webrtc::kOutgoingPacket, plot);
298 });
299 plots.RegisterPlot("incoming_rtcp_types", [&](Plot* plot) {
300 analyzer.CreateRtcpTypeGraph(webrtc::kIncomingPacket, plot);
301 });
302 plots.RegisterPlot("outgoing_rtcp_types", [&](Plot* plot) {
303 analyzer.CreateRtcpTypeGraph(webrtc::kOutgoingPacket, plot);
304 });
305 plots.RegisterPlot("incoming_packet_count", [&](Plot* plot) {
306 analyzer.CreateAccumulatedPacketsGraph(webrtc::kIncomingPacket, plot);
307 });
308 plots.RegisterPlot("outgoing_packet_count", [&](Plot* plot) {
309 analyzer.CreateAccumulatedPacketsGraph(webrtc::kOutgoingPacket, plot);
310 });
Kristoffer Erlandsson283c1062020-03-30 13:01:37 +0200311 plots.RegisterPlot("incoming_packet_rate", [&](Plot* plot) {
312 analyzer.CreatePacketRateGraph(webrtc::kIncomingPacket, plot);
313 });
314 plots.RegisterPlot("outgoing_packet_rate", [&](Plot* plot) {
315 analyzer.CreatePacketRateGraph(webrtc::kOutgoingPacket, plot);
316 });
Kristoffer Erlandssona2ce4232020-04-01 14:33:30 +0200317 plots.RegisterPlot("total_incoming_packet_rate", [&](Plot* plot) {
318 analyzer.CreateTotalPacketRateGraph(webrtc::kIncomingPacket, plot);
319 });
320 plots.RegisterPlot("total_outgoing_packet_rate", [&](Plot* plot) {
321 analyzer.CreateTotalPacketRateGraph(webrtc::kOutgoingPacket, plot);
322 });
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200323 plots.RegisterPlot("audio_playout",
324 [&](Plot* plot) { analyzer.CreatePlayoutGraph(plot); });
Lionel Koenig6afa92a2023-01-16 11:23:36 +0100325
326 plots.RegisterPlot("neteq_set_minimum_delay", [&](Plot* plot) {
327 analyzer.CreateNetEqSetMinimumDelay(plot);
328 });
329
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200330 plots.RegisterPlot("incoming_audio_level", [&](Plot* plot) {
331 analyzer.CreateAudioLevelGraph(webrtc::kIncomingPacket, plot);
332 });
333 plots.RegisterPlot("outgoing_audio_level", [&](Plot* plot) {
334 analyzer.CreateAudioLevelGraph(webrtc::kOutgoingPacket, plot);
335 });
336 plots.RegisterPlot("incoming_sequence_number_delta", [&](Plot* plot) {
337 analyzer.CreateSequenceNumberGraph(plot);
338 });
339 plots.RegisterPlot("incoming_delay", [&](Plot* plot) {
340 analyzer.CreateIncomingDelayGraph(plot);
341 });
342 plots.RegisterPlot("incoming_loss_rate", [&](Plot* plot) {
343 analyzer.CreateIncomingPacketLossGraph(plot);
344 });
345 plots.RegisterPlot("incoming_bitrate", [&](Plot* plot) {
346 analyzer.CreateTotalIncomingBitrateGraph(plot);
347 });
348 plots.RegisterPlot("outgoing_bitrate", [&](Plot* plot) {
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200349 analyzer.CreateTotalOutgoingBitrateGraph(
350 plot, absl::GetFlag(FLAGS_show_detector_state),
Diep Bui38b3cf02022-07-19 14:09:45 +0200351 absl::GetFlag(FLAGS_show_alr_state),
352 absl::GetFlag(FLAGS_show_link_capacity));
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200353 });
354 plots.RegisterPlot("incoming_stream_bitrate", [&](Plot* plot) {
355 analyzer.CreateStreamBitrateGraph(webrtc::kIncomingPacket, plot);
356 });
357 plots.RegisterPlot("outgoing_stream_bitrate", [&](Plot* plot) {
358 analyzer.CreateStreamBitrateGraph(webrtc::kOutgoingPacket, plot);
359 });
360 plots.RegisterPlot("incoming_layer_bitrate_allocation", [&](Plot* plot) {
361 analyzer.CreateBitrateAllocationGraph(webrtc::kIncomingPacket, plot);
362 });
363 plots.RegisterPlot("outgoing_layer_bitrate_allocation", [&](Plot* plot) {
364 analyzer.CreateBitrateAllocationGraph(webrtc::kOutgoingPacket, plot);
365 });
366 plots.RegisterPlot("simulated_receiveside_bwe", [&](Plot* plot) {
367 analyzer.CreateReceiveSideBweSimulationGraph(plot);
368 });
369 plots.RegisterPlot("simulated_sendside_bwe", [&](Plot* plot) {
370 analyzer.CreateSendSideBweSimulationGraph(plot);
371 });
372 plots.RegisterPlot("simulated_goog_cc", [&](Plot* plot) {
373 analyzer.CreateGoogCcSimulationGraph(plot);
374 });
375 plots.RegisterPlot("network_delay_feedback", [&](Plot* plot) {
376 analyzer.CreateNetworkDelayFeedbackGraph(plot);
377 });
378 plots.RegisterPlot("fraction_loss_feedback", [&](Plot* plot) {
379 analyzer.CreateFractionLossGraph(plot);
380 });
381 plots.RegisterPlot("incoming_timestamps", [&](Plot* plot) {
382 analyzer.CreateTimestampGraph(webrtc::kIncomingPacket, plot);
383 });
384 plots.RegisterPlot("outgoing_timestamps", [&](Plot* plot) {
385 analyzer.CreateTimestampGraph(webrtc::kOutgoingPacket, plot);
386 });
387
388 auto GetFractionLost = [](const webrtc::rtcp::ReportBlock& block) -> float {
389 return static_cast<double>(block.fraction_lost()) / 256 * 100;
390 };
391 plots.RegisterPlot("incoming_rtcp_fraction_lost", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200392 analyzer.CreateSenderAndReceiverReportPlot(
393 webrtc::kIncomingPacket, GetFractionLost,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200394 "Fraction lost (incoming RTCP)", "Loss rate (percent)", plot);
395 });
396 plots.RegisterPlot("outgoing_rtcp_fraction_lost", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200397 analyzer.CreateSenderAndReceiverReportPlot(
398 webrtc::kOutgoingPacket, GetFractionLost,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200399 "Fraction lost (outgoing RTCP)", "Loss rate (percent)", plot);
400 });
401 auto GetCumulativeLost = [](const webrtc::rtcp::ReportBlock& block) -> float {
402 return block.cumulative_lost_signed();
403 };
404 plots.RegisterPlot("incoming_rtcp_cumulative_lost", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200405 analyzer.CreateSenderAndReceiverReportPlot(
406 webrtc::kIncomingPacket, GetCumulativeLost,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200407 "Cumulative lost packets (incoming RTCP)", "Packets", plot);
408 });
409 plots.RegisterPlot("outgoing_rtcp_cumulative_lost", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200410 analyzer.CreateSenderAndReceiverReportPlot(
411 webrtc::kOutgoingPacket, GetCumulativeLost,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200412 "Cumulative lost packets (outgoing RTCP)", "Packets", plot);
413 });
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200414
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200415 auto GetHighestSeqNumber =
416 [](const webrtc::rtcp::ReportBlock& block) -> float {
417 return block.extended_high_seq_num();
418 };
419 plots.RegisterPlot("incoming_rtcp_highest_seq_number", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200420 analyzer.CreateSenderAndReceiverReportPlot(
421 webrtc::kIncomingPacket, GetHighestSeqNumber,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200422 "Highest sequence number (incoming RTCP)", "Sequence number", plot);
423 });
424 plots.RegisterPlot("outgoing_rtcp_highest_seq_number", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200425 analyzer.CreateSenderAndReceiverReportPlot(
426 webrtc::kOutgoingPacket, GetHighestSeqNumber,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200427 "Highest sequence number (outgoing RTCP)", "Sequence number", plot);
428 });
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200429
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200430 auto DelaySinceLastSr = [](const webrtc::rtcp::ReportBlock& block) -> float {
431 return static_cast<double>(block.delay_since_last_sr()) / 65536;
432 };
433 plots.RegisterPlot("incoming_rtcp_delay_since_last_sr", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200434 analyzer.CreateSenderAndReceiverReportPlot(
435 webrtc::kIncomingPacket, DelaySinceLastSr,
436 "Delay since last received sender report (incoming RTCP)", "Time (s)",
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200437 plot);
438 });
439 plots.RegisterPlot("outgoing_rtcp_delay_since_last_sr", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200440 analyzer.CreateSenderAndReceiverReportPlot(
441 webrtc::kOutgoingPacket, DelaySinceLastSr,
442 "Delay since last received sender report (outgoing RTCP)", "Time (s)",
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200443 plot);
444 });
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200445
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200446 plots.RegisterPlot("pacer_delay",
447 [&](Plot* plot) { analyzer.CreatePacerDelayGraph(plot); });
448 plots.RegisterPlot("audio_encoder_bitrate", [&](Plot* plot) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200449 CreateAudioEncoderTargetBitrateGraph(parsed_log, config, plot);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200450 });
451 plots.RegisterPlot("audio_encoder_frame_length", [&](Plot* plot) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200452 CreateAudioEncoderFrameLengthGraph(parsed_log, config, plot);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200453 });
454 plots.RegisterPlot("audio_encoder_packet_loss", [&](Plot* plot) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200455 CreateAudioEncoderPacketLossGraph(parsed_log, config, plot);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200456 });
457 plots.RegisterPlot("audio_encoder_fec", [&](Plot* plot) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200458 CreateAudioEncoderEnableFecGraph(parsed_log, config, plot);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200459 });
460 plots.RegisterPlot("audio_encoder_dtx", [&](Plot* plot) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200461 CreateAudioEncoderEnableDtxGraph(parsed_log, config, plot);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200462 });
463 plots.RegisterPlot("audio_encoder_num_channels", [&](Plot* plot) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200464 CreateAudioEncoderNumChannelsGraph(parsed_log, config, plot);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200465 });
466
467 plots.RegisterPlot("ice_candidate_pair_config", [&](Plot* plot) {
468 analyzer.CreateIceCandidatePairConfigGraph(plot);
469 });
470 plots.RegisterPlot("ice_connectivity_check", [&](Plot* plot) {
471 analyzer.CreateIceConnectivityCheckGraph(plot);
472 });
473 plots.RegisterPlot("dtls_transport_state", [&](Plot* plot) {
474 analyzer.CreateDtlsTransportStateGraph(plot);
475 });
476 plots.RegisterPlot("dtls_writable_state", [&](Plot* plot) {
477 analyzer.CreateDtlsWritableStateGraph(plot);
478 });
479
480 std::string wav_path;
Mirko Bonadei6183a0f2022-07-05 19:19:43 +0000481 bool has_generated_wav_file = false;
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200482 if (!absl::GetFlag(FLAGS_wav_filename).empty()) {
483 wav_path = absl::GetFlag(FLAGS_wav_filename);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200484 } else {
Mirko Bonadei6183a0f2022-07-05 19:19:43 +0000485 // TODO(bugs.webrtc.org/14248): Remove the need to generate a file
486 // and read the file directly from memory.
487 wav_path = std::tmpnam(nullptr);
488 std::ofstream out_wav_file(wav_path);
489 out_wav_file.write(
490 reinterpret_cast<char*>(&webrtc::conversational_speech_en_wav[0]),
491 webrtc::conversational_speech_en_wav_len);
492 has_generated_wav_file = true;
Bjorn Terelius0295a962017-10-25 17:42:41 +0200493 }
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200494 absl::optional<webrtc::NetEqStatsGetterMap> neteq_stats;
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200495
496 plots.RegisterPlot("simulated_neteq_expand_rate", [&](Plot* plot) {
497 if (!neteq_stats) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200498 neteq_stats = webrtc::SimulateNetEq(parsed_log, config, wav_path, 48000);
Minyue Li45fc6df2018-06-21 11:47:14 +0200499 }
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200500 webrtc::CreateNetEqNetworkStatsGraph(
501 parsed_log, config, *neteq_stats,
Minyue Li27e2b7d2018-05-07 15:20:24 +0200502 [](const webrtc::NetEqNetworkStatistics& stats) {
503 return stats.expand_rate / 16384.f;
504 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200505 "Expand rate", plot);
506 });
507
508 plots.RegisterPlot("simulated_neteq_speech_expand_rate", [&](Plot* plot) {
509 if (!neteq_stats) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200510 neteq_stats = webrtc::SimulateNetEq(parsed_log, config, wav_path, 48000);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200511 }
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200512 webrtc::CreateNetEqNetworkStatsGraph(
513 parsed_log, config, *neteq_stats,
Minyue Li27e2b7d2018-05-07 15:20:24 +0200514 [](const webrtc::NetEqNetworkStatistics& stats) {
515 return stats.speech_expand_rate / 16384.f;
516 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200517 "Speech expand rate", plot);
518 });
519
520 plots.RegisterPlot("simulated_neteq_accelerate_rate", [&](Plot* plot) {
521 if (!neteq_stats) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200522 neteq_stats = webrtc::SimulateNetEq(parsed_log, config, wav_path, 48000);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200523 }
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200524 webrtc::CreateNetEqNetworkStatsGraph(
525 parsed_log, config, *neteq_stats,
Minyue Li27e2b7d2018-05-07 15:20:24 +0200526 [](const webrtc::NetEqNetworkStatistics& stats) {
527 return stats.accelerate_rate / 16384.f;
528 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200529 "Accelerate rate", plot);
530 });
531
532 plots.RegisterPlot("simulated_neteq_preemptive_rate", [&](Plot* plot) {
533 if (!neteq_stats) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200534 neteq_stats = webrtc::SimulateNetEq(parsed_log, config, wav_path, 48000);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200535 }
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200536 webrtc::CreateNetEqNetworkStatsGraph(
537 parsed_log, config, *neteq_stats,
Minyue Li27e2b7d2018-05-07 15:20:24 +0200538 [](const webrtc::NetEqNetworkStatistics& stats) {
Jakob Ivarsson21f6fd72019-04-04 10:15:02 +0200539 return stats.preemptive_rate / 16384.f;
540 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200541 "Preemptive rate", plot);
542 });
543
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200544 plots.RegisterPlot("simulated_neteq_concealment_events", [&](Plot* plot) {
545 if (!neteq_stats) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200546 neteq_stats = webrtc::SimulateNetEq(parsed_log, config, wav_path, 48000);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200547 }
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200548 webrtc::CreateNetEqLifetimeStatsGraph(
549 parsed_log, config, *neteq_stats,
Minyue Lic9ac93f2018-06-26 13:01:32 +0200550 [](const webrtc::NetEqLifetimeStatistics& stats) {
551 return static_cast<float>(stats.concealment_events);
552 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200553 "Concealment events", plot);
554 });
555
556 plots.RegisterPlot("simulated_neteq_preferred_buffer_size", [&](Plot* plot) {
557 if (!neteq_stats) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200558 neteq_stats = webrtc::SimulateNetEq(parsed_log, config, wav_path, 48000);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200559 }
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200560 webrtc::CreateNetEqNetworkStatsGraph(
561 parsed_log, config, *neteq_stats,
Jakob Ivarsson21f6fd72019-04-04 10:15:02 +0200562 [](const webrtc::NetEqNetworkStatistics& stats) {
563 return stats.preferred_buffer_size_ms;
564 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200565 "Preferred buffer size (ms)", plot);
566 });
567
568 if (absl::c_find(plot_flags, "all") != plot_flags.end()) {
569 plots.EnableAllPlots();
570 // Treated separately since it isn't registered like the other plots.
571 plot_flags.push_back("simulated_neteq_jitter_buffer_delay");
572 } else {
573 bool success = plots.EnablePlotsByFlags(plot_flags, flag_aliases);
574 if (!success) {
575 return 1;
576 }
henrik.lundin3c938fc2017-06-14 06:09:58 -0700577 }
578
Mirko Bonadeif2d97b82019-07-24 15:29:47 +0200579 if (absl::GetFlag(FLAGS_list_plots)) {
580 std::cerr << "List of registered plots (for use with the --plot flag):"
581 << std::endl;
582 for (const auto& plot : plots) {
583 // TODO(terelius): Also print a help text.
584 std::cerr << " " << plot.label << std::endl;
585 }
586 // The following flag doesn't fit the model used for the other plots.
587 std::cerr << "simulated_neteq_jitter_buffer_delay" << std::endl;
588 std::cerr << "List of plot aliases (for use with the --plot flag):"
589 << std::endl;
590 std::cerr << " all = every registered plot" << std::endl;
591 for (const auto& alias : flag_aliases) {
592 std::cerr << " " << alias.first << " = ";
593 for (const auto& replacement : alias.second) {
594 std::cerr << replacement << ",";
595 }
596 std::cerr << std::endl;
597 }
598 return 0;
599 }
600 if (args.size() != 2) {
601 // Print usage information.
602 std::cerr << absl::ProgramUsageMessage();
603 return 1;
604 }
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800605
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200606 for (const auto& plot : plots) {
607 if (plot.enabled) {
Bjorn Terelius8a89b5b2020-06-09 17:17:21 +0200608 Plot* output = collection.AppendNewPlot();
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200609 plot.plot_func(output);
610 output->SetId(plot.label);
611 }
Zach Stein10a58012018-12-07 12:26:28 -0800612 }
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200613
614 // The model we use for registering plots assumes that the each plot label
615 // can be mapped to a lambda that will produce exactly one plot. The
616 // simulated_neteq_jitter_buffer_delay plot doesn't fit this model since it
617 // creates multiple plots, and would need some state kept between the lambda
618 // calls.
619 if (absl::c_find(plot_flags, "simulated_neteq_jitter_buffer_delay") !=
620 plot_flags.end()) {
621 if (!neteq_stats) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200622 neteq_stats = webrtc::SimulateNetEq(parsed_log, config, wav_path, 48000);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200623 }
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200624 for (webrtc::NetEqStatsGetterMap::const_iterator it = neteq_stats->cbegin();
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200625 it != neteq_stats->cend(); ++it) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200626 webrtc::CreateAudioJitterBufferGraph(parsed_log, config, it->first,
627 it->second.get(),
Bjorn Terelius8a89b5b2020-06-09 17:17:21 +0200628 collection.AppendNewPlot());
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200629 }
Zach Stein10a58012018-12-07 12:26:28 -0800630 }
631
Bjorn Terelius8a89b5b2020-06-09 17:17:21 +0200632 if (absl::GetFlag(FLAGS_protobuf_output)) {
633 webrtc::analytics::ChartCollection proto_charts;
634 collection.ExportProtobuf(&proto_charts);
635 std::cout << proto_charts.SerializeAsString();
636 } else {
637 collection.PrintPythonCode(absl::GetFlag(FLAGS_shared_xaxis));
638 }
terelius54ce6802016-07-13 06:44:41 -0700639
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200640 if (absl::GetFlag(FLAGS_print_triage_alerts)) {
Bjorn Terelius48b82792020-05-19 10:57:24 +0200641 webrtc::TriageHelper triage_alerts(config);
642 triage_alerts.AnalyzeLog(parsed_log);
643 triage_alerts.Print(stderr);
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100644 }
645
Mirko Bonadei6183a0f2022-07-05 19:19:43 +0000646 // TODO(bugs.webrtc.org/14248): Remove the need to generate a file
647 // and read the file directly from memory.
648 if (has_generated_wav_file) {
649 RTC_CHECK_EQ(std::remove(wav_path.c_str()), 0)
650 << "Failed to remove " << wav_path;
651 }
terelius54ce6802016-07-13 06:44:41 -0700652 return 0;
653}