Add UMA for measuring the diff between the BWE at 2 seconds compared to the BWE at 20 seconds when the BWE should have converged.

BUG=crbug/425925
R=mflodman@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/30819005

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7620 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.cc b/webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.cc
index 47a79ad..9b55dad 100644
--- a/webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.cc
+++ b/webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.cc
@@ -22,6 +22,7 @@
 enum { kLimitNumPackets = 20 };
 enum { kAvgPacketSizeBytes = 1000 };
 enum { kStartPhaseMs = 2000 };
+enum { kBweConverganceTimeMs = 20000 };
 
 // Calculate the rate that TCP-Friendly Rate Control (TFRC) would apply.
 // The formula in RFC 3448, Section 3.1, is used.
@@ -61,7 +62,8 @@
       time_last_decrease_ms_(0),
       first_report_time_ms_(-1),
       initially_lost_packets_(0),
-      uma_updated_(false) {
+      bitrate_at_2_seconds_kbps_(0),
+      uma_update_state_(kNoUpdate) {
 }
 
 SendSideBandwidthEstimation::~SendSideBandwidthEstimation() {}
@@ -130,18 +132,35 @@
 
   if (first_report_time_ms_ == -1) {
     first_report_time_ms_ = now_ms;
-  } else if (IsInStartPhase(now_ms)) {
-    initially_lost_packets_ += (fraction_loss * number_of_packets) >> 8;
-  } else if (!uma_updated_) {
-    uma_updated_ = true;
+  } else {
+    UpdateUmaStats(now_ms, rtt, (fraction_loss * number_of_packets) >> 8);
+  }
+}
+
+void SendSideBandwidthEstimation::UpdateUmaStats(int64_t now_ms,
+                                                 int rtt,
+                                                 int lost_packets) {
+  if (IsInStartPhase(now_ms)) {
+    initially_lost_packets_ += lost_packets;
+  } else if (uma_update_state_ == kNoUpdate) {
+    uma_update_state_ = kFirstDone;
+    bitrate_at_2_seconds_kbps_ = (bitrate_ + 500) / 1000;
     RTC_HISTOGRAM_COUNTS(
         "WebRTC.BWE.InitiallyLostPackets", initially_lost_packets_, 0, 100, 50);
     RTC_HISTOGRAM_COUNTS("WebRTC.BWE.InitialRtt", rtt, 0, 2000, 50);
     RTC_HISTOGRAM_COUNTS("WebRTC.BWE.InitialBandwidthEstimate",
-                         (bitrate_ + 500) / 1000,
+                         bitrate_at_2_seconds_kbps_,
                          0,
                          2000,
                          50);
+  } else if (uma_update_state_ == kFirstDone &&
+             now_ms - first_report_time_ms_ >= kBweConverganceTimeMs) {
+    uma_update_state_ = kDone;
+    int bitrate_diff_kbps = std::max(
+        bitrate_at_2_seconds_kbps_ - static_cast<int>((bitrate_ + 500) / 1000),
+        0);
+    RTC_HISTOGRAM_COUNTS(
+        "WebRTC.BWE.InitialVsConvergedDiff", bitrate_diff_kbps, 0, 2000, 50);
   }
 }
 
diff --git a/webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.h b/webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.h
index 0fe3ae6..3361904 100644
--- a/webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.h
+++ b/webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.h
@@ -43,8 +43,12 @@
   void SetMinBitrate(uint32_t min_bitrate);
 
  private:
+  enum UmaState { kNoUpdate, kFirstDone, kDone };
+
   bool IsInStartPhase(int64_t now_ms) const;
 
+  void UpdateUmaStats(int64_t now_ms, int rtt, int lost_packets);
+
   // Returns the input bitrate capped to the thresholds defined by the max,
   // min and incoming bandwidth.
   uint32_t CapBitrateToThresholds(uint32_t bitrate);
@@ -72,7 +76,8 @@
   uint32_t time_last_decrease_ms_;
   int64_t first_report_time_ms_;
   int initially_lost_packets_;
-  bool uma_updated_;
+  int bitrate_at_2_seconds_kbps_;
+  UmaState uma_update_state_;
 };
 }  // namespace webrtc
 #endif  // WEBRTC_MODULES_BITRATE_CONTROLLER_SEND_SIDE_BANDWIDTH_ESTIMATION_H_