blob: e028a0f8e1e73eb4d6c2b533269ec884cdf96663 [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
135void SetAllPlotFlags(bool setting);
136
philipel23c7f252017-07-14 06:30:03 -0700137
terelius54ce6802016-07-13 06:44:41 -0700138int main(int argc, char* argv[]) {
139 std::string program_name = argv[0];
140 std::string usage =
141 "A tool for visualizing WebRTC event logs.\n"
142 "Example usage:\n" +
143 program_name + " <logfile> | python\n" + "Run " + program_name +
144 " --help for a list of command line options\n";
terelius2ee076d2017-08-15 02:04:02 -0700145
146 // Parse command line flags without removing them. We're only interested in
147 // the |plot_profile| flag.
148 rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, false);
149 if (strcmp(FLAG_plot_profile, "all") == 0) {
150 SetAllPlotFlags(true);
151 } else if (strcmp(FLAG_plot_profile, "none") == 0) {
152 SetAllPlotFlags(false);
Bjorn Terelius1edfff92017-10-11 13:15:19 +0200153 } else if (strcmp(FLAG_plot_profile, "sendside_bwe") == 0) {
154 SetAllPlotFlags(false);
155 FLAG_plot_outgoing_packet_sizes = true;
156 FLAG_plot_outgoing_bitrate = true;
157 FLAG_plot_outgoing_stream_bitrate = true;
158 FLAG_plot_simulated_sendside_bwe = true;
159 FLAG_plot_network_delay_feedback = true;
160 FLAG_plot_fraction_loss_feedback = true;
161 } else if (strcmp(FLAG_plot_profile, "receiveside_bwe") == 0) {
162 SetAllPlotFlags(false);
163 FLAG_plot_incoming_packet_sizes = true;
164 FLAG_plot_incoming_delay_delta = true;
165 FLAG_plot_incoming_delay = true;
166 FLAG_plot_incoming_loss_rate = true;
167 FLAG_plot_incoming_bitrate = true;
168 FLAG_plot_incoming_stream_bitrate = true;
169 FLAG_plot_simulated_receiveside_bwe = true;
terelius2ee076d2017-08-15 02:04:02 -0700170 } else if (strcmp(FLAG_plot_profile, "default") == 0) {
171 // Do nothing.
172 } else {
173 rtc::Flag* plot_profile_flag = rtc::FlagList::Lookup("plot_profile");
174 RTC_CHECK(plot_profile_flag);
175 plot_profile_flag->Print(false);
176 }
177 // Parse the remaining flags. They are applied relative to the chosen profile.
kjellander4fa5be42017-05-16 00:01:23 -0700178 rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
terelius2ee076d2017-08-15 02:04:02 -0700179
tereliusc4a5c142017-07-20 08:05:09 -0700180 if (argc != 2 || FLAG_help) {
kjellander4fa5be42017-05-16 00:01:23 -0700181 // Print usage information.
182 std::cout << usage;
tereliusc4a5c142017-07-20 08:05:09 -0700183 if (FLAG_help)
184 rtc::FlagList::Print(nullptr, false);
kjellander4fa5be42017-05-16 00:01:23 -0700185 return 0;
186 }
187
henrik.lundin3c938fc2017-06-14 06:09:58 -0700188 webrtc::test::SetExecutablePath(argv[0]);
kjellander4fa5be42017-05-16 00:01:23 -0700189 webrtc::test::InitFieldTrialsFromString(FLAG_force_fieldtrials);
stefan985d2802016-11-15 06:54:09 -0800190
terelius54ce6802016-07-13 06:44:41 -0700191 std::string filename = argv[1];
192
193 webrtc::ParsedRtcEventLog parsed_log;
194
195 if (!parsed_log.ParseFile(filename)) {
196 std::cerr << "Could not parse the entire log file." << std::endl;
197 std::cerr << "Proceeding to analyze the first "
198 << parsed_log.GetNumberOfEvents() << " events in the file."
199 << std::endl;
200 }
201
202 webrtc::plotting::EventLogAnalyzer analyzer(parsed_log);
203 std::unique_ptr<webrtc::plotting::PlotCollection> collection(
204 new webrtc::plotting::PythonPlotCollection());
205
terelius2ee076d2017-08-15 02:04:02 -0700206 if (FLAG_plot_incoming_packet_sizes) {
207 analyzer.CreatePacketGraph(webrtc::PacketDirection::kIncomingPacket,
208 collection->AppendNewPlot());
terelius54ce6802016-07-13 06:44:41 -0700209 }
terelius2ee076d2017-08-15 02:04:02 -0700210 if (FLAG_plot_outgoing_packet_sizes) {
211 analyzer.CreatePacketGraph(webrtc::PacketDirection::kOutgoingPacket,
212 collection->AppendNewPlot());
213 }
214 if (FLAG_plot_incoming_packet_count) {
215 analyzer.CreateAccumulatedPacketsGraph(
216 webrtc::PacketDirection::kIncomingPacket, collection->AppendNewPlot());
217 }
218 if (FLAG_plot_outgoing_packet_count) {
219 analyzer.CreateAccumulatedPacketsGraph(
220 webrtc::PacketDirection::kOutgoingPacket, collection->AppendNewPlot());
221 }
222 if (FLAG_plot_audio_playout) {
tereliusdc35dcd2016-08-01 12:03:27 -0700223 analyzer.CreatePlayoutGraph(collection->AppendNewPlot());
terelius54ce6802016-07-13 06:44:41 -0700224 }
terelius2ee076d2017-08-15 02:04:02 -0700225 if (FLAG_plot_audio_level) {
ivocaac9d6f2016-09-22 07:01:47 -0700226 analyzer.CreateAudioLevelGraph(collection->AppendNewPlot());
227 }
terelius2ee076d2017-08-15 02:04:02 -0700228 if (FLAG_plot_incoming_sequence_number_delta) {
229 analyzer.CreateSequenceNumberGraph(collection->AppendNewPlot());
terelius54ce6802016-07-13 06:44:41 -0700230 }
terelius2ee076d2017-08-15 02:04:02 -0700231 if (FLAG_plot_incoming_delay_delta) {
232 analyzer.CreateIncomingDelayDeltaGraph(collection->AppendNewPlot());
terelius54ce6802016-07-13 06:44:41 -0700233 }
terelius2ee076d2017-08-15 02:04:02 -0700234 if (FLAG_plot_incoming_delay) {
235 analyzer.CreateIncomingDelayGraph(collection->AppendNewPlot());
terelius54ce6802016-07-13 06:44:41 -0700236 }
terelius2ee076d2017-08-15 02:04:02 -0700237 if (FLAG_plot_incoming_loss_rate) {
Stefan Holmer99f8e082016-09-09 13:37:50 +0200238 analyzer.CreateIncomingPacketLossGraph(collection->AppendNewPlot());
tereliusf736d232016-08-04 10:00:11 -0700239 }
terelius2ee076d2017-08-15 02:04:02 -0700240 if (FLAG_plot_incoming_bitrate) {
241 analyzer.CreateTotalBitrateGraph(webrtc::PacketDirection::kIncomingPacket,
242 collection->AppendNewPlot(),
243 FLAG_show_detector_state);
terelius54ce6802016-07-13 06:44:41 -0700244 }
terelius2ee076d2017-08-15 02:04:02 -0700245 if (FLAG_plot_outgoing_bitrate) {
246 analyzer.CreateTotalBitrateGraph(webrtc::PacketDirection::kOutgoingPacket,
247 collection->AppendNewPlot(),
248 FLAG_show_detector_state);
terelius54ce6802016-07-13 06:44:41 -0700249 }
terelius2ee076d2017-08-15 02:04:02 -0700250 if (FLAG_plot_incoming_stream_bitrate) {
251 analyzer.CreateStreamBitrateGraph(webrtc::PacketDirection::kIncomingPacket,
252 collection->AppendNewPlot());
253 }
254 if (FLAG_plot_outgoing_stream_bitrate) {
255 analyzer.CreateStreamBitrateGraph(webrtc::PacketDirection::kOutgoingPacket,
256 collection->AppendNewPlot());
257 }
Bjorn Terelius28db2662017-10-04 14:22:43 +0200258 if (FLAG_plot_simulated_receiveside_bwe) {
259 analyzer.CreateReceiveSideBweSimulationGraph(collection->AppendNewPlot());
260 }
terelius2ee076d2017-08-15 02:04:02 -0700261 if (FLAG_plot_simulated_sendside_bwe) {
Bjorn Terelius28db2662017-10-04 14:22:43 +0200262 analyzer.CreateSendSideBweSimulationGraph(collection->AppendNewPlot());
Stefan Holmer13181032016-07-29 14:48:54 +0200263 }
terelius2ee076d2017-08-15 02:04:02 -0700264 if (FLAG_plot_network_delay_feedback) {
tereliuse34c19c2016-08-15 08:47:14 -0700265 analyzer.CreateNetworkDelayFeedbackGraph(collection->AppendNewPlot());
stefanc3de0332016-08-02 07:22:17 -0700266 }
terelius2ee076d2017-08-15 02:04:02 -0700267 if (FLAG_plot_fraction_loss_feedback) {
268 analyzer.CreateFractionLossGraph(collection->AppendNewPlot());
269 }
270 if (FLAG_plot_timestamps) {
stefane372d3c2017-02-02 08:04:18 -0800271 analyzer.CreateTimestampGraph(collection->AppendNewPlot());
272 }
Bjorn Terelius0295a962017-10-25 17:42:41 +0200273 if (FLAG_plot_pacer_delay) {
274 analyzer.CreatePacerDelayGraph(collection->AppendNewPlot());
275 }
terelius2ee076d2017-08-15 02:04:02 -0700276 if (FLAG_plot_audio_encoder_bitrate_bps) {
michaelt6e5b2192017-02-22 07:33:27 -0800277 analyzer.CreateAudioEncoderTargetBitrateGraph(collection->AppendNewPlot());
278 }
terelius2ee076d2017-08-15 02:04:02 -0700279 if (FLAG_plot_audio_encoder_frame_length_ms) {
michaelt6e5b2192017-02-22 07:33:27 -0800280 analyzer.CreateAudioEncoderFrameLengthGraph(collection->AppendNewPlot());
281 }
terelius2ee076d2017-08-15 02:04:02 -0700282 if (FLAG_plot_audio_encoder_packet_loss) {
283 analyzer.CreateAudioEncoderPacketLossGraph(collection->AppendNewPlot());
michaelt6e5b2192017-02-22 07:33:27 -0800284 }
terelius2ee076d2017-08-15 02:04:02 -0700285 if (FLAG_plot_audio_encoder_fec) {
michaelt6e5b2192017-02-22 07:33:27 -0800286 analyzer.CreateAudioEncoderEnableFecGraph(collection->AppendNewPlot());
287 }
terelius2ee076d2017-08-15 02:04:02 -0700288 if (FLAG_plot_audio_encoder_dtx) {
michaelt6e5b2192017-02-22 07:33:27 -0800289 analyzer.CreateAudioEncoderEnableDtxGraph(collection->AppendNewPlot());
290 }
terelius2ee076d2017-08-15 02:04:02 -0700291 if (FLAG_plot_audio_encoder_num_channels) {
michaelt6e5b2192017-02-22 07:33:27 -0800292 analyzer.CreateAudioEncoderNumChannelsGraph(collection->AppendNewPlot());
293 }
terelius2ee076d2017-08-15 02:04:02 -0700294 if (FLAG_plot_audio_jitter_buffer) {
owb7fbeb0b2017-08-16 02:48:33 -0700295 std::string wav_path;
296 if (FLAG_wav_filename[0] != '\0') {
297 wav_path = FLAG_wav_filename;
298 } else {
299 wav_path = webrtc::test::ResourcePath(
300 "audio_processing/conversational_speech/EN_script2_F_sp2_B1", "wav");
301 }
302 analyzer.CreateAudioJitterBufferGraph(wav_path, 48000,
303 collection->AppendNewPlot());
henrik.lundin3c938fc2017-06-14 06:09:58 -0700304 }
305
tereliusdc35dcd2016-08-01 12:03:27 -0700306 collection->Draw();
terelius54ce6802016-07-13 06:44:41 -0700307
308 return 0;
309}
terelius2ee076d2017-08-15 02:04:02 -0700310
311
312void SetAllPlotFlags(bool setting) {
313 FLAG_plot_incoming_packet_sizes = setting;
314 FLAG_plot_outgoing_packet_sizes = setting;
315 FLAG_plot_incoming_packet_count = setting;
316 FLAG_plot_outgoing_packet_count = setting;
317 FLAG_plot_audio_playout = setting;
318 FLAG_plot_audio_level = setting;
319 FLAG_plot_incoming_sequence_number_delta = setting;
320 FLAG_plot_incoming_delay_delta = setting;
321 FLAG_plot_incoming_delay = setting;
322 FLAG_plot_incoming_loss_rate = setting;
323 FLAG_plot_incoming_bitrate = setting;
324 FLAG_plot_outgoing_bitrate = setting;
325 FLAG_plot_incoming_stream_bitrate = setting;
326 FLAG_plot_outgoing_stream_bitrate = setting;
Bjorn Terelius28db2662017-10-04 14:22:43 +0200327 FLAG_plot_simulated_receiveside_bwe = setting;
terelius2ee076d2017-08-15 02:04:02 -0700328 FLAG_plot_simulated_sendside_bwe = setting;
329 FLAG_plot_network_delay_feedback = setting;
330 FLAG_plot_fraction_loss_feedback = setting;
331 FLAG_plot_timestamps = setting;
332 FLAG_plot_audio_encoder_bitrate_bps = setting;
333 FLAG_plot_audio_encoder_frame_length_ms = setting;
334 FLAG_plot_audio_encoder_packet_loss = setting;
335 FLAG_plot_audio_encoder_fec = setting;
336 FLAG_plot_audio_encoder_dtx = setting;
337 FLAG_plot_audio_encoder_num_channels = setting;
338 FLAG_plot_audio_jitter_buffer = setting;
339}