Bug 724513 - Part 3 - Add telemetry for the invalid disk cache situation. r=taras
authorGraeme McCutcheon <graememcc_firefox@graeme-online.co.uk>
Thu, 11 Oct 2012 09:50:41 +0100
changeset 112152 b032c4cc9d7dc684bb112424e9d07dd4be8dd046
parent 112151 6ec71de7ba2d66438d9ee4ee03628ada27999c3c
child 112153 6ac4bb259db3be313d5128a6a96b20d86faf5dd3
push id23798
push userryanvm@gmail.com
push dateSat, 03 Nov 2012 00:06:35 +0000
treeherdermozilla-central@6134edeea902 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstaras
bugs724513
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 724513 - Part 3 - Add telemetry for the invalid disk cache situation. r=taras
startupcache/StartupCache.cpp
startupcache/test/TestStartupCache.cpp
toolkit/components/telemetry/Histograms.json
--- a/startupcache/StartupCache.cpp
+++ b/startupcache/StartupCache.cpp
@@ -476,16 +476,17 @@ StartupCache::InvalidateCache()
 {
   WaitOnWriteThread();
   mTable.Clear();
   mArchive = NULL;
   nsresult rv = mFile->Remove(false);
   if (NS_FAILED(rv) && rv != NS_ERROR_FILE_TARGET_DOES_NOT_EXIST &&
       rv != NS_ERROR_FILE_NOT_FOUND) {
     gIgnoreDiskCache = true;
+    mozilla::Telemetry::Accumulate(Telemetry::STARTUP_CACHE_INVALID, true);
     return;
   }
   gIgnoreDiskCache = false;
   LoadArchive(gPostFlushAgeAction);
 }
 
 void
 StartupCache::IgnoreDiskCache()
--- a/startupcache/test/TestStartupCache.cpp
+++ b/startupcache/test/TestStartupCache.cpp
@@ -395,24 +395,24 @@ SetupJS(JSContext **cxp)
   JSContext *cx = JS_NewContext(rt, 8192);
   if (!cx)
     return false;
   *cxp = cx;
   return true;
 }
 
 bool
-GetHistogramCounts(const char *testmsg, JSContext *cx, jsval *counts)
+GetHistogramCounts(const char *testmsg, const nsACString &histogram_id,
+                   JSContext *cx, jsval *counts)
 {
   nsCOMPtr<nsITelemetry> telemetry = do_GetService("@mozilla.org/base/telemetry;1");
-  NS_NAMED_LITERAL_CSTRING(histogram_id, "STARTUP_CACHE_AGE_HOURS");
   JS::AutoValueRooter h(cx);
   nsresult trv = telemetry->GetHistogramById(histogram_id, cx, h.addr());
   if (NS_FAILED(trv)) {
-    fail("%s: couldn't get histogram", testmsg);
+    fail("%s: couldn't get histogram %s", testmsg, ToNewCString(histogram_id));
     return false;
   }
   passed(testmsg);
 
   JS::AutoValueRooter snapshot_val(cx);
   JSFunction *snapshot_fn = NULL;
   JS::AutoValueRooter ss(cx);
   return (JS_GetProperty(cx, JSVAL_TO_OBJECT(h.value()), "snapshot",
@@ -454,21 +454,42 @@ CompareCountArrays(JSContext *cx, JSObje
       } else {
         // Some element of the histograms's count arrays differed.
         // That's a good thing!
         return NS_OK;
       }
     }
   }
 
-  // All of the elements of the histograms's count arrays differed.
+  // None of the elements of the histograms's count arrays differed.
   // Not good, we should have recorded something.
   return NS_ERROR_FAILURE;
 }
 
