Enable BWE logging to command line when rtc_enable_bwe_test_logging is set to true

This patch enables bwe related variable logging to the command line.
This is useful to test congestion control algorithm over real networks.

NOTRY=true

Review-Url: https://codereview.webrtc.org/2296253002
Cr-Commit-Position: refs/heads/master@{#14209}
diff --git a/webrtc/build/webrtc.gni b/webrtc/build/webrtc.gni
index 3c84363..0a851de 100644
--- a/webrtc/build/webrtc.gni
+++ b/webrtc/build/webrtc.gni
@@ -45,6 +45,9 @@
   # should be generated.
   apm_debug_dump = false
 
+  # Set this to true to enable BWE test logging.
+  rtc_enable_bwe_test_logging = false
+
   # Disable these to not build components which can be externally provided.
   rtc_build_expat = true
   rtc_build_json = true
diff --git a/webrtc/modules/bitrate_controller/BUILD.gn b/webrtc/modules/bitrate_controller/BUILD.gn
index 2d3dff3..0440418 100644
--- a/webrtc/modules/bitrate_controller/BUILD.gn
+++ b/webrtc/modules/bitrate_controller/BUILD.gn
@@ -18,6 +18,12 @@
     "send_side_bandwidth_estimation.h",
   ]
 
+  if (rtc_enable_bwe_test_logging) {
+    defines = [ "BWE_TEST_LOGGING_COMPILE_TIME_ENABLE=1" ]
+  } else {
+    defines = [ "BWE_TEST_LOGGING_COMPILE_TIME_ENABLE=0" ]
+  }
+
   # TODO(jschuh): Bug 1348: fix this warning.
   configs += [ "//build/config/compiler:no_size_t_to_int_warning" ]
 
diff --git a/webrtc/modules/bitrate_controller/bitrate_controller.gypi b/webrtc/modules/bitrate_controller/bitrate_controller.gypi
index 3d86f2e..82121cd 100644
--- a/webrtc/modules/bitrate_controller/bitrate_controller.gypi
+++ b/webrtc/modules/bitrate_controller/bitrate_controller.gypi
@@ -21,6 +21,13 @@
         'send_side_bandwidth_estimation.cc',
         'send_side_bandwidth_estimation.h',
       ],
+      'conditions': [
+        ['enable_bwe_test_logging==1', {
+          'defines': [ 'BWE_TEST_LOGGING_COMPILE_TIME_ENABLE=1' ],
+        }, {
+          'defines': [ 'BWE_TEST_LOGGING_COMPILE_TIME_ENABLE=0' ],
+        }],
+      ],
       # TODO(jschuh): Bug 1348: fix size_t to int truncations.
       'msvs_disabled_warnings': [ 4267, ],
     },
diff --git a/webrtc/modules/bitrate_controller/bitrate_controller_impl.cc b/webrtc/modules/bitrate_controller/bitrate_controller_impl.cc
index e94baa7..bc2f1f6 100644
--- a/webrtc/modules/bitrate_controller/bitrate_controller_impl.cc
+++ b/webrtc/modules/bitrate_controller/bitrate_controller_impl.cc
@@ -17,6 +17,7 @@
 
 #include "webrtc/base/checks.h"
 #include "webrtc/base/logging.h"
+#include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h"
 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
 
 namespace webrtc {
@@ -179,6 +180,8 @@
     rtc::CritScope cs(&critsect_);
     bandwidth_estimation_.UpdateReceiverEstimate(clock_->TimeInMilliseconds(),
                                                  bitrate);
+    BWE_TEST_LOGGING_PLOT(1, "REMB[kbps]", clock_->TimeInMilliseconds(),
+                          bitrate / 1000);
   }
   MaybeTriggerOnNetworkChanged();
 }
@@ -269,6 +272,14 @@
     last_reserved_bitrate_bps_ = reserved_bitrate_bps_;
     new_bitrate = true;
   }
+
+  BWE_TEST_LOGGING_PLOT(1, "fraction_loss_[%%]", clock_->TimeInMilliseconds(),
+                        (last_fraction_loss_ * 100) / 256);
+  BWE_TEST_LOGGING_PLOT(1, "rtt[ms]", clock_->TimeInMilliseconds(),
+                        last_rtt_ms_);
+  BWE_TEST_LOGGING_PLOT(1, "Target_bitrate[kbps]", clock_->TimeInMilliseconds(),
+                        last_bitrate_bps_ / 1000);
+
   return new_bitrate;
 }
 
