blob: 6182b701dfc5f7f8e48c192f99772298b84a466c [file] [log] [blame]
terelius54ce6802016-07-13 06:44:41 -07001/*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Yves Gerey3e707812018-11-28 16:47:49 +010011#include <stdio.h>
12#include <string.h>
Jonas Olsson5b2eda42019-06-11 14:29:40 +020013
terelius54ce6802016-07-13 06:44:41 -070014#include <iostream>
Yves Gerey3e707812018-11-28 16:47:49 +010015#include <map>
16#include <memory>
17#include <string>
18#include <utility>
Mirko Bonadei4b091f42019-07-16 11:55:08 +020019#include <vector>
terelius54ce6802016-07-13 06:44:41 -070020
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +020021#include "absl/algorithm/container.h"
Mirko Bonadei4b091f42019-07-16 11:55:08 +020022#include "absl/flags/flag.h"
23#include "absl/flags/parse.h"
Mirko Bonadeif2d97b82019-07-24 15:29:47 +020024#include "absl/flags/usage.h"
25#include "absl/flags/usage_config.h"
26#include "absl/strings/match.h"
Ivo Creusen3ce44a32019-10-31 14:38:11 +010027#include "api/neteq/neteq.h"
Danil Chapovalov83bbe912019-08-07 12:24:53 +020028#include "api/rtc_event_log/rtc_event_log.h"
Sebastian Janssonb290a6d2019-01-03 14:46:23 +010029#include "logging/rtc_event_log/rtc_event_log_parser.h"
Yves Gerey3e707812018-11-28 16:47:49 +010030#include "modules/rtp_rtcp/source/rtcp_packet/report_block.h"
31#include "rtc_base/checks.h"
Björn Tereliusa06048a2019-11-01 14:31:46 +010032#include "rtc_base/logging.h"
Bjorn Terelius48b82792020-05-19 10:57:24 +020033#include "rtc_tools/rtc_event_log_visualizer/alerts.h"
Bjorn Tereliusc186e142020-06-05 10:47:19 +020034#include "rtc_tools/rtc_event_log_visualizer/analyze_audio.h"
Mirko Bonadei575998c2019-07-25 13:57:41 +020035#include "rtc_tools/rtc_event_log_visualizer/analyzer.h"
36#include "rtc_tools/rtc_event_log_visualizer/plot_base.h"
Mirko Bonadei17f48782018-09-28 08:51:10 +020037#include "system_wrappers/include/field_trial.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020038#include "test/field_trial.h"
Steve Anton10542f22019-01-11 09:11:00 -080039#include "test/testsupport/file_utils.h"
terelius54ce6802016-07-13 06:44:41 -070040
Mirko Bonadei4b091f42019-07-16 11:55:08 +020041ABSL_FLAG(std::string,
42 plot,
43 "default",
Mirko Bonadeif2d97b82019-07-24 15:29:47 +020044 "A comma separated list of plot names. See --list_plots for valid "
45 "options.");
Bjorn Terelius1edfff92017-10-11 13:15:19 +020046
Mirko Bonadei4b091f42019-07-16 11:55:08 +020047ABSL_FLAG(
48 std::string,
stefan985d2802016-11-15 06:54:09 -080049 force_fieldtrials,
50 "",
51 "Field trials control experimental feature code which can be forced. "
52 "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enabled/"
53 " will assign the group Enabled to field trial WebRTC-FooFeature. Multiple "
54 "trials are separated by \"/\"");
Mirko Bonadei4b091f42019-07-16 11:55:08 +020055ABSL_FLAG(std::string,
56 wav_filename,
57 "",
58 "Path to wav file used for simulation of jitter buffer");
terelius54ce6802016-07-13 06:44:41 -070059
Mirko Bonadei4b091f42019-07-16 11:55:08 +020060ABSL_FLAG(bool,
61 show_detector_state,
62 false,
63 "Show the state of the delay based BWE detector on the total "
64 "bitrate graph");
terelius2ee076d2017-08-15 02:04:02 -070065
Mirko Bonadei4b091f42019-07-16 11:55:08 +020066ABSL_FLAG(bool,
67 show_alr_state,
68 false,
69 "Show the state ALR state on the total bitrate graph");
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +010070
Mirko Bonadei4b091f42019-07-16 11:55:08 +020071ABSL_FLAG(bool,
72 parse_unconfigured_header_extensions,
73 true,
74 "Attempt to parse unconfigured header extensions using the default "
75 "WebRTC mapping. This can give very misleading results if the "
76 "application negotiates a different mapping.");
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020077
Mirko Bonadei4b091f42019-07-16 11:55:08 +020078ABSL_FLAG(bool,
79 print_triage_alerts,
Bjorn Tereliusadef7982020-05-19 13:12:01 +020080 true,
Mirko Bonadei4b091f42019-07-16 11:55:08 +020081 "Print triage alerts, i.e. a list of potential problems.");
Bjorn Terelius2eb31882017-11-30 15:15:25 +010082
Mirko Bonadei4b091f42019-07-16 11:55:08 +020083ABSL_FLAG(bool,
84 normalize_time,
85 true,
86 "Normalize the log timestamps so that the call starts at time 0.");
Stefan Holmer1d4a2272018-05-24 13:48:09 +020087
Mirko Bonadei4b091f42019-07-16 11:55:08 +020088ABSL_FLAG(bool,
89 shared_xaxis,
90 false,
91 "Share x-axis between all plots so that zooming in one plot "
92 "updates all the others too. A downside is that certain "
93 "operations like panning become much slower.");
Bjorn Tereliusff8cce32019-04-11 18:34:01 +020094
Mirko Bonadei4b091f42019-07-16 11:55:08 +020095ABSL_FLAG(bool,
96 protobuf_output,
97 false,
98 "Output charts as protobuf instead of python code.");
Bjorn Tereliusef73f592018-09-10 20:11:49 +020099
Mirko Bonadeif2d97b82019-07-24 15:29:47 +0200100ABSL_FLAG(bool,
101 list_plots,
102 false,
103 "List of registered plots (for use with the --plot flag)");
104
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200105using webrtc::Plot;
106
107namespace {
108std::vector<std::string> StrSplit(const std::string& s,
109 const std::string& delimiter) {
110 std::vector<std::string> v;
111 size_t pos = 0;
112 while (pos < s.length()) {
113 const std::string token = s.substr(pos, s.find(delimiter, pos) - pos);
114 pos += token.length() + delimiter.length();
115 v.push_back(token);
116 }
117 return v;
118}
119
120struct PlotDeclaration {
121 PlotDeclaration(const std::string& label, std::function<void(Plot*)> f)
122 : label(label), enabled(false), plot_func(f) {}
123 const std::string label;
124 bool enabled;
125 // TODO(terelius): Add a help text/explanation.
126 const std::function<void(Plot*)> plot_func;
127};
128
129class PlotMap {
130 public:
131 void RegisterPlot(const std::string& label, std::function<void(Plot*)> f) {
132 for (const auto& plot : plots_) {
133 RTC_DCHECK(plot.label != label)
134 << "Can't use the same label for multiple plots";
135 }
136 plots_.push_back({label, f});
137 }
138
139 bool EnablePlotsByFlags(
140 const std::vector<std::string>& flags,
141 const std::map<std::string, std::vector<std::string>>& flag_aliases) {
142 bool status = true;
143 for (const std::string& flag : flags) {
144 auto alias_it = flag_aliases.find(flag);
145 if (alias_it != flag_aliases.end()) {
146 const auto& replacements = alias_it->second;
147 for (const auto& replacement : replacements) {
148 status &= EnablePlotByFlag(replacement);
149 }
150 } else {
151 status &= EnablePlotByFlag(flag);
152 }
153 }
154 return status;
155 }
156
157 void EnableAllPlots() {
158 for (auto& plot : plots_) {
159 plot.enabled = true;
160 }
161 }
162
163 std::vector<PlotDeclaration>::iterator begin() { return plots_.begin(); }
164 std::vector<PlotDeclaration>::iterator end() { return plots_.end(); }
165
166 private:
167 bool EnablePlotByFlag(const std::string& flag) {
168 for (auto& plot : plots_) {
169 if (plot.label == flag) {
170 plot.enabled = true;
171 return true;
172 }
173 }
174 if (flag == "simulated_neteq_jitter_buffer_delay") {
175 // This flag is handled separately.
176 return true;
177 }
178 std::cerr << "Unrecognized plot name \'" << flag << "\'. Aborting."
179 << std::endl;
180 return false;
181 }
182
183 std::vector<PlotDeclaration> plots_;
184};
Mirko Bonadeif2d97b82019-07-24 15:29:47 +0200185
186bool ContainsHelppackageFlags(absl::string_view filename) {
187 return absl::EndsWith(filename, "main.cc");
188}
189
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200190} // namespace
terelius2ee076d2017-08-15 02:04:02 -0700191
terelius54ce6802016-07-13 06:44:41 -0700192int main(int argc, char* argv[]) {
Mirko Bonadeif2d97b82019-07-24 15:29:47 +0200193 absl::SetProgramUsageMessage(
terelius54ce6802016-07-13 06:44:41 -0700194 "A tool for visualizing WebRTC event logs.\n"
Mirko Bonadeif2d97b82019-07-24 15:29:47 +0200195 "Example usage:\n"
196 "./event_log_visualizer <logfile> | python\n");
Bjorn Terelius48b82792020-05-19 10:57:24 +0200197 absl::FlagsUsageConfig flag_config;
198 flag_config.contains_help_flags = &ContainsHelppackageFlags;
199 absl::SetFlagsUsageConfig(flag_config);
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200200 std::vector<char*> args = absl::ParseCommandLine(argc, argv);
201
Björn Tereliusa06048a2019-11-01 14:31:46 +0100202 // Print RTC_LOG warnings and errors even in release builds.
203 if (rtc::LogMessage::GetLogToDebug() > rtc::LS_WARNING) {
204 rtc::LogMessage::LogToDebug(rtc::LS_WARNING);
205 }
206 rtc::LogMessage::SetLogToStderr(true);
207
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200208 // Flag replacements
209 std::map<std::string, std::vector<std::string>> flag_aliases = {
210 {"default",
211 {"incoming_delay", "incoming_loss_rate", "incoming_bitrate",
Bjorn Terelius873a7a92019-06-13 16:01:17 +0200212 "outgoing_bitrate", "incoming_stream_bitrate",
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200213 "outgoing_stream_bitrate", "network_delay_feedback",
214 "fraction_loss_feedback"}},
215 {"sendside_bwe",
216 {"outgoing_packet_sizes", "outgoing_bitrate", "outgoing_stream_bitrate",
217 "simulated_sendside_bwe", "network_delay_feedback",
218 "fraction_loss_feedback"}},
219 {"receiveside_bwe",
220 {"incoming_packet_sizes", "incoming_delay", "incoming_loss_rate",
Bjorn Terelius873a7a92019-06-13 16:01:17 +0200221 "incoming_bitrate", "incoming_stream_bitrate",
222 "simulated_receiveside_bwe"}},
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200223 {"rtcp_details",
224 {"incoming_rtcp_fraction_lost", "outgoing_rtcp_fraction_lost",
Bjorn Terelius873a7a92019-06-13 16:01:17 +0200225 "incoming_rtcp_cumulative_lost", "outgoing_rtcp_cumulative_lost",
226 "incoming_rtcp_highest_seq_number", "outgoing_rtcp_highest_seq_number",
227 "incoming_rtcp_delay_since_last_sr",
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200228 "outgoing_rtcp_delay_since_last_sr"}},
229 {"simulated_neteq_stats",
230 {"simulated_neteq_jitter_buffer_delay",
Bjorn Terelius873a7a92019-06-13 16:01:17 +0200231 "simulated_neteq_preferred_buffer_size",
Jakob Ivarssonddd41912020-11-03 13:28:52 +0100232 "simulated_neteq_concealment_events", "simulated_neteq_preemptive_rate",
Bjorn Terelius873a7a92019-06-13 16:01:17 +0200233 "simulated_neteq_accelerate_rate", "simulated_neteq_speech_expand_rate",
234 "simulated_neteq_expand_rate"}}};
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200235
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200236 std::vector<std::string> plot_flags =
237 StrSplit(absl::GetFlag(FLAGS_plot), ",");
kjellander4fa5be42017-05-16 00:01:23 -0700238
Bjorn Tereliusedab3012018-01-31 17:23:40 +0100239 // InitFieldTrialsFromString stores the char*, so the char array must outlive
240 // the application.
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200241 const std::string field_trials = absl::GetFlag(FLAGS_force_fieldtrials);
242 webrtc::field_trial::InitFieldTrialsFromString(field_trials.c_str());
stefan985d2802016-11-15 06:54:09 -0800243
Sebastian Janssonb290a6d2019-01-03 14:46:23 +0100244 webrtc::ParsedRtcEventLog::UnconfiguredHeaderExtensions header_extensions =
245 webrtc::ParsedRtcEventLog::UnconfiguredHeaderExtensions::kDontParse;
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200246 if (absl::GetFlag(FLAGS_parse_unconfigured_header_extensions)) {
Sebastian Janssonb290a6d2019-01-03 14:46:23 +0100247 header_extensions = webrtc::ParsedRtcEventLog::
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +0200248 UnconfiguredHeaderExtensions::kAttemptWebrtcDefaultConfig;
249 }
Björn Tereliusa06048a2019-11-01 14:31:46 +0100250 webrtc::ParsedRtcEventLog parsed_log(header_extensions,
251 /*allow_incomplete_logs*/ true);
terelius54ce6802016-07-13 06:44:41 -0700252
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200253 if (args.size() == 2) {
254 std::string filename = args[1];
Björn Tereliusa06048a2019-11-01 14:31:46 +0100255 auto status = parsed_log.ParseFile(filename);
256 if (!status.ok()) {
257 std::cerr << "Failed to parse " << filename << ": " << status.message()
258 << std::endl;
259 return -1;
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200260 }
terelius54ce6802016-07-13 06:44:41 -0700261 }
262
Bjorn Terelius48b82792020-05-19 10:57:24 +0200263 webrtc::AnalyzerConfig config;
Björn Tereliuscb241582022-02-25 08:22:38 +0000264 config.window_duration_ = webrtc::TimeDelta::Millis(250);
265 config.step_ = webrtc::TimeDelta::Millis(10);
266 if (!parsed_log.start_log_events().empty()) {
267 config.rtc_to_utc_offset_ = parsed_log.start_log_events()[0].utc_time() -
268 parsed_log.start_log_events()[0].log_time();
269 }
Bjorn Terelius48b82792020-05-19 10:57:24 +0200270 config.normalize_time_ = absl::GetFlag(FLAGS_normalize_time);
271 config.begin_time_ = parsed_log.first_timestamp();
272 config.end_time_ = parsed_log.last_timestamp();
273 if (config.end_time_ < config.begin_time_) {
274 RTC_LOG(LS_WARNING) << "Log end time " << config.end_time_
275 << " not after begin time " << config.begin_time_
276 << ". Nothing to analyze. Is the log broken?";
277 return -1;
278 }
279
280 webrtc::EventLogAnalyzer analyzer(parsed_log, config);
Bjorn Terelius8a89b5b2020-06-09 17:17:21 +0200281 webrtc::PlotCollection collection;
Björn Tereliuscb241582022-02-25 08:22:38 +0000282 collection.SetCallTimeToUtcOffsetMs(config.CallTimeToUtcOffsetMs());
terelius54ce6802016-07-13 06:44:41 -0700283
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200284 PlotMap plots;
285 plots.RegisterPlot("incoming_packet_sizes", [&](Plot* plot) {
286 analyzer.CreatePacketGraph(webrtc::kIncomingPacket, plot);
287 });
288
289 plots.RegisterPlot("outgoing_packet_sizes", [&](Plot* plot) {
290 analyzer.CreatePacketGraph(webrtc::kOutgoingPacket, plot);
291 });
292 plots.RegisterPlot("incoming_rtcp_types", [&](Plot* plot) {
293 analyzer.CreateRtcpTypeGraph(webrtc::kIncomingPacket, plot);
294 });
295 plots.RegisterPlot("outgoing_rtcp_types", [&](Plot* plot) {
296 analyzer.CreateRtcpTypeGraph(webrtc::kOutgoingPacket, plot);
297 });
298 plots.RegisterPlot("incoming_packet_count", [&](Plot* plot) {
299 analyzer.CreateAccumulatedPacketsGraph(webrtc::kIncomingPacket, plot);
300 });
301 plots.RegisterPlot("outgoing_packet_count", [&](Plot* plot) {
302 analyzer.CreateAccumulatedPacketsGraph(webrtc::kOutgoingPacket, plot);
303 });
Kristoffer Erlandsson283c1062020-03-30 13:01:37 +0200304 plots.RegisterPlot("incoming_packet_rate", [&](Plot* plot) {
305 analyzer.CreatePacketRateGraph(webrtc::kIncomingPacket, plot);
306 });
307 plots.RegisterPlot("outgoing_packet_rate", [&](Plot* plot) {
308 analyzer.CreatePacketRateGraph(webrtc::kOutgoingPacket, plot);
309 });
Kristoffer Erlandssona2ce4232020-04-01 14:33:30 +0200310 plots.RegisterPlot("total_incoming_packet_rate", [&](Plot* plot) {
311 analyzer.CreateTotalPacketRateGraph(webrtc::kIncomingPacket, plot);
312 });
313 plots.RegisterPlot("total_outgoing_packet_rate", [&](Plot* plot) {
314 analyzer.CreateTotalPacketRateGraph(webrtc::kOutgoingPacket, plot);
315 });
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200316 plots.RegisterPlot("audio_playout",
317 [&](Plot* plot) { analyzer.CreatePlayoutGraph(plot); });
318 plots.RegisterPlot("incoming_audio_level", [&](Plot* plot) {
319 analyzer.CreateAudioLevelGraph(webrtc::kIncomingPacket, plot);
320 });
321 plots.RegisterPlot("outgoing_audio_level", [&](Plot* plot) {
322 analyzer.CreateAudioLevelGraph(webrtc::kOutgoingPacket, plot);
323 });
324 plots.RegisterPlot("incoming_sequence_number_delta", [&](Plot* plot) {
325 analyzer.CreateSequenceNumberGraph(plot);
326 });
327 plots.RegisterPlot("incoming_delay", [&](Plot* plot) {
328 analyzer.CreateIncomingDelayGraph(plot);
329 });
330 plots.RegisterPlot("incoming_loss_rate", [&](Plot* plot) {
331 analyzer.CreateIncomingPacketLossGraph(plot);
332 });
333 plots.RegisterPlot("incoming_bitrate", [&](Plot* plot) {
334 analyzer.CreateTotalIncomingBitrateGraph(plot);
335 });
336 plots.RegisterPlot("outgoing_bitrate", [&](Plot* plot) {
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200337 analyzer.CreateTotalOutgoingBitrateGraph(
338 plot, absl::GetFlag(FLAGS_show_detector_state),
339 absl::GetFlag(FLAGS_show_alr_state));
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200340 });
341 plots.RegisterPlot("incoming_stream_bitrate", [&](Plot* plot) {
342 analyzer.CreateStreamBitrateGraph(webrtc::kIncomingPacket, plot);
343 });
344 plots.RegisterPlot("outgoing_stream_bitrate", [&](Plot* plot) {
345 analyzer.CreateStreamBitrateGraph(webrtc::kOutgoingPacket, plot);
346 });
347 plots.RegisterPlot("incoming_layer_bitrate_allocation", [&](Plot* plot) {
348 analyzer.CreateBitrateAllocationGraph(webrtc::kIncomingPacket, plot);
349 });
350 plots.RegisterPlot("outgoing_layer_bitrate_allocation", [&](Plot* plot) {
351 analyzer.CreateBitrateAllocationGraph(webrtc::kOutgoingPacket, plot);
352 });
353 plots.RegisterPlot("simulated_receiveside_bwe", [&](Plot* plot) {
354 analyzer.CreateReceiveSideBweSimulationGraph(plot);
355 });
356 plots.RegisterPlot("simulated_sendside_bwe", [&](Plot* plot) {
357 analyzer.CreateSendSideBweSimulationGraph(plot);
358 });
359 plots.RegisterPlot("simulated_goog_cc", [&](Plot* plot) {
360 analyzer.CreateGoogCcSimulationGraph(plot);
361 });
362 plots.RegisterPlot("network_delay_feedback", [&](Plot* plot) {
363 analyzer.CreateNetworkDelayFeedbackGraph(plot);
364 });
365 plots.RegisterPlot("fraction_loss_feedback", [&](Plot* plot) {
366 analyzer.CreateFractionLossGraph(plot);
367 });
368 plots.RegisterPlot("incoming_timestamps", [&](Plot* plot) {
369 analyzer.CreateTimestampGraph(webrtc::kIncomingPacket, plot);
370 });
371 plots.RegisterPlot("outgoing_timestamps", [&](Plot* plot) {
372 analyzer.CreateTimestampGraph(webrtc::kOutgoingPacket, plot);
373 });
374
375 auto GetFractionLost = [](const webrtc::rtcp::ReportBlock& block) -> float {
376 return static_cast<double>(block.fraction_lost()) / 256 * 100;
377 };
378 plots.RegisterPlot("incoming_rtcp_fraction_lost", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200379 analyzer.CreateSenderAndReceiverReportPlot(
380 webrtc::kIncomingPacket, GetFractionLost,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200381 "Fraction lost (incoming RTCP)", "Loss rate (percent)", plot);
382 });
383 plots.RegisterPlot("outgoing_rtcp_fraction_lost", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200384 analyzer.CreateSenderAndReceiverReportPlot(
385 webrtc::kOutgoingPacket, GetFractionLost,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200386 "Fraction lost (outgoing RTCP)", "Loss rate (percent)", plot);
387 });
388 auto GetCumulativeLost = [](const webrtc::rtcp::ReportBlock& block) -> float {
389 return block.cumulative_lost_signed();
390 };
391 plots.RegisterPlot("incoming_rtcp_cumulative_lost", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200392 analyzer.CreateSenderAndReceiverReportPlot(
393 webrtc::kIncomingPacket, GetCumulativeLost,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200394 "Cumulative lost packets (incoming RTCP)", "Packets", plot);
395 });
396 plots.RegisterPlot("outgoing_rtcp_cumulative_lost", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200397 analyzer.CreateSenderAndReceiverReportPlot(
398 webrtc::kOutgoingPacket, GetCumulativeLost,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200399 "Cumulative lost packets (outgoing RTCP)", "Packets", plot);
400 });
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200401
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200402 auto GetHighestSeqNumber =
403 [](const webrtc::rtcp::ReportBlock& block) -> float {
404 return block.extended_high_seq_num();
405 };
406 plots.RegisterPlot("incoming_rtcp_highest_seq_number", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200407 analyzer.CreateSenderAndReceiverReportPlot(
408 webrtc::kIncomingPacket, GetHighestSeqNumber,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200409 "Highest sequence number (incoming RTCP)", "Sequence number", plot);
410 });
411 plots.RegisterPlot("outgoing_rtcp_highest_seq_number", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200412 analyzer.CreateSenderAndReceiverReportPlot(
413 webrtc::kOutgoingPacket, GetHighestSeqNumber,
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200414 "Highest sequence number (outgoing RTCP)", "Sequence number", plot);
415 });
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200416
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200417 auto DelaySinceLastSr = [](const webrtc::rtcp::ReportBlock& block) -> float {
418 return static_cast<double>(block.delay_since_last_sr()) / 65536;
419 };
420 plots.RegisterPlot("incoming_rtcp_delay_since_last_sr", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200421 analyzer.CreateSenderAndReceiverReportPlot(
422 webrtc::kIncomingPacket, DelaySinceLastSr,
423 "Delay since last received sender report (incoming RTCP)", "Time (s)",
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200424 plot);
425 });
426 plots.RegisterPlot("outgoing_rtcp_delay_since_last_sr", [&](Plot* plot) {
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200427 analyzer.CreateSenderAndReceiverReportPlot(
428 webrtc::kOutgoingPacket, DelaySinceLastSr,
429 "Delay since last received sender report (outgoing RTCP)", "Time (s)",
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200430 plot);
431 });
Bjorn Tereliusb1222c22018-07-24 13:45:31 +0200432
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200433 plots.RegisterPlot("pacer_delay",
434 [&](Plot* plot) { analyzer.CreatePacerDelayGraph(plot); });
435 plots.RegisterPlot("audio_encoder_bitrate", [&](Plot* plot) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200436 CreateAudioEncoderTargetBitrateGraph(parsed_log, config, plot);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200437 });
438 plots.RegisterPlot("audio_encoder_frame_length", [&](Plot* plot) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200439 CreateAudioEncoderFrameLengthGraph(parsed_log, config, plot);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200440 });
441 plots.RegisterPlot("audio_encoder_packet_loss", [&](Plot* plot) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200442 CreateAudioEncoderPacketLossGraph(parsed_log, config, plot);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200443 });
444 plots.RegisterPlot("audio_encoder_fec", [&](Plot* plot) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200445 CreateAudioEncoderEnableFecGraph(parsed_log, config, plot);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200446 });
447 plots.RegisterPlot("audio_encoder_dtx", [&](Plot* plot) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200448 CreateAudioEncoderEnableDtxGraph(parsed_log, config, plot);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200449 });
450 plots.RegisterPlot("audio_encoder_num_channels", [&](Plot* plot) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200451 CreateAudioEncoderNumChannelsGraph(parsed_log, config, plot);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200452 });
453
454 plots.RegisterPlot("ice_candidate_pair_config", [&](Plot* plot) {
455 analyzer.CreateIceCandidatePairConfigGraph(plot);
456 });
457 plots.RegisterPlot("ice_connectivity_check", [&](Plot* plot) {
458 analyzer.CreateIceConnectivityCheckGraph(plot);
459 });
460 plots.RegisterPlot("dtls_transport_state", [&](Plot* plot) {
461 analyzer.CreateDtlsTransportStateGraph(plot);
462 });
463 plots.RegisterPlot("dtls_writable_state", [&](Plot* plot) {
464 analyzer.CreateDtlsWritableStateGraph(plot);
465 });
466
467 std::string wav_path;
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200468 if (!absl::GetFlag(FLAGS_wav_filename).empty()) {
469 wav_path = absl::GetFlag(FLAGS_wav_filename);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200470 } else {
471 wav_path = webrtc::test::ResourcePath(
472 "audio_processing/conversational_speech/EN_script2_F_sp2_B1", "wav");
Bjorn Terelius0295a962017-10-25 17:42:41 +0200473 }
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200474 absl::optional<webrtc::NetEqStatsGetterMap> neteq_stats;
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200475
476 plots.RegisterPlot("simulated_neteq_expand_rate", [&](Plot* plot) {
477 if (!neteq_stats) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200478 neteq_stats = webrtc::SimulateNetEq(parsed_log, config, wav_path, 48000);
Minyue Li45fc6df2018-06-21 11:47:14 +0200479 }
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200480 webrtc::CreateNetEqNetworkStatsGraph(
481 parsed_log, config, *neteq_stats,
Minyue Li27e2b7d2018-05-07 15:20:24 +0200482 [](const webrtc::NetEqNetworkStatistics& stats) {
483 return stats.expand_rate / 16384.f;
484 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200485 "Expand rate", plot);
486 });
487
488 plots.RegisterPlot("simulated_neteq_speech_expand_rate", [&](Plot* plot) {
489 if (!neteq_stats) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200490 neteq_stats = webrtc::SimulateNetEq(parsed_log, config, wav_path, 48000);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200491 }
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200492 webrtc::CreateNetEqNetworkStatsGraph(
493 parsed_log, config, *neteq_stats,
Minyue Li27e2b7d2018-05-07 15:20:24 +0200494 [](const webrtc::NetEqNetworkStatistics& stats) {
495 return stats.speech_expand_rate / 16384.f;
496 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200497 "Speech expand rate", plot);
498 });
499
500 plots.RegisterPlot("simulated_neteq_accelerate_rate", [&](Plot* plot) {
501 if (!neteq_stats) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200502 neteq_stats = webrtc::SimulateNetEq(parsed_log, config, wav_path, 48000);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200503 }
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200504 webrtc::CreateNetEqNetworkStatsGraph(
505 parsed_log, config, *neteq_stats,
Minyue Li27e2b7d2018-05-07 15:20:24 +0200506 [](const webrtc::NetEqNetworkStatistics& stats) {
507 return stats.accelerate_rate / 16384.f;
508 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200509 "Accelerate rate", plot);
510 });
511
512 plots.RegisterPlot("simulated_neteq_preemptive_rate", [&](Plot* plot) {
513 if (!neteq_stats) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200514 neteq_stats = webrtc::SimulateNetEq(parsed_log, config, wav_path, 48000);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200515 }
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200516 webrtc::CreateNetEqNetworkStatsGraph(
517 parsed_log, config, *neteq_stats,
Minyue Li27e2b7d2018-05-07 15:20:24 +0200518 [](const webrtc::NetEqNetworkStatistics& stats) {
Jakob Ivarsson21f6fd72019-04-04 10:15:02 +0200519 return stats.preemptive_rate / 16384.f;
520 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200521 "Preemptive rate", plot);
522 });
523
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200524 plots.RegisterPlot("simulated_neteq_concealment_events", [&](Plot* plot) {
525 if (!neteq_stats) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200526 neteq_stats = webrtc::SimulateNetEq(parsed_log, config, wav_path, 48000);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200527 }
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200528 webrtc::CreateNetEqLifetimeStatsGraph(
529 parsed_log, config, *neteq_stats,
Minyue Lic9ac93f2018-06-26 13:01:32 +0200530 [](const webrtc::NetEqLifetimeStatistics& stats) {
531 return static_cast<float>(stats.concealment_events);
532 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200533 "Concealment events", plot);
534 });
535
536 plots.RegisterPlot("simulated_neteq_preferred_buffer_size", [&](Plot* plot) {
537 if (!neteq_stats) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200538 neteq_stats = webrtc::SimulateNetEq(parsed_log, config, wav_path, 48000);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200539 }
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200540 webrtc::CreateNetEqNetworkStatsGraph(
541 parsed_log, config, *neteq_stats,
Jakob Ivarsson21f6fd72019-04-04 10:15:02 +0200542 [](const webrtc::NetEqNetworkStatistics& stats) {
543 return stats.preferred_buffer_size_ms;
544 },
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200545 "Preferred buffer size (ms)", plot);
546 });
547
548 if (absl::c_find(plot_flags, "all") != plot_flags.end()) {
549 plots.EnableAllPlots();
550 // Treated separately since it isn't registered like the other plots.
551 plot_flags.push_back("simulated_neteq_jitter_buffer_delay");
552 } else {
553 bool success = plots.EnablePlotsByFlags(plot_flags, flag_aliases);
554 if (!success) {
555 return 1;
556 }
henrik.lundin3c938fc2017-06-14 06:09:58 -0700557 }
558
Mirko Bonadeif2d97b82019-07-24 15:29:47 +0200559 if (absl::GetFlag(FLAGS_list_plots)) {
560 std::cerr << "List of registered plots (for use with the --plot flag):"
561 << std::endl;
562 for (const auto& plot : plots) {
563 // TODO(terelius): Also print a help text.
564 std::cerr << " " << plot.label << std::endl;
565 }
566 // The following flag doesn't fit the model used for the other plots.
567 std::cerr << "simulated_neteq_jitter_buffer_delay" << std::endl;
568 std::cerr << "List of plot aliases (for use with the --plot flag):"
569 << std::endl;
570 std::cerr << " all = every registered plot" << std::endl;
571 for (const auto& alias : flag_aliases) {
572 std::cerr << " " << alias.first << " = ";
573 for (const auto& replacement : alias.second) {
574 std::cerr << replacement << ",";
575 }
576 std::cerr << std::endl;
577 }
578 return 0;
579 }
580 if (args.size() != 2) {
581 // Print usage information.
582 std::cerr << absl::ProgramUsageMessage();
583 return 1;
584 }
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800585
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200586 for (const auto& plot : plots) {
587 if (plot.enabled) {
Bjorn Terelius8a89b5b2020-06-09 17:17:21 +0200588 Plot* output = collection.AppendNewPlot();
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200589 plot.plot_func(output);
590 output->SetId(plot.label);
591 }
Zach Stein10a58012018-12-07 12:26:28 -0800592 }
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200593
594 // The model we use for registering plots assumes that the each plot label
595 // can be mapped to a lambda that will produce exactly one plot. The
596 // simulated_neteq_jitter_buffer_delay plot doesn't fit this model since it
597 // creates multiple plots, and would need some state kept between the lambda
598 // calls.
599 if (absl::c_find(plot_flags, "simulated_neteq_jitter_buffer_delay") !=
600 plot_flags.end()) {
601 if (!neteq_stats) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200602 neteq_stats = webrtc::SimulateNetEq(parsed_log, config, wav_path, 48000);
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200603 }
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200604 for (webrtc::NetEqStatsGetterMap::const_iterator it = neteq_stats->cbegin();
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200605 it != neteq_stats->cend(); ++it) {
Bjorn Tereliusc186e142020-06-05 10:47:19 +0200606 webrtc::CreateAudioJitterBufferGraph(parsed_log, config, it->first,
607 it->second.get(),
Bjorn Terelius8a89b5b2020-06-09 17:17:21 +0200608 collection.AppendNewPlot());
Bjorn Terelius1aa9ee92019-06-11 17:39:38 +0200609 }
Zach Stein10a58012018-12-07 12:26:28 -0800610 }
611
Bjorn Terelius8a89b5b2020-06-09 17:17:21 +0200612 if (absl::GetFlag(FLAGS_protobuf_output)) {
613 webrtc::analytics::ChartCollection proto_charts;
614 collection.ExportProtobuf(&proto_charts);
615 std::cout << proto_charts.SerializeAsString();
616 } else {
617 collection.PrintPythonCode(absl::GetFlag(FLAGS_shared_xaxis));
618 }
terelius54ce6802016-07-13 06:44:41 -0700619
Mirko Bonadei4b091f42019-07-16 11:55:08 +0200620 if (absl::GetFlag(FLAGS_print_triage_alerts)) {
Bjorn Terelius48b82792020-05-19 10:57:24 +0200621 webrtc::TriageHelper triage_alerts(config);
622 triage_alerts.AnalyzeLog(parsed_log);
623 triage_alerts.Print(stderr);
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100624 }
625
terelius54ce6802016-07-13 06:44:41 -0700626 return 0;
627}