blob: aa92a7f644b0c81d32a354955d01d14ea3854d82 [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.");
74DEFINE_bool(plot_simulated_sendside_bwe,
terelius54ce6802016-07-13 06:44:41 -070075 false,
terelius2ee076d2017-08-15 02:04:02 -070076 "Run the send-side bandwidth estimator with the outgoing rtp and "
77 "incoming rtcp and plot the resulting estimate.");
stefanc3de0332016-08-02 07:22:17 -070078DEFINE_bool(plot_network_delay_feedback,
terelius2ee076d2017-08-15 02:04:02 -070079 true,
stefanc3de0332016-08-02 07:22:17 -070080 "Compute network delay based on sent packets and the received "
81 "transport feedback.");
terelius2ee076d2017-08-15 02:04:02 -070082DEFINE_bool(plot_fraction_loss_feedback,
83 true,
tereliusf736d232016-08-04 10:00:11 -070084 "Plot packet loss in percent for outgoing packets (as perceived by "
85 "the send-side bandwidth estimator).");
stefane372d3c2017-02-02 08:04:18 -080086DEFINE_bool(plot_timestamps,
87 false,
88 "Plot the rtp timestamps of all rtp and rtcp packets over time.");
terelius2ee076d2017-08-15 02:04:02 -070089DEFINE_bool(plot_audio_encoder_bitrate_bps,
michaelt6e5b2192017-02-22 07:33:27 -080090 false,
91 "Plot the audio encoder target bitrate.");
terelius2ee076d2017-08-15 02:04:02 -070092DEFINE_bool(plot_audio_encoder_frame_length_ms,
michaelt6e5b2192017-02-22 07:33:27 -080093 false,
94 "Plot the audio encoder frame length.");
95DEFINE_bool(
terelius2ee076d2017-08-15 02:04:02 -070096 plot_audio_encoder_packet_loss,
michaelt6e5b2192017-02-22 07:33:27 -080097 false,
terelius2ee076d2017-08-15 02:04:02 -070098 "Plot the uplink packet loss fraction which is sent to the audio encoder.");
99DEFINE_bool(plot_audio_encoder_fec, false, "Plot the audio encoder FEC.");
100DEFINE_bool(plot_audio_encoder_dtx, false, "Plot the audio encoder DTX.");
101DEFINE_bool(plot_audio_encoder_num_channels,
michaelt6e5b2192017-02-22 07:33:27 -0800102 false,
103 "Plot the audio encoder number of channels.");
henrik.lundin3c938fc2017-06-14 06:09:58 -0700104DEFINE_bool(plot_audio_jitter_buffer,
105 false,
106 "Plot the audio jitter buffer delay profile.");
stefan985d2802016-11-15 06:54:09 -0800107DEFINE_string(
108 force_fieldtrials,
109 "",
110 "Field trials control experimental feature code which can be forced. "
111 "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enabled/"
112 " will assign the group Enabled to field trial WebRTC-FooFeature. Multiple "
113 "trials are separated by \"/\"");
owb7fbeb0b2017-08-16 02:48:33 -0700114DEFINE_string(wav_filename,
115 "",
116 "Path to wav file used for simulation of jitter buffer");
kjellander4fa5be42017-05-16 00:01:23 -0700117DEFINE_bool(help, false, "prints this message");
terelius54ce6802016-07-13 06:44:41 -0700118
terelius2ee076d2017-08-15 02:04:02 -0700119DEFINE_bool(show_detector_state,
120 false,
121 "Show the state of the delay based BWE detector on the total "
122 "bitrate graph");
123
124void SetAllPlotFlags(bool setting);
125
philipel23c7f252017-07-14 06:30:03 -0700126
terelius54ce6802016-07-13 06:44:41 -0700127int main(int argc, char* argv[]) {
128 std::string program_name = argv[0];
129 std::string usage =
130 "A tool for visualizing WebRTC event logs.\n"
131 "Example usage:\n" +
132 program_name + " <logfile> | python\n" + "Run " + program_name +
133 " --help for a list of command line options\n";
terelius2ee076d2017-08-15 02:04:02 -0700134
135 // Parse command line flags without removing them. We're only interested in
136 // the |plot_profile| flag.
137 rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, false);
138 if (strcmp(FLAG_plot_profile, "all") == 0) {
139 SetAllPlotFlags(true);
140 } else if (strcmp(FLAG_plot_profile, "none") == 0) {
141 SetAllPlotFlags(false);
142 } else if (strcmp(FLAG_plot_profile, "default") == 0) {
143 // Do nothing.
144 } else {
145 rtc::Flag* plot_profile_flag = rtc::FlagList::Lookup("plot_profile");
146 RTC_CHECK(plot_profile_flag);
147 plot_profile_flag->Print(false);
148 }
149 // Parse the remaining flags. They are applied relative to the chosen profile.
kjellander4fa5be42017-05-16 00:01:23 -0700150 rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
terelius2ee076d2017-08-15 02:04:02 -0700151
tereliusc4a5c142017-07-20 08:05:09 -0700152 if (argc != 2 || FLAG_help) {
kjellander4fa5be42017-05-16 00:01:23 -0700153 // Print usage information.
154 std::cout << usage;
tereliusc4a5c142017-07-20 08:05:09 -0700155 if (FLAG_help)
156 rtc::FlagList::Print(nullptr, false);
kjellander4fa5be42017-05-16 00:01:23 -0700157 return 0;
158 }
159
henrik.lundin3c938fc2017-06-14 06:09:58 -0700160 webrtc::test::SetExecutablePath(argv[0]);
kjellander4fa5be42017-05-16 00:01:23 -0700161 webrtc::test::InitFieldTrialsFromString(FLAG_force_fieldtrials);
stefan985d2802016-11-15 06:54:09 -0800162
terelius54ce6802016-07-13 06:44:41 -0700163 std::string filename = argv[1];
164
165 webrtc::ParsedRtcEventLog parsed_log;
166
167 if (!parsed_log.ParseFile(filename)) {
168 std::cerr << "Could not parse the entire log file." << std::endl;
169 std::cerr << "Proceeding to analyze the first "
170 << parsed_log.GetNumberOfEvents() << " events in the file."
171 << std::endl;
172 }
173
174 webrtc::plotting::EventLogAnalyzer analyzer(parsed_log);
175 std::unique_ptr<webrtc::plotting::PlotCollection> collection(
176 new webrtc::plotting::PythonPlotCollection());
177
terelius2ee076d2017-08-15 02:04:02 -0700178 if (FLAG_plot_incoming_packet_sizes) {
179 analyzer.CreatePacketGraph(webrtc::PacketDirection::kIncomingPacket,
180 collection->AppendNewPlot());
terelius54ce6802016-07-13 06:44:41 -0700181 }
terelius2ee076d2017-08-15 02:04:02 -0700182 if (FLAG_plot_outgoing_packet_sizes) {
183 analyzer.CreatePacketGraph(webrtc::PacketDirection::kOutgoingPacket,
184 collection->AppendNewPlot());
185 }
186 if (FLAG_plot_incoming_packet_count) {
187 analyzer.CreateAccumulatedPacketsGraph(
188 webrtc::PacketDirection::kIncomingPacket, collection->AppendNewPlot());
189 }
190 if (FLAG_plot_outgoing_packet_count) {
191 analyzer.CreateAccumulatedPacketsGraph(
192 webrtc::PacketDirection::kOutgoingPacket, collection->AppendNewPlot());
193 }
194 if (FLAG_plot_audio_playout) {
tereliusdc35dcd2016-08-01 12:03:27 -0700195 analyzer.CreatePlayoutGraph(collection->AppendNewPlot());
terelius54ce6802016-07-13 06:44:41 -0700196 }
terelius2ee076d2017-08-15 02:04:02 -0700197 if (FLAG_plot_audio_level) {
ivocaac9d6f2016-09-22 07:01:47 -0700198 analyzer.CreateAudioLevelGraph(collection->AppendNewPlot());
199 }
terelius2ee076d2017-08-15 02:04:02 -0700200 if (FLAG_plot_incoming_sequence_number_delta) {
201 analyzer.CreateSequenceNumberGraph(collection->AppendNewPlot());
terelius54ce6802016-07-13 06:44:41 -0700202 }
terelius2ee076d2017-08-15 02:04:02 -0700203 if (FLAG_plot_incoming_delay_delta) {
204 analyzer.CreateIncomingDelayDeltaGraph(collection->AppendNewPlot());
terelius54ce6802016-07-13 06:44:41 -0700205 }
terelius2ee076d2017-08-15 02:04:02 -0700206 if (FLAG_plot_incoming_delay) {
207 analyzer.CreateIncomingDelayGraph(collection->AppendNewPlot());
terelius54ce6802016-07-13 06:44:41 -0700208 }
terelius2ee076d2017-08-15 02:04:02 -0700209 if (FLAG_plot_incoming_loss_rate) {
Stefan Holmer99f8e082016-09-09 13:37:50 +0200210 analyzer.CreateIncomingPacketLossGraph(collection->AppendNewPlot());
tereliusf736d232016-08-04 10:00:11 -0700211 }
terelius2ee076d2017-08-15 02:04:02 -0700212 if (FLAG_plot_incoming_bitrate) {
213 analyzer.CreateTotalBitrateGraph(webrtc::PacketDirection::kIncomingPacket,
214 collection->AppendNewPlot(),
215 FLAG_show_detector_state);
terelius54ce6802016-07-13 06:44:41 -0700216 }
terelius2ee076d2017-08-15 02:04:02 -0700217 if (FLAG_plot_outgoing_bitrate) {
218 analyzer.CreateTotalBitrateGraph(webrtc::PacketDirection::kOutgoingPacket,
219 collection->AppendNewPlot(),
220 FLAG_show_detector_state);
terelius54ce6802016-07-13 06:44:41 -0700221 }
terelius2ee076d2017-08-15 02:04:02 -0700222 if (FLAG_plot_incoming_stream_bitrate) {
223 analyzer.CreateStreamBitrateGraph(webrtc::PacketDirection::kIncomingPacket,
224 collection->AppendNewPlot());
225 }
226 if (FLAG_plot_outgoing_stream_bitrate) {
227 analyzer.CreateStreamBitrateGraph(webrtc::PacketDirection::kOutgoingPacket,
228 collection->AppendNewPlot());
229 }
230 if (FLAG_plot_simulated_sendside_bwe) {
tereliuse34c19c2016-08-15 08:47:14 -0700231 analyzer.CreateBweSimulationGraph(collection->AppendNewPlot());
Stefan Holmer13181032016-07-29 14:48:54 +0200232 }
terelius2ee076d2017-08-15 02:04:02 -0700233 if (FLAG_plot_network_delay_feedback) {
tereliuse34c19c2016-08-15 08:47:14 -0700234 analyzer.CreateNetworkDelayFeedbackGraph(collection->AppendNewPlot());
stefanc3de0332016-08-02 07:22:17 -0700235 }
terelius2ee076d2017-08-15 02:04:02 -0700236 if (FLAG_plot_fraction_loss_feedback) {
237 analyzer.CreateFractionLossGraph(collection->AppendNewPlot());
238 }
239 if (FLAG_plot_timestamps) {
stefane372d3c2017-02-02 08:04:18 -0800240 analyzer.CreateTimestampGraph(collection->AppendNewPlot());
241 }
terelius2ee076d2017-08-15 02:04:02 -0700242 if (FLAG_plot_audio_encoder_bitrate_bps) {
michaelt6e5b2192017-02-22 07:33:27 -0800243 analyzer.CreateAudioEncoderTargetBitrateGraph(collection->AppendNewPlot());
244 }
terelius2ee076d2017-08-15 02:04:02 -0700245 if (FLAG_plot_audio_encoder_frame_length_ms) {
michaelt6e5b2192017-02-22 07:33:27 -0800246 analyzer.CreateAudioEncoderFrameLengthGraph(collection->AppendNewPlot());
247 }
terelius2ee076d2017-08-15 02:04:02 -0700248 if (FLAG_plot_audio_encoder_packet_loss) {
249 analyzer.CreateAudioEncoderPacketLossGraph(collection->AppendNewPlot());
michaelt6e5b2192017-02-22 07:33:27 -0800250 }
terelius2ee076d2017-08-15 02:04:02 -0700251 if (FLAG_plot_audio_encoder_fec) {
michaelt6e5b2192017-02-22 07:33:27 -0800252 analyzer.CreateAudioEncoderEnableFecGraph(collection->AppendNewPlot());
253 }
terelius2ee076d2017-08-15 02:04:02 -0700254 if (FLAG_plot_audio_encoder_dtx) {
michaelt6e5b2192017-02-22 07:33:27 -0800255 analyzer.CreateAudioEncoderEnableDtxGraph(collection->AppendNewPlot());
256 }
terelius2ee076d2017-08-15 02:04:02 -0700257 if (FLAG_plot_audio_encoder_num_channels) {
michaelt6e5b2192017-02-22 07:33:27 -0800258 analyzer.CreateAudioEncoderNumChannelsGraph(collection->AppendNewPlot());
259 }
terelius2ee076d2017-08-15 02:04:02 -0700260 if (FLAG_plot_audio_jitter_buffer) {
owb7fbeb0b2017-08-16 02:48:33 -0700261 std::string wav_path;
262 if (FLAG_wav_filename[0] != '\0') {
263 wav_path = FLAG_wav_filename;
264 } else {
265 wav_path = webrtc::test::ResourcePath(
266 "audio_processing/conversational_speech/EN_script2_F_sp2_B1", "wav");
267 }
268 analyzer.CreateAudioJitterBufferGraph(wav_path, 48000,
269 collection->AppendNewPlot());
henrik.lundin3c938fc2017-06-14 06:09:58 -0700270 }
271
tereliusdc35dcd2016-08-01 12:03:27 -0700272 collection->Draw();
terelius54ce6802016-07-13 06:44:41 -0700273
274 return 0;
275}
terelius2ee076d2017-08-15 02:04:02 -0700276
277
278void SetAllPlotFlags(bool setting) {
279 FLAG_plot_incoming_packet_sizes = setting;
280 FLAG_plot_outgoing_packet_sizes = setting;
281 FLAG_plot_incoming_packet_count = setting;
282 FLAG_plot_outgoing_packet_count = setting;
283 FLAG_plot_audio_playout = setting;
284 FLAG_plot_audio_level = setting;
285 FLAG_plot_incoming_sequence_number_delta = setting;
286 FLAG_plot_incoming_delay_delta = setting;
287 FLAG_plot_incoming_delay = setting;
288 FLAG_plot_incoming_loss_rate = setting;
289 FLAG_plot_incoming_bitrate = setting;
290 FLAG_plot_outgoing_bitrate = setting;
291 FLAG_plot_incoming_stream_bitrate = setting;
292 FLAG_plot_outgoing_stream_bitrate = setting;
293 FLAG_plot_simulated_sendside_bwe = setting;
294 FLAG_plot_network_delay_feedback = setting;
295 FLAG_plot_fraction_loss_feedback = setting;
296 FLAG_plot_timestamps = setting;
297 FLAG_plot_audio_encoder_bitrate_bps = setting;
298 FLAG_plot_audio_encoder_frame_length_ms = setting;
299 FLAG_plot_audio_encoder_packet_loss = setting;
300 FLAG_plot_audio_encoder_fec = setting;
301 FLAG_plot_audio_encoder_dtx = setting;
302 FLAG_plot_audio_encoder_num_channels = setting;
303 FLAG_plot_audio_jitter_buffer = setting;
304}