blob: 0870f8f145947e36cc051584f41a8773eb52a865 [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,
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,
Bjorn Tereliusadef7982020-05-19 13:12:01 +020081 true,
Mirko Bonadei4b091f42019-07-16 11:55:08 +020082 "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",
Jakob Ivarssonddd41912020-11-03 13:28:52 +0100233 "simulated_neteq_concealment_events", "simulated_neteq_preemptive_rate",
Bjorn Terelius873a7a92019-06-13 16:01:17 +0200234 "simulated_neteq_accelerate_rate", "simulated_neteq_speech_expand_rate",
235 "simulated_neteq_expand_rate"}}};
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200236
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200237 std::vector<std::string> plot_flags =
238 StrSplit(absl::GetFlag(FLAGS_plot), ",");
kjellander4fa5be42017-05-16 00:01:23 -0700239
Bjorn Tereliusedab3012018-01-31 17:23:40 +0100240 // InitFieldTrialsFromString stores the char*, so the char array must outlive
241 // the application.
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200242 const std::string field_trials = absl::GetFlag(FLAGS_force_fieldtrials);
243 webrtc::field_trial::InitFieldTrialsFromString(field_trials.c_str());
stefan985d2802016-11-15 06:54:09 -0800244
Sebastian Janssonb290a6d2019-01-03 14:46:23 +0100245 webrtc::ParsedRtcEventLog::UnconfiguredHeaderExtensions header_extensions =
246 webrtc::ParsedRtcEventLog::UnconfiguredHeaderExtensions::kDontParse;
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200247 if (absl::GetFlag(FLAGS_parse_unconfigured_header_extensions)) {
Sebastian Janssonb290a6d2019-01-03 14:46:23 +0100248 header_extensions = webrtc::ParsedRtcEventLog::
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200249 UnconfiguredHeaderExtensions::kAttemptWebrtcDefaultConfig;
250 }
Björn Tereliusa06048a2019-11-01 14:31:46 +0100251 webrtc::ParsedRtcEventLog parsed_log(header_extensions,
252 /*allow_incomplete_logs*/ true);
terelius54ce6802016-07-13 06:44:41 -0700253
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200254 if (args.size() == 2) {
255 std::string filename = args[1];
Björn Tereliusa06048a2019-11-01 14:31:46 +0100256 auto status = parsed_log.ParseFile(filename);
257 if (!status.ok()) {
258 std::cerr << "Failed to parse " << filename << ": " << status.message()
259 << std::endl;
260 return -1;
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200261 }
terelius54ce6802016-07-13 06:44:41 -0700262 }
263
Bjorn Terelius48b82792020-05-19 10:57:24 +0200264 webrtc::AnalyzerConfig config;
Björn Tereliuscb241582022-02-25 08:22:38 +0000265 config.window_duration_ = webrtc::TimeDelta::Millis(250);
266 config.step_ = webrtc::TimeDelta::Millis(10);
267 if (!parsed_log.start_log_events().empty()) {
268 config.rtc_to_utc_offset_ = parsed_log.start_log_events()[0].utc_time() -
269 parsed_log.start_log_events()[0].log_time();
270 }
Bjorn Terelius48b82792020-05-19 10:57:24 +0200271 config.normalize_time_ = absl::GetFlag(FLAGS_normalize_time);
272 config.begin_time_ = parsed_log.first_timestamp();
273 config.end_time_ = parsed_log.last_timestamp();
274 if (config.end_time_ < config.begin_time_) {
275 RTC_LOG(LS_WARNING) << "Log end time " << config.end_time_
276 << " not after begin time " << config.begin_time_
277 << ". Nothing to analyze. Is the log broken?";
278 return -1;
279 }
280
281 webrtc::EventLogAnalyzer analyzer(parsed_log, config);
Bjorn Terelius8a89b5b2020-06-09 17:17:21 +0200282 webrtc::PlotCollection collection;
Björn Tereliuscb241582022-02-25 08:22:38 +0000283 collection.SetCallTimeToUtcOffsetMs(config.CallTimeToUtcOffsetMs());
terelius54ce6802016-07-13 06:44:41 -0700284
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200285 PlotMap plots;
286 plots.RegisterPlot("incoming_packet_sizes", [&](Plot* plot) {
287 analyzer.CreatePacketGraph(webrtc::kIncomingPacket, plot);
288 });
289
290 plots.RegisterPlot("outgoing_packet_sizes", [&](Plot* plot) {
291 analyzer.CreatePacketGraph(webrtc::kOutgoingPacket, plot);
292 });
293 plots.RegisterPlot("incoming_rtcp_types", [&](Plot* plot) {
294 analyzer.CreateRtcpTypeGraph(webrtc::kIncomingPacket, plot);
295 });
296 plots.RegisterPlot("outgoing_rtcp_types", [&](Plot* plot) {
297 analyzer.CreateRtcpTypeGraph(webrtc::kOutgoingPacket, plot);
298 });
299 plots.RegisterPlot("incoming_packet_count", [&](Plot* plot) {
300 analyzer.CreateAccumulatedPacketsGraph(webrtc::kIncomingPacket, plot);
301 });
302 plots.RegisterPlot("outgoing_packet_count", [&](Plot* plot) {
303 analyzer.CreateAccumulatedPacketsGraph(webrtc::kOutgoingPacket, plot);
304 });
Kristoffer Erlandsson283c1062020-03-30 13:01:37 +0200305 plots.RegisterPlot("incoming_packet_rate", [&](Plot* plot) {
306 analyzer.CreatePacketRateGraph(webrtc::kIncomingPacket, plot);
307 });
308 plots.RegisterPlot("outgoing_packet_rate", [&](Plot* plot) {
309 analyzer.CreatePacketRateGraph(webrtc::kOutgoingPacket, plot);
310 });
Kristoffer Erlandssona2ce4232020-04-01 14:33:30 +0200311 plots.RegisterPlot("total_incoming_packet_rate", [&](Plot* plot) {
312 analyzer.CreateTotalPacketRateGraph(webrtc::kIncomingPacket, plot);
313 });
314 plots.RegisterPlot("total_outgoing_packet_rate", [&](Plot* plot) {
315 analyzer.CreateTotalPacketRateGraph(webrtc::kOutgoingPacket, plot);
316 });
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200317 plots.RegisterPlot("audio_playout",
318 [&](Plot* plot) { analyzer.CreatePlayoutGraph(plot); });
319 plots.RegisterPlot("incoming_audio_level", [&](Plot* plot) {
320 analyzer.CreateAudioLevelGraph(webrtc::kIncomingPacket, plot);
321 });
322 plots.RegisterPlot("outgoing_audio_level", [&](Plot* plot) {
323 analyzer.CreateAudioLevelGraph(webrtc::kOutgoingPacket, plot);
324 });
325 plots.RegisterPlot("incoming_sequence_number_delta", [&](Plot* plot) {
326 analyzer.CreateSequenceNumberGraph(plot);
327 });
328 plots.RegisterPlot("incoming_delay", [&](Plot* plot) {
329 analyzer.CreateIncomingDelayGraph(plot);
330 });
331 plots.RegisterPlot("incoming_loss_rate", [&](Plot* plot) {
332 analyzer.CreateIncomingPacketLossGraph(plot);
333 });
334 plots.RegisterPlot("incoming_bitrate", [&](Plot* plot) {
335 analyzer.CreateTotalIncomingBitrateGraph(plot);
336 });
337 plots.RegisterPlot("outgoing_bitrate", [&](Plot* plot) {
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200338 analyzer.CreateTotalOutgoingBitrateGraph(
339 plot, absl::GetFlag(FLAGS_show_detector_state),
340 absl::GetFlag(FLAGS_show_alr_state));
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200341 });
342 plots.RegisterPlot("incoming_stream_bitrate", [&](Plot* plot) {
343 analyzer.CreateStreamBitrateGraph(webrtc::kIncomingPacket, plot);
344 });
345 plots.RegisterPlot("outgoing_stream_bitrate", [&](Plot* plot) {
346 analyzer.CreateStreamBitrateGraph(webrtc::kOutgoingPacket, plot);
347 });
348 plots.RegisterPlot("incoming_layer_bitrate_allocation", [&](Plot* plot) {
349 analyzer.CreateBitrateAllocationGraph(webrtc::kIncomingPacket, plot);
350 });
351 plots.RegisterPlot("outgoing_layer_bitrate_allocation", [&](Plot* plot) {
352 analyzer.CreateBitrateAllocationGraph(webrtc::kOutgoingPacket, plot);
353 });
354 plots.RegisterPlot("simulated_receiveside_bwe", [&](Plot* plot) {
355 analyzer.CreateReceiveSideBweSimulationGraph(plot);
356 });
357 plots.RegisterPlot("simulated_sendside_bwe", [&](Plot* plot) {
358 analyzer.CreateSendSideBweSimulationGraph(plot);
359 });
360 plots.RegisterPlot("simulated_goog_cc", [&](Plot* plot) {
361 analyzer.CreateGoogCcSimulationGraph(plot);
362 });
363 plots.RegisterPlot("network_delay_feedback", [&](Plot* plot) {
364 analyzer.CreateNetworkDelayFeedbackGraph(plot);
365 });
366 plots.RegisterPlot("fraction_loss_feedback", [&](Plot* plot) {
367 analyzer.CreateFractionLossGraph(plot);
368 });
369 plots.RegisterPlot("incoming_timestamps", [&](Plot* plot) {
370 analyzer.CreateTimestampGraph(webrtc::kIncomingPacket, plot);
371 });
372 plots.RegisterPlot("outgoing_timestamps", [&](Plot* plot) {
373 analyzer.CreateTimestampGraph(webrtc::kOutgoingPacket, plot);
374 });
375
376 auto GetFractionLost = [](const webrtc::rtcp::ReportBlock& block) -> float {
377 return static_cast<double>(block.fraction_lost()) / 256 * 100;
378 };
379 plots.RegisterPlot("incoming_rtcp_fraction_lost", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200380 analyzer.CreateSenderAndReceiverReportPlot(
381 webrtc::kIncomingPacket, GetFractionLost,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200382 "Fraction lost (incoming RTCP)", "Loss rate (percent)", plot);
383 });
384 plots.RegisterPlot("outgoing_rtcp_fraction_lost", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200385 analyzer.CreateSenderAndReceiverReportPlot(
386 webrtc::kOutgoingPacket, GetFractionLost,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200387 "Fraction lost (outgoing RTCP)", "Loss rate (percent)", plot);
388 });
389 auto GetCumulativeLost = [](const webrtc::rtcp::ReportBlock& block) -> float {
390 return block.cumulative_lost_signed();
391 };
392 plots.RegisterPlot("incoming_rtcp_cumulative_lost", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200393 analyzer.CreateSenderAndReceiverReportPlot(
394 webrtc::kIncomingPacket, GetCumulativeLost,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200395 "Cumulative lost packets (incoming RTCP)", "Packets", plot);
396 });
397 plots.RegisterPlot("outgoing_rtcp_cumulative_lost", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200398 analyzer.CreateSenderAndReceiverReportPlot(
399 webrtc::kOutgoingPacket, GetCumulativeLost,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200400 "Cumulative lost packets (outgoing RTCP)", "Packets", plot);
401 });
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200402
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200403 auto GetHighestSeqNumber =
404 [](const webrtc::rtcp::ReportBlock& block) -> float {
405 return block.extended_high_seq_num();
406 };
407 plots.RegisterPlot("incoming_rtcp_highest_seq_number", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200408 analyzer.CreateSenderAndReceiverReportPlot(
409 webrtc::kIncomingPacket, GetHighestSeqNumber,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200410 "Highest sequence number (incoming RTCP)", "Sequence number", plot);
411 });
412 plots.RegisterPlot("outgoing_rtcp_highest_seq_number", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200413 analyzer.CreateSenderAndReceiverReportPlot(
414 webrtc::kOutgoingPacket, GetHighestSeqNumber,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200415 "Highest sequence number (outgoing RTCP)", "Sequence number", plot);
416 });
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200417
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200418 auto DelaySinceLastSr = [](const webrtc::rtcp::ReportBlock& block) -> float {
419 return static_cast<double>(block.delay_since_last_sr()) / 65536;
420 };
421 plots.RegisterPlot("incoming_rtcp_delay_since_last_sr", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200422 analyzer.CreateSenderAndReceiverReportPlot(
423 webrtc::kIncomingPacket, DelaySinceLastSr,
424 "Delay since last received sender report (incoming RTCP)", "Time (s)",
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200425 plot);
426 });
427 plots.RegisterPlot("outgoing_rtcp_delay_since_last_sr", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200428 analyzer.CreateSenderAndReceiverReportPlot(
429 webrtc::kOutgoingPacket, DelaySinceLastSr,
430 "Delay since last received sender report (outgoing RTCP)", "Time (s)",
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200431 plot);
432 });
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200433
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200434 plots.RegisterPlot("pacer_delay",
435 [&](Plot* plot) { analyzer.CreatePacerDelayGraph(plot); });
436 plots.RegisterPlot("audio_encoder_bitrate", [&](Plot* plot) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200437 CreateAudioEncoderTargetBitrateGraph(parsed_log, config, plot);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200438 });
439 plots.RegisterPlot("audio_encoder_frame_length", [&](Plot* plot) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200440 CreateAudioEncoderFrameLengthGraph(parsed_log, config, plot);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200441 });
442 plots.RegisterPlot("audio_encoder_packet_loss", [&](Plot* plot) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200443 CreateAudioEncoderPacketLossGraph(parsed_log, config, plot);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200444 });
445 plots.RegisterPlot("audio_encoder_fec", [&](Plot* plot) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200446 CreateAudioEncoderEnableFecGraph(parsed_log, config, plot);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200447 });
448 plots.RegisterPlot("audio_encoder_dtx", [&](Plot* plot) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200449 CreateAudioEncoderEnableDtxGraph(parsed_log, config, plot);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200450 });
451 plots.RegisterPlot("audio_encoder_num_channels", [&](Plot* plot) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200452 CreateAudioEncoderNumChannelsGraph(parsed_log, config, plot);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200453 });
454
455 plots.RegisterPlot("ice_candidate_pair_config", [&](Plot* plot) {
456 analyzer.CreateIceCandidatePairConfigGraph(plot);
457 });
458 plots.RegisterPlot("ice_connectivity_check", [&](Plot* plot) {
459 analyzer.CreateIceConnectivityCheckGraph(plot);
460 });
461 plots.RegisterPlot("dtls_transport_state", [&](Plot* plot) {
462 analyzer.CreateDtlsTransportStateGraph(plot);
463 });
464 plots.RegisterPlot("dtls_writable_state", [&](Plot* plot) {
465 analyzer.CreateDtlsWritableStateGraph(plot);
466 });
467
468 std::string wav_path;
Mirko Bonadei6183a0f2022-07-05 19:19:43 +0000469 bool has_generated_wav_file = false;
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200470 if (!absl::GetFlag(FLAGS_wav_filename).empty()) {
471 wav_path = absl::GetFlag(FLAGS_wav_filename);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200472 } else {
Mirko Bonadei6183a0f2022-07-05 19:19:43 +0000473 // TODO(bugs.webrtc.org/14248): Remove the need to generate a file
474 // and read the file directly from memory.
475 wav_path = std::tmpnam(nullptr);
476 std::ofstream out_wav_file(wav_path);
477 out_wav_file.write(
478 reinterpret_cast<char*>(&webrtc::conversational_speech_en_wav[0]),
479 webrtc::conversational_speech_en_wav_len);
480 has_generated_wav_file = true;
Bjorn Terelius0295a962017-10-25 17:42:41 +0200481 }
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200482 absl::optional<webrtc::NetEqStatsGetterMap> neteq_stats;
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200483
484 plots.RegisterPlot("simulated_neteq_expand_rate", [&](Plot* plot) {
485 if (!neteq_stats) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200486 neteq_stats = webrtc::SimulateNetEq(parsed_log, config, wav_path, 48000);
Minyue Li45fc6df2018-06-21 11:47:14 +0200487 }
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200488 webrtc::CreateNetEqNetworkStatsGraph(
489 parsed_log, config, *neteq_stats,
Minyue Li27e2b7d2018-05-07 15:20:24 +0200490 [](const webrtc::NetEqNetworkStatistics& stats) {
491 return stats.expand_rate / 16384.f;
492 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200493 "Expand rate", plot);
494 });
495
496 plots.RegisterPlot("simulated_neteq_speech_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);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +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.speech_expand_rate / 16384.f;
504 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200505 "Speech expand rate", plot);
506 });
507
508 plots.RegisterPlot("simulated_neteq_accelerate_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.accelerate_rate / 16384.f;
516 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200517 "Accelerate rate", plot);
518 });
519
520 plots.RegisterPlot("simulated_neteq_preemptive_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) {
Jakob Ivarsson21f6fd72019-04-04 10:15:02 +0200527 return stats.preemptive_rate / 16384.f;
528 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200529 "Preemptive rate", plot);
530 });
531
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200532 plots.RegisterPlot("simulated_neteq_concealment_events", [&](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::CreateNetEqLifetimeStatsGraph(
537 parsed_log, config, *neteq_stats,
Minyue Lic9ac93f2018-06-26 13:01:32 +0200538 [](const webrtc::NetEqLifetimeStatistics& stats) {
539 return static_cast<float>(stats.concealment_events);
540 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200541 "Concealment events", plot);
542 });
543
544 plots.RegisterPlot("simulated_neteq_preferred_buffer_size", [&](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::CreateNetEqNetworkStatsGraph(
549 parsed_log, config, *neteq_stats,
Jakob Ivarsson21f6fd72019-04-04 10:15:02 +0200550 [](const webrtc::NetEqNetworkStatistics& stats) {
551 return stats.preferred_buffer_size_ms;
552 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200553 "Preferred buffer size (ms)", plot);
554 });
555
556 if (absl::c_find(plot_flags, "all") != plot_flags.end()) {
557 plots.EnableAllPlots();
558 // Treated separately since it isn't registered like the other plots.
559 plot_flags.push_back("simulated_neteq_jitter_buffer_delay");
560 } else {
561 bool success = plots.EnablePlotsByFlags(plot_flags, flag_aliases);
562 if (!success) {
563 return 1;
564 }
henrik.lundin3c938fc2017-06-14 06:09:58 -0700565 }
566
Mirko Bonadeif2d97b82019-07-24 15:29:47 +0200567 if (absl::GetFlag(FLAGS_list_plots)) {
568 std::cerr << "List of registered plots (for use with the --plot flag):"
569 << std::endl;
570 for (const auto& plot : plots) {
571 // TODO(terelius): Also print a help text.
572 std::cerr << " " << plot.label << std::endl;
573 }
574 // The following flag doesn't fit the model used for the other plots.
575 std::cerr << "simulated_neteq_jitter_buffer_delay" << std::endl;
576 std::cerr << "List of plot aliases (for use with the --plot flag):"
577 << std::endl;
578 std::cerr << " all = every registered plot" << std::endl;
579 for (const auto& alias : flag_aliases) {
580 std::cerr << " " << alias.first << " = ";
581 for (const auto& replacement : alias.second) {
582 std::cerr << replacement << ",";
583 }
584 std::cerr << std::endl;
585 }
586 return 0;
587 }
588 if (args.size() != 2) {
589 // Print usage information.
590 std::cerr << absl::ProgramUsageMessage();
591 return 1;
592 }
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800593
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200594 for (const auto& plot : plots) {
595 if (plot.enabled) {
Bjorn Terelius8a89b5b2020-06-09 17:17:21 +0200596 Plot* output = collection.AppendNewPlot();
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200597 plot.plot_func(output);
598 output->SetId(plot.label);
599 }
Zach Stein10a58012018-12-07 12:26:28 -0800600 }
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200601
602 // The model we use for registering plots assumes that the each plot label
603 // can be mapped to a lambda that will produce exactly one plot. The
604 // simulated_neteq_jitter_buffer_delay plot doesn't fit this model since it
605 // creates multiple plots, and would need some state kept between the lambda
606 // calls.
607 if (absl::c_find(plot_flags, "simulated_neteq_jitter_buffer_delay") !=
608 plot_flags.end()) {
609 if (!neteq_stats) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200610 neteq_stats = webrtc::SimulateNetEq(parsed_log, config, wav_path, 48000);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200611 }
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200612 for (webrtc::NetEqStatsGetterMap::const_iterator it = neteq_stats->cbegin();
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200613 it != neteq_stats->cend(); ++it) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200614 webrtc::CreateAudioJitterBufferGraph(parsed_log, config, it->first,
615 it->second.get(),
Bjorn Terelius8a89b5b2020-06-09 17:17:21 +0200616 collection.AppendNewPlot());
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200617 }
Zach Stein10a58012018-12-07 12:26:28 -0800618 }
619
Bjorn Terelius8a89b5b2020-06-09 17:17:21 +0200620 if (absl::GetFlag(FLAGS_protobuf_output)) {
621 webrtc::analytics::ChartCollection proto_charts;
622 collection.ExportProtobuf(&proto_charts);
623 std::cout << proto_charts.SerializeAsString();
624 } else {
625 collection.PrintPythonCode(absl::GetFlag(FLAGS_shared_xaxis));
626 }
terelius54ce6802016-07-13 06:44:41 -0700627
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200628 if (absl::GetFlag(FLAGS_print_triage_alerts)) {
Bjorn Terelius48b82792020-05-19 10:57:24 +0200629 webrtc::TriageHelper triage_alerts(config);
630 triage_alerts.AnalyzeLog(parsed_log);
631 triage_alerts.Print(stderr);
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100632 }
633
Mirko Bonadei6183a0f2022-07-05 19:19:43 +0000634 // TODO(bugs.webrtc.org/14248): Remove the need to generate a file
635 // and read the file directly from memory.
636 if (has_generated_wav_file) {
637 RTC_CHECK_EQ(std::remove(wav_path.c_str()), 0)
638 << "Failed to remove " << wav_path;
639 }
terelius54ce6802016-07-13 06:44:41 -0700640 return 0;
641}