blob: b38f1a4fcf4e62a07146fe72fcc839838d92ff1e [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
11#include <iostream>
12
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "logging/rtc_event_log/rtc_event_log_parser.h"
14#include "rtc_base/flags.h"
15#include "rtc_tools/event_log_visualizer/analyzer.h"
16#include "rtc_tools/event_log_visualizer/plot_base.h"
17#include "rtc_tools/event_log_visualizer/plot_python.h"
18#include "test/field_trial.h"
19#include "test/testsupport/fileutils.h"
terelius54ce6802016-07-13 06:44:41 -070020
terelius2ee076d2017-08-15 02:04:02 -070021DEFINE_string(plot_profile,
22 "default",
23 "A profile that selects a certain subset of the plots. Currently "
Bjorn Terelius1edfff92017-10-11 13:15:19 +020024 "defined profiles are \"all\", \"none\", \"sendside_bwe\","
25 "\"receiveside_bwe\" and \"default\"");
terelius2ee076d2017-08-15 02:04:02 -070026
27DEFINE_bool(plot_incoming_packet_sizes,
terelius54ce6802016-07-13 06:44:41 -070028 false,
terelius2ee076d2017-08-15 02:04:02 -070029 "Plot bar graph showing the size of each incoming packet.");
30DEFINE_bool(plot_outgoing_packet_sizes,
31 false,
32 "Plot bar graph showing the size of each outgoing packet.");
33DEFINE_bool(plot_incoming_packet_count,
34 false,
35 "Plot the accumulated number of packets for each incoming stream.");
36DEFINE_bool(plot_outgoing_packet_count,
37 false,
38 "Plot the accumulated number of packets for each outgoing stream.");
terelius54ce6802016-07-13 06:44:41 -070039DEFINE_bool(plot_audio_playout,
40 false,
41 "Plot bar graph showing the time between each audio playout.");
ivocaac9d6f2016-09-22 07:01:47 -070042DEFINE_bool(plot_audio_level,
43 false,
terelius2ee076d2017-08-15 02:04:02 -070044 "Plot line graph showing the audio level of incoming audio.");
45DEFINE_bool(plot_incoming_sequence_number_delta,
46 false,
47 "Plot the sequence number difference between consecutive incoming "
48 "packets.");
terelius54ce6802016-07-13 06:44:41 -070049DEFINE_bool(
terelius2ee076d2017-08-15 02:04:02 -070050 plot_incoming_delay_delta,
terelius54ce6802016-07-13 06:44:41 -070051 false,
52 "Plot the difference in 1-way path delay between consecutive packets.");
terelius2ee076d2017-08-15 02:04:02 -070053DEFINE_bool(plot_incoming_delay,
54 true,
55 "Plot the 1-way path delay for incoming packets, normalized so "
56 "that the first packet has delay 0.");
57DEFINE_bool(plot_incoming_loss_rate,
58 true,
59 "Compute the loss rate for incoming packets using a method that's "
60 "similar to the one used for RTCP SR and RR fraction lost. Note "
61 "that the loss rate can be negative if packets are duplicated or "
62 "reordered.");
63DEFINE_bool(plot_incoming_bitrate,
64 true,
65 "Plot the total bitrate used by all incoming streams.");
66DEFINE_bool(plot_outgoing_bitrate,
67 true,
68 "Plot the total bitrate used by all outgoing streams.");
69DEFINE_bool(plot_incoming_stream_bitrate,
70 true,
71 "Plot the bitrate used by each incoming stream.");
72DEFINE_bool(plot_outgoing_stream_bitrate,
73 true,
74 "Plot the bitrate used by each outgoing stream.");
Bjorn Terelius28db2662017-10-04 14:22:43 +020075DEFINE_bool(plot_simulated_receiveside_bwe,
76 false,
77 "Run the receive-side bandwidth estimator with the incoming rtp "
78 "packets and plot the resulting estimate.");
terelius2ee076d2017-08-15 02:04:02 -070079DEFINE_bool(plot_simulated_sendside_bwe,
terelius54ce6802016-07-13 06:44:41 -070080 false,
terelius2ee076d2017-08-15 02:04:02 -070081 "Run the send-side bandwidth estimator with the outgoing rtp and "
82 "incoming rtcp and plot the resulting estimate.");
stefanc3de0332016-08-02 07:22:17 -070083DEFINE_bool(plot_network_delay_feedback,
terelius2ee076d2017-08-15 02:04:02 -070084 true,
stefanc3de0332016-08-02 07:22:17 -070085 "Compute network delay based on sent packets and the received "
86 "transport feedback.");
terelius2ee076d2017-08-15 02:04:02 -070087DEFINE_bool(plot_fraction_loss_feedback,
88 true,
tereliusf736d232016-08-04 10:00:11 -070089 "Plot packet loss in percent for outgoing packets (as perceived by "
90 "the send-side bandwidth estimator).");
Bjorn Terelius0295a962017-10-25 17:42:41 +020091DEFINE_bool(plot_pacer_delay,
92 false,
93 "Plot the time each sent packet has spent in the pacer (based on "
94 "the difference between the RTP timestamp and the send "
95 "timestamp).");
stefane372d3c2017-02-02 08:04:18 -080096DEFINE_bool(plot_timestamps,
97 false,
98 "Plot the rtp timestamps of all rtp and rtcp packets over time.");
terelius2ee076d2017-08-15 02:04:02 -070099DEFINE_bool(plot_audio_encoder_bitrate_bps,
michaelt6e5b2192017-02-22 07:33:27 -0800100 false,
101 "Plot the audio encoder target bitrate.");
terelius2ee076d2017-08-15 02:04:02 -0700102DEFINE_bool(plot_audio_encoder_frame_length_ms,
michaelt6e5b2192017-02-22 07:33:27 -0800103 false,
104 "Plot the audio encoder frame length.");
105DEFINE_bool(
terelius2ee076d2017-08-15 02:04:02 -0700106 plot_audio_encoder_packet_loss,
michaelt6e5b2192017-02-22 07:33:27 -0800107 false,
terelius2ee076d2017-08-15 02:04:02 -0700108 "Plot the uplink packet loss fraction which is sent to the audio encoder.");
109DEFINE_bool(plot_audio_encoder_fec, false, "Plot the audio encoder FEC.");
110DEFINE_bool(plot_audio_encoder_dtx, false, "Plot the audio encoder DTX.");
111DEFINE_bool(plot_audio_encoder_num_channels,
michaelt6e5b2192017-02-22 07:33:27 -0800112 false,
113 "Plot the audio encoder number of channels.");
henrik.lundin3c938fc2017-06-14 06:09:58 -0700114DEFINE_bool(plot_audio_jitter_buffer,
115 false,
116 "Plot the audio jitter buffer delay profile.");
Bjorn Terelius1edfff92017-10-11 13:15:19 +0200117
stefan985d2802016-11-15 06:54:09 -0800118DEFINE_string(
119 force_fieldtrials,
120 "",
121 "Field trials control experimental feature code which can be forced. "
122 "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enabled/"
123 " will assign the group Enabled to field trial WebRTC-FooFeature. Multiple "
124 "trials are separated by \"/\"");
owb7fbeb0b2017-08-16 02:48:33 -0700125DEFINE_string(wav_filename,
126 "",
127 "Path to wav file used for simulation of jitter buffer");
kjellander4fa5be42017-05-16 00:01:23 -0700128DEFINE_bool(help, false, "prints this message");
terelius54ce6802016-07-13 06:44:41 -0700129
terelius2ee076d2017-08-15 02:04:02 -0700130DEFINE_bool(show_detector_state,
131 false,
132 "Show the state of the delay based BWE detector on the total "
133 "bitrate graph");
134
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +0100135DEFINE_bool(show_alr_state,
136 false,
137 "Show the state ALR state on the total bitrate graph");
138
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100139DEFINE_bool(
140 print_triage_notifications,
141 false,
142 "Print triage notifications, i.e. a list of suspicious looking events.");
143
terelius2ee076d2017-08-15 02:04:02 -0700144void SetAllPlotFlags(bool setting);
145
philipel23c7f252017-07-14 06:30:03 -0700146
terelius54ce6802016-07-13 06:44:41 -0700147int main(int argc, char* argv[]) {
148 std::string program_name = argv[0];
149 std::string usage =
150 "A tool for visualizing WebRTC event logs.\n"
151 "Example usage:\n" +
152 program_name + " <logfile> | python\n" + "Run " + program_name +
153 " --help for a list of command line options\n";
terelius2ee076d2017-08-15 02:04:02 -0700154
155 // Parse command line flags without removing them. We're only interested in
156 // the |plot_profile| flag.
157 rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, false);
158 if (strcmp(FLAG_plot_profile, "all") == 0) {
159 SetAllPlotFlags(true);
160 } else if (strcmp(FLAG_plot_profile, "none") == 0) {
161 SetAllPlotFlags(false);
Bjorn Terelius1edfff92017-10-11 13:15:19 +0200162 } else if (strcmp(FLAG_plot_profile, "sendside_bwe") == 0) {
163 SetAllPlotFlags(false);
164 FLAG_plot_outgoing_packet_sizes = true;
165 FLAG_plot_outgoing_bitrate = true;
166 FLAG_plot_outgoing_stream_bitrate = true;
167 FLAG_plot_simulated_sendside_bwe = true;
168 FLAG_plot_network_delay_feedback = true;
169 FLAG_plot_fraction_loss_feedback = true;
170 } else if (strcmp(FLAG_plot_profile, "receiveside_bwe") == 0) {
171 SetAllPlotFlags(false);
172 FLAG_plot_incoming_packet_sizes = true;
173 FLAG_plot_incoming_delay_delta = true;
174 FLAG_plot_incoming_delay = true;
175 FLAG_plot_incoming_loss_rate = true;
176 FLAG_plot_incoming_bitrate = true;
177 FLAG_plot_incoming_stream_bitrate = true;
178 FLAG_plot_simulated_receiveside_bwe = true;
terelius2ee076d2017-08-15 02:04:02 -0700179 } else if (strcmp(FLAG_plot_profile, "default") == 0) {
180 // Do nothing.
181 } else {
182 rtc::Flag* plot_profile_flag = rtc::FlagList::Lookup("plot_profile");
183 RTC_CHECK(plot_profile_flag);
184 plot_profile_flag->Print(false);
185 }
186 // Parse the remaining flags. They are applied relative to the chosen profile.
kjellander4fa5be42017-05-16 00:01:23 -0700187 rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
terelius2ee076d2017-08-15 02:04:02 -0700188
tereliusc4a5c142017-07-20 08:05:09 -0700189 if (argc != 2 || FLAG_help) {
kjellander4fa5be42017-05-16 00:01:23 -0700190 // Print usage information.
191 std::cout << usage;
tereliusc4a5c142017-07-20 08:05:09 -0700192 if (FLAG_help)
193 rtc::FlagList::Print(nullptr, false);
kjellander4fa5be42017-05-16 00:01:23 -0700194 return 0;
195 }
196
henrik.lundin3c938fc2017-06-14 06:09:58 -0700197 webrtc::test::SetExecutablePath(argv[0]);
kjellander4fa5be42017-05-16 00:01:23 -0700198 webrtc::test::InitFieldTrialsFromString(FLAG_force_fieldtrials);
stefan985d2802016-11-15 06:54:09 -0800199
terelius54ce6802016-07-13 06:44:41 -0700200 std::string filename = argv[1];
201
202 webrtc::ParsedRtcEventLog parsed_log;
203
204 if (!parsed_log.ParseFile(filename)) {
205 std::cerr << "Could not parse the entire log file." << std::endl;
206 std::cerr << "Proceeding to analyze the first "
207 << parsed_log.GetNumberOfEvents() << " events in the file."
208 << std::endl;
209 }
210
211 webrtc::plotting::EventLogAnalyzer analyzer(parsed_log);
212 std::unique_ptr<webrtc::plotting::PlotCollection> collection(
213 new webrtc::plotting::PythonPlotCollection());
214
terelius2ee076d2017-08-15 02:04:02 -0700215 if (FLAG_plot_incoming_packet_sizes) {
216 analyzer.CreatePacketGraph(webrtc::PacketDirection::kIncomingPacket,
217 collection->AppendNewPlot());
terelius54ce6802016-07-13 06:44:41 -0700218 }
terelius2ee076d2017-08-15 02:04:02 -0700219 if (FLAG_plot_outgoing_packet_sizes) {
220 analyzer.CreatePacketGraph(webrtc::PacketDirection::kOutgoingPacket,
221 collection->AppendNewPlot());
222 }
223 if (FLAG_plot_incoming_packet_count) {
224 analyzer.CreateAccumulatedPacketsGraph(
225 webrtc::PacketDirection::kIncomingPacket, collection->AppendNewPlot());
226 }
227 if (FLAG_plot_outgoing_packet_count) {
228 analyzer.CreateAccumulatedPacketsGraph(
229 webrtc::PacketDirection::kOutgoingPacket, collection->AppendNewPlot());
230 }
231 if (FLAG_plot_audio_playout) {
tereliusdc35dcd2016-08-01 12:03:27 -0700232 analyzer.CreatePlayoutGraph(collection->AppendNewPlot());
terelius54ce6802016-07-13 06:44:41 -0700233 }
terelius2ee076d2017-08-15 02:04:02 -0700234 if (FLAG_plot_audio_level) {
ivocaac9d6f2016-09-22 07:01:47 -0700235 analyzer.CreateAudioLevelGraph(collection->AppendNewPlot());
236 }
terelius2ee076d2017-08-15 02:04:02 -0700237 if (FLAG_plot_incoming_sequence_number_delta) {
238 analyzer.CreateSequenceNumberGraph(collection->AppendNewPlot());
terelius54ce6802016-07-13 06:44:41 -0700239 }
terelius2ee076d2017-08-15 02:04:02 -0700240 if (FLAG_plot_incoming_delay_delta) {
241 analyzer.CreateIncomingDelayDeltaGraph(collection->AppendNewPlot());
terelius54ce6802016-07-13 06:44:41 -0700242 }
terelius2ee076d2017-08-15 02:04:02 -0700243 if (FLAG_plot_incoming_delay) {
244 analyzer.CreateIncomingDelayGraph(collection->AppendNewPlot());
terelius54ce6802016-07-13 06:44:41 -0700245 }
terelius2ee076d2017-08-15 02:04:02 -0700246 if (FLAG_plot_incoming_loss_rate) {
Stefan Holmer99f8e082016-09-09 13:37:50 +0200247 analyzer.CreateIncomingPacketLossGraph(collection->AppendNewPlot());
tereliusf736d232016-08-04 10:00:11 -0700248 }
terelius2ee076d2017-08-15 02:04:02 -0700249 if (FLAG_plot_incoming_bitrate) {
250 analyzer.CreateTotalBitrateGraph(webrtc::PacketDirection::kIncomingPacket,
251 collection->AppendNewPlot(),
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +0100252 FLAG_show_detector_state,
253 FLAG_show_alr_state);
terelius54ce6802016-07-13 06:44:41 -0700254 }
terelius2ee076d2017-08-15 02:04:02 -0700255 if (FLAG_plot_outgoing_bitrate) {
256 analyzer.CreateTotalBitrateGraph(webrtc::PacketDirection::kOutgoingPacket,
257 collection->AppendNewPlot(),
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +0100258 FLAG_show_detector_state,
259 FLAG_show_alr_state);
terelius54ce6802016-07-13 06:44:41 -0700260 }
terelius2ee076d2017-08-15 02:04:02 -0700261 if (FLAG_plot_incoming_stream_bitrate) {
262 analyzer.CreateStreamBitrateGraph(webrtc::PacketDirection::kIncomingPacket,
263 collection->AppendNewPlot());
264 }
265 if (FLAG_plot_outgoing_stream_bitrate) {
266 analyzer.CreateStreamBitrateGraph(webrtc::PacketDirection::kOutgoingPacket,
267 collection->AppendNewPlot());
268 }
Bjorn Terelius28db2662017-10-04 14:22:43 +0200269 if (FLAG_plot_simulated_receiveside_bwe) {
270 analyzer.CreateReceiveSideBweSimulationGraph(collection->AppendNewPlot());
271 }
terelius2ee076d2017-08-15 02:04:02 -0700272 if (FLAG_plot_simulated_sendside_bwe) {
Bjorn Terelius28db2662017-10-04 14:22:43 +0200273 analyzer.CreateSendSideBweSimulationGraph(collection->AppendNewPlot());
Stefan Holmer13181032016-07-29 14:48:54 +0200274 }
terelius2ee076d2017-08-15 02:04:02 -0700275 if (FLAG_plot_network_delay_feedback) {
tereliuse34c19c2016-08-15 08:47:14 -0700276 analyzer.CreateNetworkDelayFeedbackGraph(collection->AppendNewPlot());
stefanc3de0332016-08-02 07:22:17 -0700277 }
terelius2ee076d2017-08-15 02:04:02 -0700278 if (FLAG_plot_fraction_loss_feedback) {
279 analyzer.CreateFractionLossGraph(collection->AppendNewPlot());
280 }
281 if (FLAG_plot_timestamps) {
stefane372d3c2017-02-02 08:04:18 -0800282 analyzer.CreateTimestampGraph(collection->AppendNewPlot());
283 }
Bjorn Terelius0295a962017-10-25 17:42:41 +0200284 if (FLAG_plot_pacer_delay) {
285 analyzer.CreatePacerDelayGraph(collection->AppendNewPlot());
286 }
terelius2ee076d2017-08-15 02:04:02 -0700287 if (FLAG_plot_audio_encoder_bitrate_bps) {
michaelt6e5b2192017-02-22 07:33:27 -0800288 analyzer.CreateAudioEncoderTargetBitrateGraph(collection->AppendNewPlot());
289 }
terelius2ee076d2017-08-15 02:04:02 -0700290 if (FLAG_plot_audio_encoder_frame_length_ms) {
michaelt6e5b2192017-02-22 07:33:27 -0800291 analyzer.CreateAudioEncoderFrameLengthGraph(collection->AppendNewPlot());
292 }
terelius2ee076d2017-08-15 02:04:02 -0700293 if (FLAG_plot_audio_encoder_packet_loss) {
294 analyzer.CreateAudioEncoderPacketLossGraph(collection->AppendNewPlot());
michaelt6e5b2192017-02-22 07:33:27 -0800295 }
terelius2ee076d2017-08-15 02:04:02 -0700296 if (FLAG_plot_audio_encoder_fec) {
michaelt6e5b2192017-02-22 07:33:27 -0800297 analyzer.CreateAudioEncoderEnableFecGraph(collection->AppendNewPlot());
298 }
terelius2ee076d2017-08-15 02:04:02 -0700299 if (FLAG_plot_audio_encoder_dtx) {
michaelt6e5b2192017-02-22 07:33:27 -0800300 analyzer.CreateAudioEncoderEnableDtxGraph(collection->AppendNewPlot());
301 }
terelius2ee076d2017-08-15 02:04:02 -0700302 if (FLAG_plot_audio_encoder_num_channels) {
michaelt6e5b2192017-02-22 07:33:27 -0800303 analyzer.CreateAudioEncoderNumChannelsGraph(collection->AppendNewPlot());
304 }
terelius2ee076d2017-08-15 02:04:02 -0700305 if (FLAG_plot_audio_jitter_buffer) {
owb7fbeb0b2017-08-16 02:48:33 -0700306 std::string wav_path;
307 if (FLAG_wav_filename[0] != '\0') {
308 wav_path = FLAG_wav_filename;
309 } else {
310 wav_path = webrtc::test::ResourcePath(
311 "audio_processing/conversational_speech/EN_script2_F_sp2_B1", "wav");
312 }
313 analyzer.CreateAudioJitterBufferGraph(wav_path, 48000,
314 collection->AppendNewPlot());
henrik.lundin3c938fc2017-06-14 06:09:58 -0700315 }
316
tereliusdc35dcd2016-08-01 12:03:27 -0700317 collection->Draw();
terelius54ce6802016-07-13 06:44:41 -0700318
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100319 if (FLAG_print_triage_notifications) {
320 analyzer.CreateTriageNotifications();
321 analyzer.PrintNotifications(stderr);
322 }
323
terelius54ce6802016-07-13 06:44:41 -0700324 return 0;
325}
terelius2ee076d2017-08-15 02:04:02 -0700326
327
328void SetAllPlotFlags(bool setting) {
329 FLAG_plot_incoming_packet_sizes = setting;
330 FLAG_plot_outgoing_packet_sizes = setting;
331 FLAG_plot_incoming_packet_count = setting;
332 FLAG_plot_outgoing_packet_count = setting;
333 FLAG_plot_audio_playout = setting;
334 FLAG_plot_audio_level = setting;
335 FLAG_plot_incoming_sequence_number_delta = setting;
336 FLAG_plot_incoming_delay_delta = setting;
337 FLAG_plot_incoming_delay = setting;
338 FLAG_plot_incoming_loss_rate = setting;
339 FLAG_plot_incoming_bitrate = setting;
340 FLAG_plot_outgoing_bitrate = setting;
341 FLAG_plot_incoming_stream_bitrate = setting;
342 FLAG_plot_outgoing_stream_bitrate = setting;
Bjorn Terelius28db2662017-10-04 14:22:43 +0200343 FLAG_plot_simulated_receiveside_bwe = setting;
terelius2ee076d2017-08-15 02:04:02 -0700344 FLAG_plot_simulated_sendside_bwe = setting;
345 FLAG_plot_network_delay_feedback = setting;
346 FLAG_plot_fraction_loss_feedback = setting;
347 FLAG_plot_timestamps = setting;
348 FLAG_plot_audio_encoder_bitrate_bps = setting;
349 FLAG_plot_audio_encoder_frame_length_ms = setting;
350 FLAG_plot_audio_encoder_packet_loss = setting;
351 FLAG_plot_audio_encoder_fec = setting;
352 FLAG_plot_audio_encoder_dtx = setting;
353 FLAG_plot_audio_encoder_num_channels = setting;
354 FLAG_plot_audio_jitter_buffer = setting;
355}