blob: aef040e33dc0d76fa3c4c7c7467a94ff478199f4 [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).");
stefane372d3c2017-02-02 08:04:18 -080091DEFINE_bool(plot_timestamps,
92 false,
93 "Plot the rtp timestamps of all rtp and rtcp packets over time.");
terelius2ee076d2017-08-15 02:04:02 -070094DEFINE_bool(plot_audio_encoder_bitrate_bps,
michaelt6e5b2192017-02-22 07:33:27 -080095 false,
96 "Plot the audio encoder target bitrate.");
terelius2ee076d2017-08-15 02:04:02 -070097DEFINE_bool(plot_audio_encoder_frame_length_ms,
michaelt6e5b2192017-02-22 07:33:27 -080098 false,
99 "Plot the audio encoder frame length.");
100DEFINE_bool(
terelius2ee076d2017-08-15 02:04:02 -0700101 plot_audio_encoder_packet_loss,
michaelt6e5b2192017-02-22 07:33:27 -0800102 false,
terelius2ee076d2017-08-15 02:04:02 -0700103 "Plot the uplink packet loss fraction which is sent to the audio encoder.");
104DEFINE_bool(plot_audio_encoder_fec, false, "Plot the audio encoder FEC.");
105DEFINE_bool(plot_audio_encoder_dtx, false, "Plot the audio encoder DTX.");
106DEFINE_bool(plot_audio_encoder_num_channels,
michaelt6e5b2192017-02-22 07:33:27 -0800107 false,
108 "Plot the audio encoder number of channels.");
henrik.lundin3c938fc2017-06-14 06:09:58 -0700109DEFINE_bool(plot_audio_jitter_buffer,
110 false,
111 "Plot the audio jitter buffer delay profile.");
Bjorn Terelius1edfff92017-10-11 13:15:19 +0200112
stefan985d2802016-11-15 06:54:09 -0800113DEFINE_string(
114 force_fieldtrials,
115 "",
116 "Field trials control experimental feature code which can be forced. "
117 "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enabled/"
118 " will assign the group Enabled to field trial WebRTC-FooFeature. Multiple "
119 "trials are separated by \"/\"");
owb7fbeb0b2017-08-16 02:48:33 -0700120DEFINE_string(wav_filename,
121 "",
122 "Path to wav file used for simulation of jitter buffer");
kjellander4fa5be42017-05-16 00:01:23 -0700123DEFINE_bool(help, false, "prints this message");
terelius54ce6802016-07-13 06:44:41 -0700124
terelius2ee076d2017-08-15 02:04:02 -0700125DEFINE_bool(show_detector_state,
126 false,
127 "Show the state of the delay based BWE detector on the total "
128 "bitrate graph");
129
130void SetAllPlotFlags(bool setting);
131
philipel23c7f252017-07-14 06:30:03 -0700132
terelius54ce6802016-07-13 06:44:41 -0700133int main(int argc, char* argv[]) {
134 std::string program_name = argv[0];
135 std::string usage =
136 "A tool for visualizing WebRTC event logs.\n"
137 "Example usage:\n" +
138 program_name + " <logfile> | python\n" + "Run " + program_name +
139 " --help for a list of command line options\n";
terelius2ee076d2017-08-15 02:04:02 -0700140
141 // Parse command line flags without removing them. We're only interested in
142 // the |plot_profile| flag.
143 rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, false);
144 if (strcmp(FLAG_plot_profile, "all") == 0) {
145 SetAllPlotFlags(true);
146 } else if (strcmp(FLAG_plot_profile, "none") == 0) {
147 SetAllPlotFlags(false);
Bjorn Terelius1edfff92017-10-11 13:15:19 +0200148 } else if (strcmp(FLAG_plot_profile, "sendside_bwe") == 0) {
149 SetAllPlotFlags(false);
150 FLAG_plot_outgoing_packet_sizes = true;
151 FLAG_plot_outgoing_bitrate = true;
152 FLAG_plot_outgoing_stream_bitrate = true;
153 FLAG_plot_simulated_sendside_bwe = true;
154 FLAG_plot_network_delay_feedback = true;
155 FLAG_plot_fraction_loss_feedback = true;
156 } else if (strcmp(FLAG_plot_profile, "receiveside_bwe") == 0) {
157 SetAllPlotFlags(false);
158 FLAG_plot_incoming_packet_sizes = true;
159 FLAG_plot_incoming_delay_delta = true;
160 FLAG_plot_incoming_delay = true;
161 FLAG_plot_incoming_loss_rate = true;
162 FLAG_plot_incoming_bitrate = true;
163 FLAG_plot_incoming_stream_bitrate = true;
164 FLAG_plot_simulated_receiveside_bwe = true;
terelius2ee076d2017-08-15 02:04:02 -0700165 } else if (strcmp(FLAG_plot_profile, "default") == 0) {
166 // Do nothing.
167 } else {
168 rtc::Flag* plot_profile_flag = rtc::FlagList::Lookup("plot_profile");
169 RTC_CHECK(plot_profile_flag);
170 plot_profile_flag->Print(false);
171 }
172 // Parse the remaining flags. They are applied relative to the chosen profile.
kjellander4fa5be42017-05-16 00:01:23 -0700173 rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
terelius2ee076d2017-08-15 02:04:02 -0700174
tereliusc4a5c142017-07-20 08:05:09 -0700175 if (argc != 2 || FLAG_help) {
kjellander4fa5be42017-05-16 00:01:23 -0700176 // Print usage information.
177 std::cout << usage;
tereliusc4a5c142017-07-20 08:05:09 -0700178 if (FLAG_help)
179 rtc::FlagList::Print(nullptr, false);
kjellander4fa5be42017-05-16 00:01:23 -0700180 return 0;
181 }
182
henrik.lundin3c938fc2017-06-14 06:09:58 -0700183 webrtc::test::SetExecutablePath(argv[0]);
kjellander4fa5be42017-05-16 00:01:23 -0700184 webrtc::test::InitFieldTrialsFromString(FLAG_force_fieldtrials);
stefan985d2802016-11-15 06:54:09 -0800185
terelius54ce6802016-07-13 06:44:41 -0700186 std::string filename = argv[1];
187
188 webrtc::ParsedRtcEventLog parsed_log;
189
190 if (!parsed_log.ParseFile(filename)) {
191 std::cerr << "Could not parse the entire log file." << std::endl;
192 std::cerr << "Proceeding to analyze the first "
193 << parsed_log.GetNumberOfEvents() << " events in the file."
194 << std::endl;
195 }
196
197 webrtc::plotting::EventLogAnalyzer analyzer(parsed_log);
198 std::unique_ptr<webrtc::plotting::PlotCollection> collection(
199 new webrtc::plotting::PythonPlotCollection());
200
terelius2ee076d2017-08-15 02:04:02 -0700201 if (FLAG_plot_incoming_packet_sizes) {
202 analyzer.CreatePacketGraph(webrtc::PacketDirection::kIncomingPacket,
203 collection->AppendNewPlot());
terelius54ce6802016-07-13 06:44:41 -0700204 }
terelius2ee076d2017-08-15 02:04:02 -0700205 if (FLAG_plot_outgoing_packet_sizes) {
206 analyzer.CreatePacketGraph(webrtc::PacketDirection::kOutgoingPacket,
207 collection->AppendNewPlot());
208 }
209 if (FLAG_plot_incoming_packet_count) {
210 analyzer.CreateAccumulatedPacketsGraph(
211 webrtc::PacketDirection::kIncomingPacket, collection->AppendNewPlot());
212 }
213 if (FLAG_plot_outgoing_packet_count) {
214 analyzer.CreateAccumulatedPacketsGraph(
215 webrtc::PacketDirection::kOutgoingPacket, collection->AppendNewPlot());
216 }
217 if (FLAG_plot_audio_playout) {
tereliusdc35dcd2016-08-01 12:03:27 -0700218 analyzer.CreatePlayoutGraph(collection->AppendNewPlot());
terelius54ce6802016-07-13 06:44:41 -0700219 }
terelius2ee076d2017-08-15 02:04:02 -0700220 if (FLAG_plot_audio_level) {
ivocaac9d6f2016-09-22 07:01:47 -0700221 analyzer.CreateAudioLevelGraph(collection->AppendNewPlot());
222 }
terelius2ee076d2017-08-15 02:04:02 -0700223 if (FLAG_plot_incoming_sequence_number_delta) {
224 analyzer.CreateSequenceNumberGraph(collection->AppendNewPlot());
terelius54ce6802016-07-13 06:44:41 -0700225 }
terelius2ee076d2017-08-15 02:04:02 -0700226 if (FLAG_plot_incoming_delay_delta) {
227 analyzer.CreateIncomingDelayDeltaGraph(collection->AppendNewPlot());
terelius54ce6802016-07-13 06:44:41 -0700228 }
terelius2ee076d2017-08-15 02:04:02 -0700229 if (FLAG_plot_incoming_delay) {
230 analyzer.CreateIncomingDelayGraph(collection->AppendNewPlot());
terelius54ce6802016-07-13 06:44:41 -0700231 }
terelius2ee076d2017-08-15 02:04:02 -0700232 if (FLAG_plot_incoming_loss_rate) {
Stefan Holmer99f8e082016-09-09 13:37:50 +0200233 analyzer.CreateIncomingPacketLossGraph(collection->AppendNewPlot());
tereliusf736d232016-08-04 10:00:11 -0700234 }
terelius2ee076d2017-08-15 02:04:02 -0700235 if (FLAG_plot_incoming_bitrate) {
236 analyzer.CreateTotalBitrateGraph(webrtc::PacketDirection::kIncomingPacket,
237 collection->AppendNewPlot(),
238 FLAG_show_detector_state);
terelius54ce6802016-07-13 06:44:41 -0700239 }
terelius2ee076d2017-08-15 02:04:02 -0700240 if (FLAG_plot_outgoing_bitrate) {
241 analyzer.CreateTotalBitrateGraph(webrtc::PacketDirection::kOutgoingPacket,
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_incoming_stream_bitrate) {
246 analyzer.CreateStreamBitrateGraph(webrtc::PacketDirection::kIncomingPacket,
247 collection->AppendNewPlot());
248 }
249 if (FLAG_plot_outgoing_stream_bitrate) {
250 analyzer.CreateStreamBitrateGraph(webrtc::PacketDirection::kOutgoingPacket,
251 collection->AppendNewPlot());
252 }
Bjorn Terelius28db2662017-10-04 14:22:43 +0200253 if (FLAG_plot_simulated_receiveside_bwe) {
254 analyzer.CreateReceiveSideBweSimulationGraph(collection->AppendNewPlot());
255 }
terelius2ee076d2017-08-15 02:04:02 -0700256 if (FLAG_plot_simulated_sendside_bwe) {
Bjorn Terelius28db2662017-10-04 14:22:43 +0200257 analyzer.CreateSendSideBweSimulationGraph(collection->AppendNewPlot());
Stefan Holmer13181032016-07-29 14:48:54 +0200258 }
terelius2ee076d2017-08-15 02:04:02 -0700259 if (FLAG_plot_network_delay_feedback) {
tereliuse34c19c2016-08-15 08:47:14 -0700260 analyzer.CreateNetworkDelayFeedbackGraph(collection->AppendNewPlot());
stefanc3de0332016-08-02 07:22:17 -0700261 }
terelius2ee076d2017-08-15 02:04:02 -0700262 if (FLAG_plot_fraction_loss_feedback) {
263 analyzer.CreateFractionLossGraph(collection->AppendNewPlot());
264 }
265 if (FLAG_plot_timestamps) {
stefane372d3c2017-02-02 08:04:18 -0800266 analyzer.CreateTimestampGraph(collection->AppendNewPlot());
267 }
terelius2ee076d2017-08-15 02:04:02 -0700268 if (FLAG_plot_audio_encoder_bitrate_bps) {
michaelt6e5b2192017-02-22 07:33:27 -0800269 analyzer.CreateAudioEncoderTargetBitrateGraph(collection->AppendNewPlot());
270 }
terelius2ee076d2017-08-15 02:04:02 -0700271 if (FLAG_plot_audio_encoder_frame_length_ms) {
michaelt6e5b2192017-02-22 07:33:27 -0800272 analyzer.CreateAudioEncoderFrameLengthGraph(collection->AppendNewPlot());
273 }
terelius2ee076d2017-08-15 02:04:02 -0700274 if (FLAG_plot_audio_encoder_packet_loss) {
275 analyzer.CreateAudioEncoderPacketLossGraph(collection->AppendNewPlot());
michaelt6e5b2192017-02-22 07:33:27 -0800276 }
terelius2ee076d2017-08-15 02:04:02 -0700277 if (FLAG_plot_audio_encoder_fec) {
michaelt6e5b2192017-02-22 07:33:27 -0800278 analyzer.CreateAudioEncoderEnableFecGraph(collection->AppendNewPlot());
279 }
terelius2ee076d2017-08-15 02:04:02 -0700280 if (FLAG_plot_audio_encoder_dtx) {
michaelt6e5b2192017-02-22 07:33:27 -0800281 analyzer.CreateAudioEncoderEnableDtxGraph(collection->AppendNewPlot());
282 }
terelius2ee076d2017-08-15 02:04:02 -0700283 if (FLAG_plot_audio_encoder_num_channels) {
michaelt6e5b2192017-02-22 07:33:27 -0800284 analyzer.CreateAudioEncoderNumChannelsGraph(collection->AppendNewPlot());
285 }
terelius2ee076d2017-08-15 02:04:02 -0700286 if (FLAG_plot_audio_jitter_buffer) {
owb7fbeb0b2017-08-16 02:48:33 -0700287 std::string wav_path;
288 if (FLAG_wav_filename[0] != '\0') {
289 wav_path = FLAG_wav_filename;
290 } else {
291 wav_path = webrtc::test::ResourcePath(
292 "audio_processing/conversational_speech/EN_script2_F_sp2_B1", "wav");
293 }
294 analyzer.CreateAudioJitterBufferGraph(wav_path, 48000,
295 collection->AppendNewPlot());
henrik.lundin3c938fc2017-06-14 06:09:58 -0700296 }
297
tereliusdc35dcd2016-08-01 12:03:27 -0700298 collection->Draw();
terelius54ce6802016-07-13 06:44:41 -0700299
300 return 0;
301}
terelius2ee076d2017-08-15 02:04:02 -0700302
303
304void SetAllPlotFlags(bool setting) {
305 FLAG_plot_incoming_packet_sizes = setting;
306 FLAG_plot_outgoing_packet_sizes = setting;
307 FLAG_plot_incoming_packet_count = setting;
308 FLAG_plot_outgoing_packet_count = setting;
309 FLAG_plot_audio_playout = setting;
310 FLAG_plot_audio_level = setting;
311 FLAG_plot_incoming_sequence_number_delta = setting;
312 FLAG_plot_incoming_delay_delta = setting;
313 FLAG_plot_incoming_delay = setting;
314 FLAG_plot_incoming_loss_rate = setting;
315 FLAG_plot_incoming_bitrate = setting;
316 FLAG_plot_outgoing_bitrate = setting;
317 FLAG_plot_incoming_stream_bitrate = setting;
318 FLAG_plot_outgoing_stream_bitrate = setting;
Bjorn Terelius28db2662017-10-04 14:22:43 +0200319 FLAG_plot_simulated_receiveside_bwe = setting;
terelius2ee076d2017-08-15 02:04:02 -0700320 FLAG_plot_simulated_sendside_bwe = setting;
321 FLAG_plot_network_delay_feedback = setting;
322 FLAG_plot_fraction_loss_feedback = setting;
323 FLAG_plot_timestamps = setting;
324 FLAG_plot_audio_encoder_bitrate_bps = setting;
325 FLAG_plot_audio_encoder_frame_length_ms = setting;
326 FLAG_plot_audio_encoder_packet_loss = setting;
327 FLAG_plot_audio_encoder_fec = setting;
328 FLAG_plot_audio_encoder_dtx = setting;
329 FLAG_plot_audio_encoder_num_channels = setting;
330 FLAG_plot_audio_jitter_buffer = setting;
331}