Bug 1287987 - Record VIDEO_HIDDEN_PLAY_TIME_PERCENTAGE telemetry - r=kamidphish
authorGerald Squelart <gsquelart@mozilla.com>
Tue, 19 Jul 2016 17:47:45 +1000
changeset 330909 3f4268be982986a087206a5bc950fa5f17a4c09a
parent 330908 b30a96d890b60d296ec1830f0743ee03716971ed
child 330910 bd2f3939764154062cf4d65c8a39bd461df10c44
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskamidphish
bugs1287987
milestone50.0a1
Bug 1287987 - Record VIDEO_HIDDEN_PLAY_TIME_PERCENTAGE telemetry - r=kamidphish MozReview-Commit-ID: FJk7Jn5mqTp
dom/html/HTMLMediaElement.cpp
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -3085,21 +3085,61 @@ HTMLMediaElement::ReportTelemetry()
       uint32_t percentage = 100 * droppedFrames / totalFrames;
       LOG(LogLevel::Debug,
           ("Reporting telemetry DROPPED_FRAMES_IN_VIDEO_PLAYBACK"));
       Telemetry::Accumulate(Telemetry::VIDEO_DROPPED_FRAMES_PROPORTION,
                             percentage);
     }
   }
 
-  Telemetry::Accumulate(Telemetry::VIDEO_PLAY_TIME_MS, SECONDS_TO_MS(mPlayTime.Total()));
-  LOG(LogLevel::Debug, ("%p VIDEO_PLAY_TIME_MS = %f", this, mPlayTime.Total()));
-
-  Telemetry::Accumulate(Telemetry::VIDEO_HIDDEN_PLAY_TIME_MS, SECONDS_TO_MS(mHiddenPlayTime.Total()));
-  LOG(LogLevel::Debug, ("%p VIDEO_HIDDEN_PLAY_TIME_MS = %f", this, mHiddenPlayTime.Total()));
+  double playTime = mPlayTime.Total();
+  double hiddenPlayTime = mHiddenPlayTime.Total();
+
+  Telemetry::Accumulate(Telemetry::VIDEO_PLAY_TIME_MS, SECONDS_TO_MS(playTime));
+  LOG(LogLevel::Debug, ("%p VIDEO_PLAY_TIME_MS = %f", this, playTime));
+
+  Telemetry::Accumulate(Telemetry::VIDEO_HIDDEN_PLAY_TIME_MS, SECONDS_TO_MS(hiddenPlayTime));
+  LOG(LogLevel::Debug, ("%p VIDEO_HIDDEN_PLAY_TIME_MS = %f", this, hiddenPlayTime));
+
+  if (playTime > 0.0 &&
+      mMediaInfo.HasVideo() &&
+      mMediaInfo.mVideo.mImage.height > 0) {
+    // We have actually played some valid video -> Report hidden/total ratio.
+    uint32_t hiddenPercentage = uint32_t(hiddenPlayTime / playTime * 100.0 + 0.5);
+
+    // Keyed by audio+video or video alone, and by a resolution range.
+    nsCString key(mMediaInfo.HasAudio() ? "AV," : "V,");
+    static const struct { int32_t mH; const char* mRes; } sResolutions[] = {
+      {  240, "0<h<=240" },
+      {  480, "240<h<=480" },
+      {  576, "480<h<=576" },
+      {  720, "576<h<=720" },
+      { 1080, "720<h<=1080" },
+      { 2160, "1080<h<=2160" }
+    };
+    const char* resolution = "h>2160";
+    int32_t height = mMediaInfo.mVideo.mImage.height;
+    for (const auto& res : sResolutions) {
+      if (height <= res.mH) {
+        resolution = res.mRes;
+        break;
+      }
+    }
+    key.AppendASCII(resolution);
+
+    Telemetry::Accumulate(Telemetry::VIDEO_HIDDEN_PLAY_TIME_PERCENTAGE,
+                          key,
+                          hiddenPercentage);
+    // Also accumulate all percentages in an "All" key.
+    Telemetry::Accumulate(Telemetry::VIDEO_HIDDEN_PLAY_TIME_PERCENTAGE,
+                          NS_LITERAL_CSTRING("All"),
+                          hiddenPercentage);
+    LOG(LogLevel::Debug, ("%p VIDEO_HIDDEN_PLAY_TIME_PERCENTAGE = %u, keys: '%s' and 'All'",
+                          this, hiddenPercentage, key.get()));
+  }
 }
 
 void HTMLMediaElement::UnbindFromTree(bool aDeep,
                                       bool aNullParent)
 {
   if (!mPaused && mNetworkState != nsIDOMHTMLMediaElement::NETWORK_EMPTY) {
     Pause();
   }