Bug 825519 - Add telemetry for the max number of times any one image was decoded. r=joe
authorJustin Lebar <justin.lebar@gmail.com>
Thu, 03 Jan 2013 16:06:08 -0500
changeset 123055 ecd2331e67980cd52f5c20cbd53fedab0e6606d4
parent 123054 97d2ac9d16c48485218c0f960c461d9cbd1b2bb2
child 123056 958f452fc41ed816fb56b29e56245063469e2092
push idunknown
push userunknown
push dateunknown
reviewersjoe
bugs825519
milestone20.0a1
Bug 825519 - Add telemetry for the max number of times any one image was decoded. r=joe
image/src/RasterImage.cpp
toolkit/components/telemetry/Histograms.json
--- a/image/src/RasterImage.cpp
+++ b/image/src/RasterImage.cpp
@@ -62,16 +62,20 @@ GetCompressedImageAccountingLog()
 // because otherwise, we have to initialize them in a static initializer, which
 // makes us slower to start up.
 static uint32_t gDecodeBytesAtATime = 0;
 static uint32_t gMaxMSBeforeYield = 0;
 static bool gHQDownscaling = false;
 // This is interpreted as a floating-point value / 1000
 static uint32_t gHQDownscalingMinFactor = 1000;
 
+// The maximum number of times any one RasterImage was decoded.  This is only
+// used for statistics.
+static int32_t sMaxDecodeCount = 0;
+
 static void
 InitPrefCaches()
 {
   Preferences::AddUintVarCache(&gDecodeBytesAtATime,
                                "image.mem.decode_bytes_at_a_time", 200000);
   Preferences::AddUintVarCache(&gMaxMSBeforeYield,
                                "image.mem.max_ms_before_yield", 400);
   Preferences::AddBoolVarCache(&gHQDownscaling,
@@ -2568,16 +2572,26 @@ RasterImage::InitDecoder(bool aDoSizeDec
   mDecoder->SetDecodeFlags(mFrameDecodeFlags);
   mDecoder->Init();
   CONTAINER_ENSURE_SUCCESS(mDecoder->GetDecoderError());
 
   if (!aDoSizeDecode) {
     Telemetry::GetHistogramById(Telemetry::IMAGE_DECODE_COUNT)->Subtract(mDecodeCount);
     mDecodeCount++;
     Telemetry::GetHistogramById(Telemetry::IMAGE_DECODE_COUNT)->Add(mDecodeCount);
+
+    if (mDecodeCount > sMaxDecodeCount) {
+      // Don't subtract out 0 from the histogram, because that causes its count
+      // to go negative, which is not kosher.
+      if (sMaxDecodeCount > 0) {
+        Telemetry::GetHistogramById(Telemetry::IMAGE_MAX_DECODE_COUNT)->Subtract(sMaxDecodeCount);
+      }
+      sMaxDecodeCount = mDecodeCount;
+      Telemetry::GetHistogramById(Telemetry::IMAGE_MAX_DECODE_COUNT)->Add(sMaxDecodeCount);
+    }
   }
 
   return NS_OK;
 }
 
 // Flushes, closes, and nulls-out a decoder. Cleans up any related decoding
 // state. It is an error to call this function when there is no initialized
 // decoder.
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -502,16 +502,22 @@
     "description": "Number of chunks per decode attempt"
   },
   "IMAGE_DECODE_COUNT": {
     "kind": "exponential",
     "high": "500",
     "n_buckets": 50,
     "description": "Decode count"
   },
+  "IMAGE_MAX_DECODE_COUNT": {
+    "kind": "exponential",
+    "high": "10000",
+    "n_buckets": 100,
+    "description": "Max decode count over all images"
+  },
   "IMAGE_DECODE_SPEED_JPEG": {
     "kind": "exponential",
     "low": 500,
     "high": "50000000",
     "n_buckets": 50,
     "description": "JPEG image decode speed (Kbytes/sec)"
   },
   "IMAGE_DECODE_SPEED_GIF": {