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}
diff --git a/webrtc/tools/event_log_visualizer/analyzer.cc b/webrtc/tools/event_log_visualizer/analyzer.cc
index 0d2483e..ff5a5b4 100644
--- a/webrtc/tools/event_log_visualizer/analyzer.cc
+++ b/webrtc/tools/event_log_visualizer/analyzer.cc
@@ -582,7 +582,7 @@
           return rtc::Optional<float>(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 @@
       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 @@
   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 @@
   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 @@
           return rtc::Optional<float>(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 @@
         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 @@
     ProcessPairs<LoggedRtpPacket, double>(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<LoggedRtpPacket, double>(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 @@
     AccumulatePairs<LoggedRtpPacket, double>(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<LoggedRtpPacket, double>(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 @@
 
 // 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<float>(bwe_update.timestamp - begin_time_) / 1000000;
     float y = static_cast<float>(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 @@
   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 @@
         static_cast<float>(window_duration_) / 1000000;
     float x = static_cast<float>(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<float>(loss_update.timestamp - begin_time_) / 1000000;
       float y = static_cast<float>(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<float>(delay_update.timestamp - begin_time_) / 1000000;
       float y = static_cast<float>(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<float>(cluster.timestamp - begin_time_) / 1000000;
       float y = static_cast<float>(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<float>(result.timestamp - begin_time_) / 1000000;
         float y = static_cast<float>(*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 @@
         },
         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 @@
     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 @@
   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 @@
         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 @@
           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::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<AudioNetworkAdaptationEvent>(
       [](const AudioNetworkAdaptationEvent& ana_event) -> rtc::Optional<float> {
         if (ana_event.config.bitrate_bps)
@@ -1303,15 +1303,15 @@
               static_cast<float>(*ana_event.config.bitrate_bps));
         return rtc::Optional<float>();
       },
-      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<AudioNetworkAdaptationEvent>(
       [](const AudioNetworkAdaptationEvent& ana_event) {
         if (ana_event.config.frame_length_ms)
@@ -1319,7 +1319,8 @@
               static_cast<float>(*ana_event.config.frame_length_ms));
         return rtc::Optional<float>();
       },
-      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::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<AudioNetworkAdaptationEvent>(
       [](const AudioNetworkAdaptationEvent& ana_event) {
         if (ana_event.config.uplink_packet_loss_fraction)
@@ -1336,7 +1337,8 @@
               *ana_event.config.uplink_packet_loss_fraction));
         return rtc::Optional<float>();
       },
-      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::CreateAudioEncoderEnableFecGraph(Plot* plot) {
-  TimeSeries* time_series =
-      plot->AddTimeSeries("Audio encoder FEC", LINE_DOT_GRAPH);
+  TimeSeries time_series("Audio encoder FEC", LINE_DOT_GRAPH);
   ProcessPoints<AudioNetworkAdaptationEvent>(
       [](const AudioNetworkAdaptationEvent& ana_event) {
         if (ana_event.config.enable_fec)
@@ -1353,15 +1354,15 @@
               static_cast<float>(*ana_event.config.enable_fec));
         return rtc::Optional<float>();
       },
-      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<AudioNetworkAdaptationEvent>(
       [](const AudioNetworkAdaptationEvent& ana_event) {
         if (ana_event.config.enable_dtx)
@@ -1369,15 +1370,15 @@
               static_cast<float>(*ana_event.config.enable_dtx));
         return rtc::Optional<float>();
       },
-      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<AudioNetworkAdaptationEvent>(
       [](const AudioNetworkAdaptationEvent& ana_event) {
         if (ana_event.config.num_channels)
@@ -1385,7 +1386,8 @@
               static_cast<float>(*ana_event.config.num_channels));
         return rtc::Optional<float>();
       },
-      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);