blob: fc9f707d4c11be4981463f7bcf031522d9e5c4bb [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 "
24 "defined profiles are \"all\", \"none\" and \"default\"");
25
26DEFINE_bool(plot_incoming_packet_sizes,
terelius54ce6802016-07-13 06:44:41 -070027 false,
terelius2ee076d2017-08-15 02:04:02 -070028 "Plot bar graph showing the size of each incoming packet.");
29DEFINE_bool(plot_outgoing_packet_sizes,
30 false,
31 "Plot bar graph showing the size of each outgoing packet.");
32DEFINE_bool(plot_incoming_packet_count,
33 false,
34 "Plot the accumulated number of packets for each incoming stream.");
35DEFINE_bool(plot_outgoing_packet_count,
36 false,
37 "Plot the accumulated number of packets for each outgoing stream.");
terelius54ce6802016-07-13 06:44:41 -070038DEFINE_bool(plot_audio_playout,
39 false,
40 "Plot bar graph showing the time between each audio playout.");
ivocaac9d6f2016-09-22 07:01:47 -070041DEFINE_bool(plot_audio_level,
42 false,
terelius2ee076d2017-08-15 02:04:02 -070043 "Plot line graph showing the audio level of incoming audio.");
44DEFINE_bool(plot_incoming_sequence_number_delta,
45 false,
46 "Plot the sequence number difference between consecutive incoming "
47 "packets.");
terelius54ce6802016-07-13 06:44:41 -070048DEFINE_bool(
terelius2ee076d2017-08-15 02:04:02 -070049 plot_incoming_delay_delta,
terelius54ce6802016-07-13 06:44:41 -070050 false,
51 "Plot the difference in 1-way path delay between consecutive packets.");
terelius2ee076d2017-08-15 02:04:02 -070052DEFINE_bool(plot_incoming_delay,
53 true,
54 "Plot the 1-way path delay for incoming packets, normalized so "
55 "that the first packet has delay 0.");
56DEFINE_bool(plot_incoming_loss_rate,
57 true,
58 "Compute the loss rate for incoming packets using a method that's "
59 "similar to the one used for RTCP SR and RR fraction lost. Note "
60 "that the loss rate can be negative if packets are duplicated or "
61 "reordered.");
62DEFINE_bool(plot_incoming_bitrate,
63 true,
64 "Plot the total bitrate used by all incoming streams.");
65DEFINE_bool(plot_outgoing_bitrate,
66 true,
67 "Plot the total bitrate used by all outgoing streams.");
68DEFINE_bool(plot_incoming_stream_bitrate,
69 true,
70 "Plot the bitrate used by each incoming stream.");
71DEFINE_bool(plot_outgoing_stream_bitrate,
72 true,
73 "Plot the bitrate used by each outgoing stream.");
Bjorn Terelius28db2662017-10-04 14:22:43 +020074DEFINE_bool(plot_simulated_receiveside_bwe,
75 false,
76 "Run the receive-side bandwidth estimator with the incoming rtp "
77 "packets and plot the resulting estimate.");
terelius2ee076d2017-08-15 02:04:02 -070078DEFINE_bool(plot_simulated_sendside_bwe,
terelius54ce6802016-07-13 06:44:41 -070079 false,
terelius2ee076d2017-08-15 02:04:02 -070080 "Run the send-side bandwidth estimator with the outgoing rtp and "
81 "incoming rtcp and plot the resulting estimate.");
stefanc3de0332016-08-02 07:22:17 -070082DEFINE_bool(plot_network_delay_feedback,
terelius2ee076d2017-08-15 02:04:02 -070083 true,
stefanc3de0332016-08-02 07:22:17 -070084 "Compute network delay based on sent packets and the received "
85 "transport feedback.");
terelius2ee076d2017-08-15 02:04:02 -070086DEFINE_bool(plot_fraction_loss_feedback,
87 true,
tereliusf736d232016-08-04 10:00:11 -070088 "Plot packet loss in percent for outgoing packets (as perceived by "
89 "the send-side bandwidth estimator).");
stefane372d3c2017-02-02 08:04:18 -080090DEFINE_bool(plot_timestamps,
91 false,
92 "Plot the rtp timestamps of all rtp and rtcp packets over time.");
terelius2ee076d2017-08-15 02:04:02 -070093DEFINE_bool(plot_audio_encoder_bitrate_bps,
michaelt6e5b2192017-02-22 07:33:27 -080094 false,
95 "Plot the audio encoder target bitrate.");
terelius2ee076d2017-08-15 02:04:02 -070096DEFINE_bool(plot_audio_encoder_frame_length_ms,
michaelt6e5b2192017-02-22 07:33:27 -080097 false,
98 "Plot the audio encoder frame length.");
99DEFINE_bool(
terelius2ee076d2017-08-15 02:04:02 -0700100 plot_audio_encoder_packet_loss,
michaelt6e5b2192017-02-22 07:33:27 -0800101 false,
terelius2ee076d2017-08-15 02:04:02 -0700102 "Plot the uplink packet loss fraction which is sent to the audio encoder.");
103DEFINE_bool(plot_audio_encoder_fec, false, "Plot the audio encoder FEC.");
104DEFINE_bool(plot_audio_encoder_dtx, false, "Plot the audio encoder DTX.");
105DEFINE_bool(plot_audio_encoder_num_channels,
michaelt6e5b2192017-02-22 07:33:27 -0800106 false,
107 "Plot the audio encoder number of channels.");
henrik.lundin3c938fc2017-06-14 06:09:58 -0700108DEFINE_bool(plot_audio_jitter_buffer,
109 false,
110 "Plot the audio jitter buffer delay profile.");
stefan985d2802016-11-15 06:54:09 -0800111DEFINE_string(
112 force_fieldtrials,
113 "",
114 "Field trials control experimental feature code which can be forced. "
115 "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enabled/"
116 " will assign the group Enabled to field trial WebRTC-FooFeature. Multiple "
117 "trials are separated by \"/\"");
owb7fbeb0b2017-08-16 02:48:33 -0700118DEFINE_string(wav_filename,
119 "",
120 "Path to wav file used for simulation of jitter buffer");
kjellander4fa5be42017-05-16 00:01:23 -0700121DEFINE_bool(help, false, "prints this message");
terelius54ce6802016-07-13 06:44:41 -0700122
terelius2ee076d2017-08-15 02:04:02 -0700123DEFINE_bool(show_detector_state,
124 false,
125 "Show the state of the delay based BWE detector on the total "
126 "bitrate graph");
127
128void SetAllPlotFlags(bool setting);
129
philipel23c7f252017-07-14 06:30:03 -0700130
terelius54ce6802016-07-13 06:44:41 -0700131int main(int argc, char* argv[]) {
132 std::string program_name = argv[0];
133 std::string usage =
134 "A tool for visualizing WebRTC event logs.\n"
135 "Example usage:\n" +
136 program_name + " <logfile> | python\n" + "Run " + program_name +
137 " --help for a list of command line options\n";
terelius2ee076d2017-08-15 02:04:02 -0700138
139 // Parse command line flags without removing them. We're only interested in
140 // the |plot_profile| flag.
141 rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, false);
142 if (strcmp(FLAG_plot_profile, "all") == 0) {
143 SetAllPlotFlags(true);
144 } else if (strcmp(FLAG_plot_profile, "none") == 0) {
145 SetAllPlotFlags(false);
146 } else if (strcmp(FLAG_plot_profile, "default") == 0) {
147 // Do nothing.
148 } else {
149 rtc::Flag* plot_profile_flag = rtc::FlagList::Lookup("plot_profile");
150 RTC_CHECK(plot_profile_flag);
151 plot_profile_flag->Print(false);
152 }
153 // Parse the remaining flags. They are applied relative to the chosen profile.
kjellander4fa5be42017-05-16 00:01:23 -0700154 rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
terelius2ee076d2017-08-15 02:04:02 -0700155
tereliusc4a5c142017-07-20 08:05:09 -0700156 if (argc != 2 || FLAG_help) {
kjellander4fa5be42017-05-16 00:01:23 -0700157 // Print usage information.
158 std::cout << usage;
tereliusc4a5c142017-07-20 08:05:09 -0700159 if (FLAG_help)
160 rtc::FlagList::Print(nullptr, false);
kjellander4fa5be42017-05-16 00:01:23 -0700161 return 0;
162 }
163
henrik.lundin3c938fc2017-06-14 06:09:58 -0700164 webrtc::test::SetExecutablePath(argv[0]);
kjellander4fa5be42017-05-16 00:01:23 -0700165 webrtc::test::InitFieldTrialsFromString(FLAG_force_fieldtrials);
stefan985d2802016-11-15 06:54:09 -0800166
terelius54ce6802016-07-13 06:44:41 -0700167 std::string filename = argv[1];
168
169 webrtc::ParsedRtcEventLog parsed_log;
170
171 if (!parsed_log.ParseFile(filename)) {
172 std::cerr << "Could not parse the entire log file." << std::endl;
173 std::cerr << "Proceeding to analyze the first "
174 << parsed_log.GetNumberOfEvents() << " events in the file."
175 << std::endl;
176 }
177
178 webrtc::plotting::EventLogAnalyzer analyzer(parsed_log);
179 std::unique_ptr<webrtc::plotting::PlotCollection> collection(
180 new webrtc::plotting::PythonPlotCollection());
181
terelius2ee076d2017-08-15 02:04:02 -0700182 if (FLAG_plot_incoming_packet_sizes) {
183 analyzer.CreatePacketGraph(webrtc::PacketDirection::kIncomingPacket,
184 collection->AppendNewPlot());
terelius54ce6802016-07-13 06:44:41 -0700185 }
terelius2ee076d2017-08-15 02:04:02 -0700186 if (FLAG_plot_outgoing_packet_sizes) {
187 analyzer.CreatePacketGraph(webrtc::PacketDirection::kOutgoingPacket,
188 collection->AppendNewPlot());
189 }
190 if (FLAG_plot_incoming_packet_count) {
191 analyzer.CreateAccumulatedPacketsGraph(
192 webrtc::PacketDirection::kIncomingPacket, collection->AppendNewPlot());
193 }
194 if (FLAG_plot_outgoing_packet_count) {
195 analyzer.CreateAccumulatedPacketsGraph(
196 webrtc::PacketDirection::kOutgoingPacket, collection->AppendNewPlot());
197 }
198 if (FLAG_plot_audio_playout) {
tereliusdc35dcd2016-08-01 12:03:27 -0700199 analyzer.CreatePlayoutGraph(collection->AppendNewPlot());
terelius54ce6802016-07-13 06:44:41 -0700200 }
terelius2ee076d2017-08-15 02:04:02 -0700201 if (FLAG_plot_audio_level) {
ivocaac9d6f2016-09-22 07:01:47 -0700202 analyzer.CreateAudioLevelGraph(collection->AppendNewPlot());
203 }
terelius2ee076d2017-08-15 02:04:02 -0700204 if (FLAG_plot_incoming_sequence_number_delta) {
205 analyzer.CreateSequenceNumberGraph(collection->AppendNewPlot());
terelius54ce6802016-07-13 06:44:41 -0700206 }
terelius2ee076d2017-08-15 02:04:02 -0700207 if (FLAG_plot_incoming_delay_delta) {
208 analyzer.CreateIncomingDelayDeltaGraph(collection->AppendNewPlot());
terelius54ce6802016-07-13 06:44:41 -0700209 }
terelius2ee076d2017-08-15 02:04:02 -0700210 if (FLAG_plot_incoming_delay) {
211 analyzer.CreateIncomingDelayGraph(collection->AppendNewPlot());
terelius54ce6802016-07-13 06:44:41 -0700212 }
terelius2ee076d2017-08-15 02:04:02 -0700213 if (FLAG_plot_incoming_loss_rate) {
Stefan Holmer99f8e082016-09-09 13:37:50 +0200214 analyzer.CreateIncomingPacketLossGraph(collection->AppendNewPlot());
tereliusf736d232016-08-04 10:00:11 -0700215 }
terelius2ee076d2017-08-15 02:04:02 -0700216 if (FLAG_plot_incoming_bitrate) {
217 analyzer.CreateTotalBitrateGraph(webrtc::PacketDirection::kIncomingPacket,
218 collection->AppendNewPlot(),
219 FLAG_show_detector_state);
terelius54ce6802016-07-13 06:44:41 -0700220 }
terelius2ee076d2017-08-15 02:04:02 -0700221 if (FLAG_plot_outgoing_bitrate) {
222 analyzer.CreateTotalBitrateGraph(webrtc::PacketDirection::kOutgoingPacket,
223 collection->AppendNewPlot(),
224 FLAG_show_detector_state);
terelius54ce6802016-07-13 06:44:41 -0700225 }
terelius2ee076d2017-08-15 02:04:02 -0700226 if (FLAG_plot_incoming_stream_bitrate) {
227 analyzer.CreateStreamBitrateGraph(webrtc::PacketDirection::kIncomingPacket,
228 collection->AppendNewPlot());
229 }
230 if (FLAG_plot_outgoing_stream_bitrate) {
231 analyzer.CreateStreamBitrateGraph(webrtc::PacketDirection::kOutgoingPacket,
232 collection->AppendNewPlot());
233 }
Bjorn Terelius28db2662017-10-04 14:22:43 +0200234 if (FLAG_plot_simulated_receiveside_bwe) {
235 analyzer.CreateReceiveSideBweSimulationGraph(collection->AppendNewPlot());
236 }
terelius2ee076d2017-08-15 02:04:02 -0700237 if (FLAG_plot_simulated_sendside_bwe) {
Bjorn Terelius28db2662017-10-04 14:22:43 +0200238 analyzer.CreateSendSideBweSimulationGraph(collection->AppendNewPlot());
Stefan Holmer13181032016-07-29 14:48:54 +0200239 }
terelius2ee076d2017-08-15 02:04:02 -0700240 if (FLAG_plot_network_delay_feedback) {
tereliuse34c19c2016-08-15 08:47:14 -0700241 analyzer.CreateNetworkDelayFeedbackGraph(collection->AppendNewPlot());
stefanc3de0332016-08-02 07:22:17 -0700242 }
terelius2ee076d2017-08-15 02:04:02 -0700243 if (FLAG_plot_fraction_loss_feedback) {
244 analyzer.CreateFractionLossGraph(collection->AppendNewPlot());
245 }
246 if (FLAG_plot_timestamps) {
stefane372d3c2017-02-02 08:04:18 -0800247 analyzer.CreateTimestampGraph(collection->AppendNewPlot());
248 }
terelius2ee076d2017-08-15 02:04:02 -0700249 if (FLAG_plot_audio_encoder_bitrate_bps) {
michaelt6e5b2192017-02-22 07:33:27 -0800250 analyzer.CreateAudioEncoderTargetBitrateGraph(collection->AppendNewPlot());
251 }
terelius2ee076d2017-08-15 02:04:02 -0700252 if (FLAG_plot_audio_encoder_frame_length_ms) {
michaelt6e5b2192017-02-22 07:33:27 -0800253 analyzer.CreateAudioEncoderFrameLengthGraph(collection->AppendNewPlot());
254 }
terelius2ee076d2017-08-15 02:04:02 -0700255 if (FLAG_plot_audio_encoder_packet_loss) {
256 analyzer.CreateAudioEncoderPacketLossGraph(collection->AppendNewPlot());
michaelt6e5b2192017-02-22 07:33:27 -0800257 }
terelius2ee076d2017-08-15 02:04:02 -0700258 if (FLAG_plot_audio_encoder_fec) {
michaelt6e5b2192017-02-22 07:33:27 -0800259 analyzer.CreateAudioEncoderEnableFecGraph(collection->AppendNewPlot());
260 }
terelius2ee076d2017-08-15 02:04:02 -0700261 if (FLAG_plot_audio_encoder_dtx) {
michaelt6e5b2192017-02-22 07:33:27 -0800262 analyzer.CreateAudioEncoderEnableDtxGraph(collection->AppendNewPlot());
263 }
terelius2ee076d2017-08-15 02:04:02 -0700264 if (FLAG_plot_audio_encoder_num_channels) {
michaelt6e5b2192017-02-22 07:33:27 -0800265 analyzer.CreateAudioEncoderNumChannelsGraph(collection->AppendNewPlot());
266 }
terelius2ee076d2017-08-15 02:04:02 -0700267 if (FLAG_plot_audio_jitter_buffer) {
owb7fbeb0b2017-08-16 02:48:33 -0700268 std::string wav_path;
269 if (FLAG_wav_filename[0] != '\0') {
270 wav_path = FLAG_wav_filename;
271 } else {
272 wav_path = webrtc::test::ResourcePath(
273 "audio_processing/conversational_speech/EN_script2_F_sp2_B1", "wav");
274 }
275 analyzer.CreateAudioJitterBufferGraph(wav_path, 48000,
276 collection->AppendNewPlot());
henrik.lundin3c938fc2017-06-14 06:09:58 -0700277 }
278
tereliusdc35dcd2016-08-01 12:03:27 -0700279 collection->Draw();
terelius54ce6802016-07-13 06:44:41 -0700280
281 return 0;
282}
terelius2ee076d2017-08-15 02:04:02 -0700283
284
285void SetAllPlotFlags(bool setting) {
286 FLAG_plot_incoming_packet_sizes = setting;
287 FLAG_plot_outgoing_packet_sizes = setting;
288 FLAG_plot_incoming_packet_count = setting;
289 FLAG_plot_outgoing_packet_count = setting;
290 FLAG_plot_audio_playout = setting;
291 FLAG_plot_audio_level = setting;
292 FLAG_plot_incoming_sequence_number_delta = setting;
293 FLAG_plot_incoming_delay_delta = setting;
294 FLAG_plot_incoming_delay = setting;
295 FLAG_plot_incoming_loss_rate = setting;
296 FLAG_plot_incoming_bitrate = setting;
297 FLAG_plot_outgoing_bitrate = setting;
298 FLAG_plot_incoming_stream_bitrate = setting;
299 FLAG_plot_outgoing_stream_bitrate = setting;
Bjorn Terelius28db2662017-10-04 14:22:43 +0200300 FLAG_plot_simulated_receiveside_bwe = setting;
terelius2ee076d2017-08-15 02:04:02 -0700301 FLAG_plot_simulated_sendside_bwe = setting;
302 FLAG_plot_network_delay_feedback = setting;
303 FLAG_plot_fraction_loss_feedback = setting;
304 FLAG_plot_timestamps = setting;
305 FLAG_plot_audio_encoder_bitrate_bps = setting;
306 FLAG_plot_audio_encoder_frame_length_ms = setting;
307 FLAG_plot_audio_encoder_packet_loss = setting;
308 FLAG_plot_audio_encoder_fec = setting;
309 FLAG_plot_audio_encoder_dtx = setting;
310 FLAG_plot_audio_encoder_num_channels = setting;
311 FLAG_plot_audio_jitter_buffer = setting;
312}