+nsresult
+TestHistogramValues(const char* type, bool use_js, JSContext *cx,
+                    JSObject *before, JSObject *after)
+{
+  if (!use_js) {
+    fail("couldn't check histogram recording");
+    return NS_ERROR_FAILURE;
+  }
+  nsresult compare = CompareCountArrays(cx, before, after);
+  if (compare == NS_ERROR_UNEXPECTED) {
+    fail("count comparison error");
+    return compare;
+  }
+  if (compare == NS_ERROR_FAILURE) {
+    fail("histogram didn't record %s", type);
+    return compare;
+  }
+  passed("histogram records %s", type);
+  return NS_OK;
+}
+
 int main(int argc, char** argv)
 {
   ScopedXPCOM xpcom("Startup Cache");
   if (xpcom.failed())
     return 1;
 
   nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
   prefs->SetIntPref("hangmonitor.timeout", 0);
@@ -494,19 +515,27 @@ int main(int argc, char** argv)
   if (!glob)
     use_js = false;
   mozilla::Maybe<JSAutoCompartment> ac;
   if (use_js)
     ac.construct(cx, glob);
   if (use_js && !JS_InitStandardClasses(cx, glob))
     use_js = false;
 
-  JS::AutoValueRooter before_counts(cx);
+  NS_NAMED_LITERAL_CSTRING(age_histogram_id, "STARTUP_CACHE_AGE_HOURS");
+  NS_NAMED_LITERAL_CSTRING(invalid_histogram_id, "STARTUP_CACHE_INVALID");
+
+  JS::AutoValueRooter age_before_counts(cx);
   if (use_js && !GetHistogramCounts("STARTUP_CACHE_AGE_HOURS histogram before test",
-                                 cx, before_counts.addr()))
+                                    age_histogram_id, cx, age_before_counts.addr()))
+    use_js = false;
+  
+  JS::AutoValueRooter invalid_before_counts(cx);
+  if (use_js && !GetHistogramCounts("STARTUP_CACHE_INVALID histogram before test",
+                                    invalid_histogram_id, cx, invalid_before_counts.addr()))
     use_js = false;
   
   nsresult scrv;
   nsCOMPtr<nsIStartupCache> sc 
     = do_GetService("@mozilla.org/startupcache/cache;1", &scrv);
   if (NS_FAILED(scrv))
     rv = 1;
   else
@@ -518,33 +547,31 @@ int main(int argc, char** argv)
   if (NS_FAILED(TestWriteObject()))
     rv = 1;
   nsCOMPtr<nsIFile> profileDir = xpcom.GetProfileDirectory();
   if (NS_FAILED(TestIgnoreDiskCache(profileDir)))
     rv = 1;
   if (NS_FAILED(TestEarlyShutdown()))
     rv = 1;
 
-  JS::AutoValueRooter after_counts(cx);
+  JS::AutoValueRooter age_after_counts(cx);
   if (use_js && !GetHistogramCounts("STARTUP_CACHE_AGE_HOURS histogram after test",
-                                    cx, after_counts.addr()))
+                                    age_histogram_id, cx, age_after_counts.addr()))
     use_js = false;
 
-  if (!use_js) {
-    fail("couldn't check histogram recording");
+  if (NS_FAILED(TestHistogramValues("age samples", use_js, cx,
+                                    JSVAL_TO_OBJECT(age_before_counts.value()),
+                                    JSVAL_TO_OBJECT(age_after_counts.value()))))
     rv = 1;
-  } else {
-    nsresult compare = CompareCountArrays(cx,
-                                          JSVAL_TO_OBJECT(before_counts.value()),
-                                          JSVAL_TO_OBJECT(after_counts.value()));
-    if (compare == NS_ERROR_UNEXPECTED) {
-      fail("count comparison error");
-      rv = 1;
-    } else if (compare == NS_ERROR_FAILURE) {
-      fail("histogram didn't record samples");
-      rv = 1;
-    } else {
-      passed("histogram records samples");
-    }
-  }
+                                                    
+  JS::AutoValueRooter invalid_after_counts(cx);
+  if (use_js && !GetHistogramCounts("STARTUP_CACHE_INVALID histogram after test",
+                                    invalid_histogram_id, cx, invalid_after_counts.addr()))
+    use_js = false;
+
+  // STARTUP_CACHE_INVALID should have been triggered by TestIgnoreDiskCache()
+  if (NS_FAILED(TestHistogramValues("invalid disk cache", use_js, cx,
+                                    JSVAL_TO_OBJECT(invalid_before_counts.value()),
+                                    JSVAL_TO_OBJECT(invalid_after_counts.value()))))
+    rv = 1;
 
   return rv;
 }
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -424,16 +424,20 @@
     "description": "Maximum retention time for the gradient cache. (ms)"
   },
   "STARTUP_CACHE_AGE_HOURS": {
     "kind": "exponential",
     "high": "3000",
     "n_buckets": 20,
     "description": "Startup cache age (hours)"
   },
+  "STARTUP_CACHE_INVALID": {
+    "kind": "flag",
+    "description": "Was the disk startup cache file detected as invalid"
+  },
   "WORD_CACHE_HITS": {
     "kind": "exponential",
     "high": "256",
     "n_buckets": 30,
     "description": "Word cache hits (chars)"
   },
   "WORD_CACHE_MISSES": {
     "kind": "exponential",