From 35ba9bd5970f91cdb1513a21694cb8fd78de5308 Mon Sep 17 00:00:00 2001 From: philipel Date: Wed, 19 Apr 2017 05:58:51 -0700 Subject: [PATCH] Event log visualizer TimeSeries is now created on the stack and then moved into the vector of series. BUG=none Review-Url: https://codereview.webrtc.org/2824973003 Cr-Commit-Position: refs/heads/master@{#17763} --- webrtc/tools/event_log_visualizer/analyzer.cc | 104 +++++++++--------- .../tools/event_log_visualizer/plot_base.cc | 10 +- webrtc/tools/event_log_visualizer/plot_base.h | 11 +- .../tools/event_log_visualizer/plot_python.cc | 1 + 4 files changed, 60 insertions(+), 66 deletions(-) diff --git a/webrtc/tools/event_log_visualizer/analyzer.cc b/webrtc/tools/event_log_visualizer/analyzer.cc index 0d2483e24d..ff5a5b40fe 100644 --- a/webrtc/tools/event_log_visualizer/analyzer.cc +++ b/webrtc/tools/event_log_visualizer/analyzer.cc @@ -582,7 +582,7 @@ void EventLogAnalyzer::CreatePacketGraph(PacketDirection desired_direction, return rtc::Optional(packet.total_length); }, packet_stream, begin_time_, &time_series); - plot->series_list_.push_back(std::move(time_series)); + plot->AppendTimeSeries(std::move(time_series)); } plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); @@ -618,7 +618,7 @@ void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries( time_series.points.emplace_back(x, i + 1); } - plot->series_list_.push_back(std::move(time_series)); + plot->AppendTimeSeries(std::move(time_series)); } } @@ -669,7 +669,7 @@ void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) { for (auto& kv : time_series) { kv.second.label = SsrcToString(kv.first); kv.second.style = BAR_GRAPH; - plot->series_list_.push_back(std::move(kv.second)); + plot->AppendTimeSeries(std::move(kv.second)); } plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); @@ -702,7 +702,7 @@ void EventLogAnalyzer::CreateAudioLevelGraph(Plot* plot) { for (auto& series : time_series) { series.second.label = GetStreamName(series.first); series.second.style = LINE_GRAPH; - plot->series_list_.push_back(std::move(series.second)); + plot->AppendTimeSeries(std::move(series.second)); } plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); @@ -732,7 +732,7 @@ void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) { return rtc::Optional(diff); }, packet_stream, begin_time_, &time_series); - plot->series_list_.push_back(std::move(time_series)); + plot->AppendTimeSeries(std::move(time_series)); } plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); @@ -789,7 +789,7 @@ void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) { time_series.points.emplace_back(x, y); } } - plot->series_list_.push_back(std::move(time_series)); + plot->AppendTimeSeries(std::move(time_series)); } plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); @@ -815,14 +815,14 @@ void EventLogAnalyzer::CreateDelayChangeGraph(Plot* plot) { ProcessPairs(NetworkDelayDiff_CaptureTime, packet_stream, begin_time_, &capture_time_data); - plot->series_list_.push_back(std::move(capture_time_data)); + plot->AppendTimeSeries(std::move(capture_time_data)); TimeSeries send_time_data(GetStreamName(stream_id) + " abs-send-time", BAR_GRAPH); ProcessPairs(NetworkDelayDiff_AbsSendTime, packet_stream, begin_time_, &send_time_data); - plot->series_list_.push_back(std::move(send_time_data)); + plot->AppendTimeSeries(std::move(send_time_data)); } plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); @@ -848,14 +848,14 @@ void EventLogAnalyzer::CreateAccumulatedDelayChangeGraph(Plot* plot) { AccumulatePairs(NetworkDelayDiff_CaptureTime, packet_stream, begin_time_, &capture_time_data); - plot->series_list_.push_back(std::move(capture_time_data)); + plot->AppendTimeSeries(std::move(capture_time_data)); TimeSeries send_time_data(GetStreamName(stream_id) + " abs-send-time", LINE_GRAPH); AccumulatePairs(NetworkDelayDiff_AbsSendTime, packet_stream, begin_time_, &send_time_data); - plot->series_list_.push_back(std::move(send_time_data)); + plot->AppendTimeSeries(std::move(send_time_data)); } plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); @@ -866,18 +866,18 @@ void EventLogAnalyzer::CreateAccumulatedDelayChangeGraph(Plot* plot) { // Plot the fraction of packets lost (as perceived by the loss-based BWE). void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) { - TimeSeries* time_series = - plot->AddTimeSeries("Fraction lost", LINE_DOT_GRAPH); + TimeSeries time_series("Fraction lost", LINE_DOT_GRAPH); for (auto& bwe_update : bwe_loss_updates_) { float x = static_cast(bwe_update.timestamp - begin_time_) / 1000000; float y = static_cast(bwe_update.fraction_loss) / 255 * 100; - time_series->points.emplace_back(x, y); + time_series.points.emplace_back(x, y); } plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin, kTopMargin); plot->SetTitle("Reported packet loss"); + plot->AppendTimeSeries(std::move(time_series)); } // Plot the total bandwidth used by all RTP streams. @@ -912,7 +912,7 @@ void EventLogAnalyzer::CreateTotalBitrateGraph( size_t bytes_in_window = 0; // Calculate a moving average of the bitrate and store in a TimeSeries. - TimeSeries* time_series = plot->AddTimeSeries("Bitrate", LINE_GRAPH); + TimeSeries bitrate_series("Bitrate", LINE_GRAPH); for (uint64_t time = begin_time_; time < end_time_ + step_; time += step_) { while (window_index_end < packets.size() && packets[window_index_end].timestamp < time) { @@ -929,46 +929,47 @@ void EventLogAnalyzer::CreateTotalBitrateGraph( static_cast(window_duration_) / 1000000; float x = static_cast(time - begin_time_) / 1000000; float y = bytes_in_window * 8 / window_duration_in_seconds / 1000; - time_series->points.emplace_back(x, y); + bitrate_series.points.emplace_back(x, y); } + plot->AppendTimeSeries(std::move(bitrate_series)); // Overlay the send-side bandwidth estimate over the outgoing bitrate. if (desired_direction == kOutgoingPacket) { - TimeSeries* loss_series = - plot->AddTimeSeries("Loss-based estimate", LINE_STEP_GRAPH); + TimeSeries loss_series("Loss-based estimate", LINE_STEP_GRAPH); for (auto& loss_update : bwe_loss_updates_) { float x = static_cast(loss_update.timestamp - begin_time_) / 1000000; float y = static_cast(loss_update.new_bitrate) / 1000; - loss_series->points.emplace_back(x, y); + loss_series.points.emplace_back(x, y); } - TimeSeries* delay_series = - plot->AddTimeSeries("Delay-based estimate", LINE_STEP_GRAPH); + TimeSeries delay_series("Delay-based estimate", LINE_STEP_GRAPH); for (auto& delay_update : bwe_delay_updates_) { float x = static_cast(delay_update.timestamp - begin_time_) / 1000000; float y = static_cast(delay_update.bitrate_bps) / 1000; - delay_series->points.emplace_back(x, y); + delay_series.points.emplace_back(x, y); } - TimeSeries* created_series = - plot->AddTimeSeries("Probe cluster created.", DOT_GRAPH); + TimeSeries created_series("Probe cluster created.", DOT_GRAPH); for (auto& cluster : bwe_probe_cluster_created_events_) { float x = static_cast(cluster.timestamp - begin_time_) / 1000000; float y = static_cast(cluster.bitrate_bps) / 1000; - created_series->points.emplace_back(x, y); + created_series.points.emplace_back(x, y); } - TimeSeries* result_series = - plot->AddTimeSeries("Probing results.", DOT_GRAPH); + TimeSeries result_series("Probing results.", DOT_GRAPH); for (auto& result : bwe_probe_result_events_) { if (result.bitrate_bps) { float x = static_cast(result.timestamp - begin_time_) / 1000000; float y = static_cast(*result.bitrate_bps) / 1000; - result_series->points.emplace_back(x, y); + result_series.points.emplace_back(x, y); } } + plot->AppendTimeSeries(std::move(loss_series)); + plot->AppendTimeSeries(std::move(delay_series)); + plot->AppendTimeSeries(std::move(created_series)); + plot->AppendTimeSeries(std::move(result_series)); } plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); @@ -1000,7 +1001,7 @@ void EventLogAnalyzer::CreateStreamBitrateGraph( }, packet_stream, begin_time_, end_time_, window_duration_, step_, &time_series); - plot->series_list_.push_back(std::move(time_series)); + plot->AppendTimeSeries(std::move(time_series)); } plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); @@ -1126,8 +1127,8 @@ void EventLogAnalyzer::CreateBweSimulationGraph(Plot* plot) { time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()}); } // Add the data set to the plot. - plot->series_list_.push_back(std::move(time_series)); - plot->series_list_.push_back(std::move(acked_time_series)); + plot->AppendTimeSeries(std::move(time_series)); + plot->AppendTimeSeries(std::move(acked_time_series)); plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin); @@ -1217,7 +1218,7 @@ void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) { for (TimeSeriesPoint& point : time_series.points) point.y -= estimated_base_delay_ms; // Add the data set to the plot. - plot->series_list_.push_back(std::move(time_series)); + plot->AppendTimeSeries(std::move(time_series)); plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin); @@ -1265,7 +1266,7 @@ void EventLogAnalyzer::CreateTimestampGraph(Plot* plot) { float y = packet.header.timestamp; timestamp_data.points.emplace_back(x, y); } - plot->series_list_.push_back(std::move(timestamp_data)); + plot->AppendTimeSeries(std::move(timestamp_data)); } { @@ -1283,7 +1284,7 @@ void EventLogAnalyzer::CreateTimestampGraph(Plot* plot) { float y = sr->rtp_timestamp(); timestamp_data.points.emplace_back(x, y); } - plot->series_list_.push_back(std::move(timestamp_data)); + plot->AppendTimeSeries(std::move(timestamp_data)); } } } @@ -1294,8 +1295,7 @@ void EventLogAnalyzer::CreateTimestampGraph(Plot* plot) { } void EventLogAnalyzer::CreateAudioEncoderTargetBitrateGraph(Plot* plot) { - TimeSeries* time_series = - plot->AddTimeSeries("Audio encoder target bitrate", LINE_DOT_GRAPH); + TimeSeries time_series("Audio encoder target bitrate", LINE_DOT_GRAPH); ProcessPoints( [](const AudioNetworkAdaptationEvent& ana_event) -> rtc::Optional { if (ana_event.config.bitrate_bps) @@ -1303,15 +1303,15 @@ void EventLogAnalyzer::CreateAudioEncoderTargetBitrateGraph(Plot* plot) { static_cast(*ana_event.config.bitrate_bps)); return rtc::Optional(); }, - audio_network_adaptation_events_, begin_time_, time_series); + audio_network_adaptation_events_, begin_time_, &time_series); + plot->AppendTimeSeries(std::move(time_series)); plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); plot->SetSuggestedYAxis(0, 1, "Bitrate (bps)", kBottomMargin, kTopMargin); plot->SetTitle("Reported audio encoder target bitrate"); } void EventLogAnalyzer::CreateAudioEncoderFrameLengthGraph(Plot* plot) { - TimeSeries* time_series = - plot->AddTimeSeries("Audio encoder frame length", LINE_DOT_GRAPH); + TimeSeries time_series("Audio encoder frame length", LINE_DOT_GRAPH); ProcessPoints( [](const AudioNetworkAdaptationEvent& ana_event) { if (ana_event.config.frame_length_ms) @@ -1319,7 +1319,8 @@ void EventLogAnalyzer::CreateAudioEncoderFrameLengthGraph(Plot* plot) { static_cast(*ana_event.config.frame_length_ms)); return rtc::Optional(); }, - audio_network_adaptation_events_, begin_time_, time_series); + audio_network_adaptation_events_, begin_time_, &time_series); + plot->AppendTimeSeries(std::move(time_series)); plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); plot->SetSuggestedYAxis(0, 1, "Frame length (ms)", kBottomMargin, kTopMargin); plot->SetTitle("Reported audio encoder frame length"); @@ -1327,8 +1328,8 @@ void EventLogAnalyzer::CreateAudioEncoderFrameLengthGraph(Plot* plot) { void EventLogAnalyzer::CreateAudioEncoderUplinkPacketLossFractionGraph( Plot* plot) { - TimeSeries* time_series = plot->AddTimeSeries( - "Audio encoder uplink packet loss fraction", LINE_DOT_GRAPH); + TimeSeries time_series("Audio encoder uplink packet loss fraction", + LINE_DOT_GRAPH); ProcessPoints( [](const AudioNetworkAdaptationEvent& ana_event) { if (ana_event.config.uplink_packet_loss_fraction) @@ -1336,7 +1337,8 @@ void EventLogAnalyzer::CreateAudioEncoderUplinkPacketLossFractionGraph( *ana_event.config.uplink_packet_loss_fraction)); return rtc::Optional(); }, - audio_network_adaptation_events_, begin_time_, time_series); + audio_network_adaptation_events_, begin_time_, &time_series); + plot->AppendTimeSeries(std::move(time_series)); plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin, kTopMargin); @@ -1344,8 +1346,7 @@ void EventLogAnalyzer::CreateAudioEncoderUplinkPacketLossFractionGraph( } void EventLogAnalyzer::CreateAudioEncoderEnableFecGraph(Plot* plot) { - TimeSeries* time_series = - plot->AddTimeSeries("Audio encoder FEC", LINE_DOT_GRAPH); + TimeSeries time_series("Audio encoder FEC", LINE_DOT_GRAPH); ProcessPoints( [](const AudioNetworkAdaptationEvent& ana_event) { if (ana_event.config.enable_fec) @@ -1353,15 +1354,15 @@ void EventLogAnalyzer::CreateAudioEncoderEnableFecGraph(Plot* plot) { static_cast(*ana_event.config.enable_fec)); return rtc::Optional(); }, - audio_network_adaptation_events_, begin_time_, time_series); + audio_network_adaptation_events_, begin_time_, &time_series); + plot->AppendTimeSeries(std::move(time_series)); plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); plot->SetSuggestedYAxis(0, 1, "FEC (false/true)", kBottomMargin, kTopMargin); plot->SetTitle("Reported audio encoder FEC"); } void EventLogAnalyzer::CreateAudioEncoderEnableDtxGraph(Plot* plot) { - TimeSeries* time_series = - plot->AddTimeSeries("Audio encoder DTX", LINE_DOT_GRAPH); + TimeSeries time_series("Audio encoder DTX", LINE_DOT_GRAPH); ProcessPoints( [](const AudioNetworkAdaptationEvent& ana_event) { if (ana_event.config.enable_dtx) @@ -1369,15 +1370,15 @@ void EventLogAnalyzer::CreateAudioEncoderEnableDtxGraph(Plot* plot) { static_cast(*ana_event.config.enable_dtx)); return rtc::Optional(); }, - audio_network_adaptation_events_, begin_time_, time_series); + audio_network_adaptation_events_, begin_time_, &time_series); + plot->AppendTimeSeries(std::move(time_series)); plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); plot->SetSuggestedYAxis(0, 1, "DTX (false/true)", kBottomMargin, kTopMargin); plot->SetTitle("Reported audio encoder DTX"); } void EventLogAnalyzer::CreateAudioEncoderNumChannelsGraph(Plot* plot) { - TimeSeries* time_series = - plot->AddTimeSeries("Audio encoder number of channels", LINE_DOT_GRAPH); + TimeSeries time_series("Audio encoder number of channels", LINE_DOT_GRAPH); ProcessPoints( [](const AudioNetworkAdaptationEvent& ana_event) { if (ana_event.config.num_channels) @@ -1385,7 +1386,8 @@ void EventLogAnalyzer::CreateAudioEncoderNumChannelsGraph(Plot* plot) { static_cast(*ana_event.config.num_channels)); return rtc::Optional(); }, - audio_network_adaptation_events_, begin_time_, time_series); + audio_network_adaptation_events_, begin_time_, &time_series); + plot->AppendTimeSeries(std::move(time_series)); plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin); plot->SetSuggestedYAxis(0, 1, "Number of channels (1 (mono)/2 (stereo))", kBottomMargin, kTopMargin); diff --git a/webrtc/tools/event_log_visualizer/plot_base.cc b/webrtc/tools/event_log_visualizer/plot_base.cc index baee3dfeee..057a3108a4 100644 --- a/webrtc/tools/event_log_visualizer/plot_base.cc +++ b/webrtc/tools/event_log_visualizer/plot_base.cc @@ -71,14 +71,8 @@ void Plot::SetTitle(std::string title) { title_ = title; } -TimeSeries* Plot::AddTimeSeries(const char* label, PlotStyle style) { - series_list_.emplace_back(label, style); - return &series_list_.back(); -} - -TimeSeries* Plot::AddTimeSeries(const std::string& label, PlotStyle style) { - series_list_.emplace_back(label, style); - return &series_list_.back(); +void Plot::AppendTimeSeries(TimeSeries&& time_series) { + series_list_.emplace_back(std::move(time_series)); } } // namespace plotting diff --git a/webrtc/tools/event_log_visualizer/plot_base.h b/webrtc/tools/event_log_visualizer/plot_base.h index b2ab299a58..afa20beaf8 100644 --- a/webrtc/tools/event_log_visualizer/plot_base.h +++ b/webrtc/tools/event_log_visualizer/plot_base.h @@ -34,10 +34,9 @@ struct TimeSeriesPoint { struct TimeSeries { TimeSeries() = default; - TimeSeries(const char* label, PlotStyle style) - : label(label), style(style), points() {} + TimeSeries(const char* label, PlotStyle style) : label(label), style(style) {} TimeSeries(const std::string& label, PlotStyle style) - : label(label), style(style), points() {} + : label(label), style(style) {} TimeSeries(TimeSeries&& other) : label(std::move(other.label)), style(other.style), @@ -108,10 +107,7 @@ class Plot { void SetTitle(std::string title); // Add a new TimeSeries to the plot. - TimeSeries* AddTimeSeries(const char* label, PlotStyle style); - TimeSeries* AddTimeSeries(const std::string& label, PlotStyle style); - - std::vector series_list_; + void AppendTimeSeries(TimeSeries&& time_series); protected: float xaxis_min_; @@ -121,6 +117,7 @@ class Plot { float yaxis_max_; std::string yaxis_label_; std::string title_; + std::vector series_list_; }; class PlotCollection { diff --git a/webrtc/tools/event_log_visualizer/plot_python.cc b/webrtc/tools/event_log_visualizer/plot_python.cc index 2b37280a42..59270a0b95 100644 --- a/webrtc/tools/event_log_visualizer/plot_python.cc +++ b/webrtc/tools/event_log_visualizer/plot_python.cc @@ -33,6 +33,7 @@ void PythonPlot::Draw() { printf("rgb_colors = [colorsys.hls_to_rgb(*hls) for hls in hls_colors]\n"); for (size_t i = 0; i < series_list_.size(); i++) { + printf("\n# === Series: %s ===\n", series_list_[i].label.c_str()); // List x coordinates printf("x%zu = [", i); if (series_list_[i].points.size() > 0)