diff --git a/webrtc/modules/congestion_controller/delay_based_bwe.cc b/webrtc/modules/congestion_controller/delay_based_bwe.cc
index b7a21be..87dc502 100644
--- a/webrtc/modules/congestion_controller/delay_based_bwe.cc
+++ b/webrtc/modules/congestion_controller/delay_based_bwe.cc
@@ -104,7 +104,8 @@
                                       info.payload_size, &ts_delta, &t_delta,
                                       &size_delta)) {
       double ts_delta_ms = (1000.0 * ts_delta) / (1 << kInterArrivalShift);
-      estimator_->Update(t_delta, ts_delta_ms, size_delta, detector_.State());
+      estimator_->Update(t_delta, ts_delta_ms, size_delta, detector_.State(),
+                         info.arrival_time_ms);
       detector_.Detect(estimator_->offset(), ts_delta_ms,
                        estimator_->num_of_deltas(), info.arrival_time_ms);
     }
diff --git a/webrtc/modules/remote_bitrate_estimator/BUILD.gn b/webrtc/modules/remote_bitrate_estimator/BUILD.gn
index c3c66eb..1e42ce9 100644
--- a/webrtc/modules/remote_bitrate_estimator/BUILD.gn
+++ b/webrtc/modules/remote_bitrate_estimator/BUILD.gn
@@ -8,11 +8,6 @@
 
 import("../../build/webrtc.gni")
 
-declare_args() {
-  # Set this to true to enable BWE test logging.
-  rtc_enable_bwe_test_logging = false
-}
-
 rtc_source_set("remote_bitrate_estimator") {
   sources = [
     "aimd_rate_control.cc",
@@ -39,11 +34,13 @@
     "transport_feedback_adapter.h",
   ]
 
-  if (rtc_enable_bwe_test_logging) {
-    defines = [ "BWE_TEST_LOGGING_COMPILE_TIME_ENABLE=1" ]
-    sources += [ "test/bwe_test_logging.cc" ]
-  } else {
-    defines = [ "BWE_TEST_LOGGING_COMPILE_TIME_ENABLE=0" ]
+  if (!rtc_include_tests) {
+    if (rtc_enable_bwe_test_logging) {
+      defines = [ "BWE_TEST_LOGGING_COMPILE_TIME_ENABLE=1" ]
+      sources += [ "test/bwe_test_logging.cc" ]
+    } else {
+      defines = [ "BWE_TEST_LOGGING_COMPILE_TIME_ENABLE=0" ]
+    }
   }
 
   if (is_clang) {
@@ -62,6 +59,7 @@
   rtc_source_set("bwe_simulator") {
     testonly = true
     sources = [
+      "bwe_simulations.cc",
       "test/bwe.cc",
       "test/bwe.h",
       "test/bwe_test.cc",
diff --git a/webrtc/modules/remote_bitrate_estimator/overuse_detector.cc b/webrtc/modules/remote_bitrate_estimator/overuse_detector.cc
index 477fc15..05f44ac 100644
--- a/webrtc/modules/remote_bitrate_estimator/overuse_detector.cc
+++ b/webrtc/modules/remote_bitrate_estimator/overuse_detector.cc
@@ -36,6 +36,7 @@
 
 const double kMaxAdaptOffsetMs = 15.0;
 const double kOverUsingTimeThreshold = 10;
+const int kMinNumDeltas = 60;
 
 bool AdaptiveThresholdExperimentIsDisabled() {
   std::string experiment_string =
@@ -92,9 +93,9 @@
   }
   const double prev_offset = prev_offset_;
   prev_offset_ = offset;
-  const double T = std::min(num_of_deltas, 60) * offset;
-  BWE_TEST_LOGGING_PLOT(1, "offset", now_ms, T);
-  BWE_TEST_LOGGING_PLOT(1, "threshold", now_ms, threshold_);
+  const double T = std::min(num_of_deltas, kMinNumDeltas) * offset;
+  BWE_TEST_LOGGING_PLOT(1, "offset[ms]", now_ms, offset);
+  BWE_TEST_LOGGING_PLOT(1, "gamma[ms]", now_ms, threshold_ / kMinNumDeltas);
   if (T > threshold_) {
     if (time_over_using_ == -1) {
       // Initialize the timer. Assume that we've been
diff --git a/webrtc/modules/remote_bitrate_estimator/overuse_detector_unittest.cc b/webrtc/modules/remote_bitrate_estimator/overuse_detector_unittest.cc
index 9f42d9f..6f3f3e7 100644
--- a/webrtc/modules/remote_bitrate_estimator/overuse_detector_unittest.cc
+++ b/webrtc/modules/remote_bitrate_estimator/overuse_detector_unittest.cc
@@ -100,7 +100,7 @@
             &timestamp_delta, &time_delta, &size_delta)) {
       double timestamp_delta_ms = timestamp_delta / 90.0;
       overuse_estimator_->Update(time_delta, timestamp_delta_ms, size_delta,
-                                 overuse_detector_->State());
+                                 overuse_detector_->State(), receive_time_ms);
       overuse_detector_->Detect(
           overuse_estimator_->offset(), timestamp_delta_ms,
           overuse_estimator_->num_of_deltas(), receive_time_ms);
diff --git a/webrtc/modules/remote_bitrate_estimator/overuse_estimator.cc b/webrtc/modules/remote_bitrate_estimator/overuse_estimator.cc
index 8391791..5535fe3 100644
--- a/webrtc/modules/remote_bitrate_estimator/overuse_estimator.cc
+++ b/webrtc/modules/remote_bitrate_estimator/overuse_estimator.cc
@@ -19,6 +19,7 @@
 
 #include "webrtc/base/logging.h"
 #include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h"
+#include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h"
 
 namespace webrtc {
 
@@ -48,9 +49,11 @@
 void OveruseEstimator::Update(int64_t t_delta,
                               double ts_delta,
                               int size_delta,
-                              BandwidthUsage current_hypothesis) {
+                              BandwidthUsage current_hypothesis,
+                              int64_t now_ms) {
   const double min_frame_period = UpdateMinFramePeriod(ts_delta);
   const double t_ts_delta = t_delta - ts_delta;
+  BWE_TEST_LOGGING_PLOT(1, "dm[ms]", now_ms, t_ts_delta);
   double fs_delta = size_delta;
 
   ++num_of_deltas_;
@@ -71,6 +74,8 @@
   const double Eh[2] = {E_[0][0]*h[0] + E_[0][1]*h[1],
                         E_[1][0]*h[0] + E_[1][1]*h[1]};
 
+  BWE_TEST_LOGGING_PLOT(1, "d[ms]", now_ms, slope_ * h[0] - offset_);
+
   const double residual = t_ts_delta - slope_*h[0] - offset_;
 
   const bool in_stable_state = (current_hypothesis == kBwNormal);
@@ -112,6 +117,11 @@
   slope_ = slope_ + K[0] * residual;
   prev_offset_ = offset_;
   offset_ = offset_ + K[1] * residual;
+
+  BWE_TEST_LOGGING_PLOT(1, "kc", now_ms, K[0]);
+  BWE_TEST_LOGGING_PLOT(1, "km", now_ms, K[1]);
+  BWE_TEST_LOGGING_PLOT(1, "slope[1/bps]", now_ms, slope_);
+  BWE_TEST_LOGGING_PLOT(1, "var_noise", now_ms, var_noise_);
 }
 
 double OveruseEstimator::UpdateMinFramePeriod(double ts_delta) {
diff --git a/webrtc/modules/remote_bitrate_estimator/overuse_estimator.h b/webrtc/modules/remote_bitrate_estimator/overuse_estimator.h
index d671f39..dd8efaa 100644
--- a/webrtc/modules/remote_bitrate_estimator/overuse_estimator.h
+++ b/webrtc/modules/remote_bitrate_estimator/overuse_estimator.h
@@ -27,8 +27,11 @@
   // between timestamp groups as defined by the InterArrival class.
   // |current_hypothesis| should be the hypothesis of the over-use detector at
   // this time.
-  void Update(int64_t t_delta, double ts_delta, int size_delta,
-              BandwidthUsage current_hypothesis);
+  void Update(int64_t t_delta,
+              double ts_delta,
+              int size_delta,
+              BandwidthUsage current_hypothesis,
+              int64_t now_ms);
 
   // Returns the estimated noise/jitter variance in ms^2.
   double var_noise() const {
diff --git a/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator.gypi b/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator.gypi
index 7978576..1823617 100644
--- a/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator.gypi
+++ b/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator.gypi
@@ -10,10 +10,6 @@
   'includes': [
     '../../build/common.gypi',
   ],
-  'variables': {
-    # Set this to true to enable BWE test logging.
-    'enable_bwe_test_logging%': 0,
-  },
   'targets': [
     {
       'target_name': 'remote_bitrate_estimator',
@@ -47,13 +43,17 @@
         'test/bwe_test_logging.h',
       ], # source
       'conditions': [
-        ['enable_bwe_test_logging==1', {
-          'defines': [ 'BWE_TEST_LOGGING_COMPILE_TIME_ENABLE=1' ],
-          'sources': [
-            'test/bwe_test_logging.cc'
+        ['include_tests==0', {
+          'conditions': [
+            ['enable_bwe_test_logging==1', {
+              'defines': [ 'BWE_TEST_LOGGING_COMPILE_TIME_ENABLE=1' ],
+              'sources': [
+                'test/bwe_test_logging.cc'
+              ],
+            }, {
+              'defines': [ 'BWE_TEST_LOGGING_COMPILE_TIME_ENABLE=0' ],
+            }],
           ],
-        }, {
-          'defines': [ 'BWE_TEST_LOGGING_COMPILE_TIME_ENABLE=0' ],
         }],
       ],
     },
@@ -71,6 +71,7 @@
             '<(DEPTH)/testing/gmock.gyp:gmock',
           ],
           'sources': [
+            'bwe_simulations.cc',
             'test/bwe.cc',
             'test/bwe.h',
             'test/bwe_test.cc',
diff --git a/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.cc b/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.cc
index 786223f..93344dd 100644
--- a/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.cc
+++ b/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.cc
@@ -313,7 +313,8 @@
                                       payload_size, &ts_delta, &t_delta,
                                       &size_delta)) {
       double ts_delta_ms = (1000.0 * ts_delta) / (1 << kInterArrivalShift);
-      estimator_->Update(t_delta, ts_delta_ms, size_delta, detector_.State());
+      estimator_->Update(t_delta, ts_delta_ms, size_delta, detector_.State(),
+                         arrival_time_ms);
       detector_.Detect(estimator_->offset(), ts_delta_ms,
                        estimator_->num_of_deltas(), arrival_time_ms);
     }
diff --git a/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.cc b/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.cc
index 0115b14..6730cbb 100644
--- a/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.cc
+++ b/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.cc
@@ -123,7 +123,7 @@
           &timestamp_delta, &time_delta, &size_delta)) {
     double timestamp_delta_ms = timestamp_delta * kTimestampToMs;
     estimator->estimator.Update(time_delta, timestamp_delta_ms, size_delta,
-                                estimator->detector.State());
+                                estimator->detector.State(), now_ms);
     estimator->detector.Detect(estimator->estimator.offset(),
                                timestamp_delta_ms,
                                estimator->estimator.num_of_deltas(), now_ms);
diff --git a/webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.cc b/webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.cc
index 3a84e81..43818b0 100644
--- a/webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.cc
+++ b/webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.cc
@@ -91,15 +91,28 @@
 }
 
 void Logging::Plot(int figure, double value) {
-  Plot(figure, value, "-");
+  Plot(figure, value, 0, "-");
+}
+
+void Logging::Plot(int figure, double value, uint32_t ssrc) {
+  Plot(figure, value, ssrc, "-");
 }
 
 void Logging::Plot(int figure, double value, const std::string& alg_name) {
+  Plot(figure, value, 0, alg_name);
+}
+
+void Logging::Plot(int figure,
+                   double value,
+                   uint32_t ssrc,
+                   const std::string& alg_name) {
   CriticalSectionScoped cs(crit_sect_.get());
   ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId());
   assert(it != thread_map_.end());
   const State& state = it->second.stack.top();
-  std::string label = state.tag + '@' + alg_name;
+  std::stringstream ss;
+  ss << ssrc;
+  std::string label = state.tag + ':' + ss.str() + '@' + alg_name;
   std::string prefix("Available");
   if (alg_name.compare(0, prefix.length(), prefix) == 0) {
     std::string receiver("Receiver");
diff --git a/webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h b/webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h
index 53550fb..7a7bca1 100644
--- a/webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h
+++ b/webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h
@@ -91,9 +91,13 @@
 // |name| is a char*, std::string or uint32_t to name the plotted value.
 // |time| is an int64_t time in ms, or -1 to inherit time from previous context.
 // |value| is a double precision float to be plotted.
+// |ssrc| identifies the source of a stream
 // |alg_name| is an optional argument, a string
 #define BWE_TEST_LOGGING_PLOT(figure, name, time, value)
 #define BWE_TEST_LOGGING_PLOT_WITH_NAME(figure, name, time, value, alg_name)
+#define BWE_TEST_LOGGING_PLOT_WITH_SSRC(figure, name, time, value, ssrc)
+#define BWE_TEST_LOGGING_PLOT_WITH_NAME_AND_SSRC(figure, name, time, value, \
+                                                 ssrc, alg_name)
 
 // Print to stdout in tab-separated format suitable for plotting, e.g.:
 //   BAR figure Context1_Context2_Name  x_left  width  value
@@ -194,6 +198,22 @@
                                                        alg_name);            \
   } while (0)
 
+#define BWE_TEST_LOGGING_PLOT_WITH_SSRC(figure, name, time, value, ssrc)     \
+  do {                                                                       \
+    __BWE_TEST_LOGGING_CONTEXT_DECLARE(__bwe_log_, __PLOT__, name,           \
+                                       static_cast<int64_t>(time), true);    \
+    webrtc::testing::bwe::Logging::GetInstance()->Plot(figure, value, ssrc); \
+  } while (0)
+
+#define BWE_TEST_LOGGING_PLOT_WITH_NAME_AND_SSRC(figure, name, time, value, \
+                                                 ssrc, alg_name)            \
+  do {                                                                      \
+    __BWE_TEST_LOGGING_CONTEXT_DECLARE(__bwe_log_, __PLOT__, name,          \
+                                       static_cast<int64_t>(time), true);   \
+    webrtc::testing::bwe::Logging::GetInstance()->Plot(figure, value, ssrc, \
+                                                       alg_name);           \
+  } while (0)
+
 #define BWE_TEST_LOGGING_BAR(figure, name, value, flow_id)                     \
   do {                                                                         \
     BWE_TEST_LOGGING_CONTEXT(name);                                            \
@@ -261,6 +281,11 @@
   void Log(const char format[], ...);
   void Plot(int figure, double value);
   void Plot(int figure, double value, const std::string& alg_name);
+  void Plot(int figure, double value, uint32_t ssrc);
+  void Plot(int figure,
+            double value,
+            uint32_t ssrc,
+            const std::string& alg_name);
   void PlotBar(int figure, const std::string& name, double value, int flow_id);
   void PlotBaselineBar(int figure,
                        const std::string& name,
diff --git a/webrtc/modules/rtp_rtcp/BUILD.gn b/webrtc/modules/rtp_rtcp/BUILD.gn
index 60cb9d7..b06b920 100644
--- a/webrtc/modules/rtp_rtcp/BUILD.gn
+++ b/webrtc/modules/rtp_rtcp/BUILD.gn
@@ -154,6 +154,12 @@
     "source/vp8_partition_aggregator.h",
   ]
 
+  if (rtc_enable_bwe_test_logging) {
+    defines = [ "BWE_TEST_LOGGING_COMPILE_TIME_ENABLE=1" ]
+  } else {
+    defines = [ "BWE_TEST_LOGGING_COMPILE_TIME_ENABLE=0" ]
+  }
+
   if (is_clang) {
     # Suppress warnings from Chrome's Clang plugins.
     # See http://code.google.com/p/webrtc/issues/detail?id=163 for details.
diff --git a/webrtc/modules/rtp_rtcp/rtp_rtcp.gypi b/webrtc/modules/rtp_rtcp/rtp_rtcp.gypi
index 0082904..e03d56c 100644
--- a/webrtc/modules/rtp_rtcp/rtp_rtcp.gypi
+++ b/webrtc/modules/rtp_rtcp/rtp_rtcp.gypi
@@ -163,7 +163,14 @@
         # Mocks
         'mocks/mock_rtp_rtcp.h',
         'source/mock/mock_rtp_payload_strategy.h',
-      ], # source
+       ], # source
+        'conditions': [
+            ['enable_bwe_test_logging==1', {
+              'defines': [ 'BWE_TEST_LOGGING_COMPILE_TIME_ENABLE=1' ],
+            }, {
+              'defines': [ 'BWE_TEST_LOGGING_COMPILE_TIME_ENABLE=0' ],
+            }],
+        ],
       # TODO(jschuh): Bug 1348: fix size_t to int truncations.
       'msvs_disabled_warnings': [ 4267, ],
     },
diff --git a/webrtc/modules/rtp_rtcp/source/receive_statistics_impl.cc b/webrtc/modules/rtp_rtcp/source/receive_statistics_impl.cc
index 4ec11b6..0a6c2f9 100644
--- a/webrtc/modules/rtp_rtcp/source/receive_statistics_impl.cc
+++ b/webrtc/modules/rtp_rtcp/source/receive_statistics_impl.cc
@@ -14,6 +14,7 @@
 
 #include <cstdlib>
 
+#include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h"
 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h"
 #include "webrtc/modules/rtp_rtcp/source/time_util.h"
 
@@ -276,6 +277,12 @@
       receive_counters_.retransmitted.packets;
   last_report_old_packets_ = receive_counters_.retransmitted.packets;
   last_report_seq_max_ = received_seq_max_;
+  BWE_TEST_LOGGING_PLOT_WITH_SSRC(1, "cumulative_loss[pkts]",
+                                  clock_->TimeInMilliseconds(),
+                                  cumulative_loss_, ssrc_);
+  BWE_TEST_LOGGING_PLOT_WITH_SSRC(
+      1, "received_seq_max[pkts]", clock_->TimeInMilliseconds(),
+      (received_seq_max_ - received_seq_first_), ssrc_);
 
   return stats;
 }
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender.cc b/webrtc/modules/rtp_rtcp/source/rtp_sender.cc
index b771551..84f1fae 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_sender.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_sender.cc
@@ -20,6 +20,7 @@
 #include "webrtc/base/timeutils.h"
 #include "webrtc/call.h"
 #include "webrtc/call/rtc_event_log.h"
+#include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h"
 #include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h"
 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
 #include "webrtc/modules/rtp_rtcp/source/playout_delay_oracle.h"
@@ -905,6 +906,20 @@
   }
   packet->SetExtension<AbsoluteSendTime>(now_ms);
 
+  if (video_) {
+    BWE_TEST_LOGGING_PLOT_WITH_SSRC(1, "VideoTotBitrate[kbps]", now_ms,
+                                    ActualSendBitrateKbit(), packet->Ssrc());
+    BWE_TEST_LOGGING_PLOT_WITH_SSRC(1, "VideoFecBitrate[Kbps]", now_ms,
+                                    FecOverheadRate() / 1000, packet->Ssrc());
+    BWE_TEST_LOGGING_PLOT_WITH_SSRC(1, "VideoNackBitrate[Kbps]", now_ms,
+                                    NackOverheadRate() / 1000, packet->Ssrc());
+  } else {
+    BWE_TEST_LOGGING_PLOT_WITH_SSRC(1, "AudioTotBitrate[kbps]", now_ms,
+                                    ActualSendBitrateKbit(), packet->Ssrc());
+    BWE_TEST_LOGGING_PLOT_WITH_SSRC(1, "AudioNackBitrate[Kbps]", now_ms,
+                                    NackOverheadRate() / 1000, packet->Ssrc());
+  }
+
   if (paced_sender_) {
     uint16_t seq_no = packet->SequenceNumber();
     uint32_t ssrc = packet->Ssrc();