Bug 1592934 - Add a telemetry probe to track storage initialization success rate; r=janv a=pascalc
authorTom Tung <ttung@mozilla.com>
Wed, 20 Nov 2019 10:34:34 +0000
changeset 563470 0376c52e0a808922d35a0b3646e828622563c56e
parent 563469 63d69f4dfafebd03825e41bbdb6b08e5b36386e4
child 563471 091036d0916b5247c8954c7ca189fb4f40ed57c4
push id2195
push userffxbld-merge
push dateMon, 25 Nov 2019 12:02:33 +0000
treeherdermozilla-release@19adee6f7bb3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjanv, pascalc
bugs1592934
milestone71.0
Bug 1592934 - Add a telemetry probe to track storage initialization success rate; r=janv a=pascalc Differential Revision: https://phabricator.services.mozilla.com/D51845
dom/quota/ActorsParent.cpp
dom/quota/QuotaManager.h
dom/quota/test/unit/test_qm_first_initialization_attempt.js
--- a/dom/quota/ActorsParent.cpp
+++ b/dom/quota/ActorsParent.cpp
@@ -189,16 +189,17 @@ static_assert(static_cast<uint32_t>(Stor
                   static_cast<uint32_t>(PERSISTENCE_TYPE_DEFAULT),
               "Enum values should match.");
 
 const char kChromeOrigin[] = "chrome";
 const char kAboutHomeOriginPrefix[] = "moz-safe-about:home";
 const char kIndexedDBOriginPrefix[] = "indexeddb://";
 const char kResourceOriginPrefix[] = "resource://";
 
+constexpr auto kStorageTelemetryKey = NS_LITERAL_CSTRING("Storage");
 constexpr auto kTempStorageTelemetryKey =
     NS_LITERAL_CSTRING("TemporaryStorage");
 
 #define INDEXEDDB_DIRECTORY_NAME "indexedDB"
 #define STORAGE_DIRECTORY_NAME "storage"
 #define PERSISTENT_DIRECTORY_NAME "persistent"
 #define PERMANENT_DIRECTORY_NAME "permanent"
 #define TEMPORARY_DIRECTORY_NAME "temporary"
@@ -3428,16 +3429,17 @@ bool QuotaObject::LockedMaybeUpdateSize(
  * Quota manager
  ******************************************************************************/
 
 QuotaManager::QuotaManager()
     : mQuotaMutex("QuotaManager.mQuotaMutex"),
       mTemporaryStorageLimit(0),
       mTemporaryStorageUsage(0),
       mNextDirectoryLockId(0),
+      mStorageInitializationAttempted(false),
       mTemporaryStorageInitializationAttempted(false),
       mTemporaryStorageInitialized(false),
       mCacheUsable(false) {
   AssertIsOnOwningThread();
   MOZ_ASSERT(!gInstance);
 }
 
 QuotaManager::~QuotaManager() {
@@ -6224,19 +6226,32 @@ void QuotaManager::AssertStorageIsInitia
 }
 
 #endif  // DEBUG
 
 nsresult QuotaManager::EnsureStorageIsInitialized() {
   AssertIsOnIOThread();
 
   if (mStorageConnection) {
+    MOZ_ASSERT(mStorageInitializationAttempted);
     return NS_OK;
   }
 
+  auto autoReportTelemetry = MakeScopeExit([&]() {
+    Telemetry::Accumulate(Telemetry::QM_FIRST_INITIALIZATION_ATTEMPT,
+                          kStorageTelemetryKey,
+                          static_cast<uint32_t>(!!mStorageConnection));
+  });
+
+  if (mStorageInitializationAttempted) {
+    autoReportTelemetry.release();
+  }
+
+  mStorageInitializationAttempted = true;
+
   nsCOMPtr<nsIFile> storageFile;
   nsresult rv = NS_NewLocalFile(mBasePath, false, getter_AddRefs(storageFile));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   rv = storageFile->Append(NS_LITERAL_STRING(STORAGE_FILE_NAME));
   if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -6870,16 +6885,17 @@ void QuotaManager::ShutdownStorage() {
       mTemporaryStorageInitialized = false;
     }
 
     mTemporaryStorageInitializationAttempted = false;
 
     ReleaseIOThreadObjects();
 
     mStorageConnection = nullptr;
+    mStorageInitializationAttempted = false;
   }
 }
 
 nsresult QuotaManager::EnsureOriginDirectory(nsIFile* aDirectory,
                                              bool* aCreated) {
   AssertIsOnIOThread();
   MOZ_ASSERT(aDirectory);
   MOZ_ASSERT(aCreated);
--- a/dom/quota/QuotaManager.h
+++ b/dom/quota/QuotaManager.h
@@ -590,16 +590,17 @@ class QuotaManager final : public Backgr
   nsString mStoragePath;
   nsString mPermanentStoragePath;
   nsString mTemporaryStoragePath;
   nsString mDefaultStoragePath;
 
   uint64_t mTemporaryStorageLimit;
   uint64_t mTemporaryStorageUsage;
   int64_t mNextDirectoryLockId;
+  bool mStorageInitializationAttempted;
   bool mTemporaryStorageInitializationAttempted;
   bool mTemporaryStorageInitialized;
   bool mCacheUsable;
 };
 
 END_QUOTA_NAMESPACE
 
 #endif /* mozilla_dom_quota_quotamanager_h__ */
--- a/dom/quota/test/unit/test_qm_first_initialization_attempt.js
+++ b/dom/quota/test/unit/test_qm_first_initialization_attempt.js
@@ -6,16 +6,37 @@
 const { TelemetryTestUtils } = ChromeUtils.import(
   "resource://testing-common/TelemetryTestUtils.jsm"
 );
 
 const telemetry = "QM_FIRST_INITIALIZATION_ATTEMPT";
 
 const testcases = [
   {
+    key: "Storage",
+    testingInitFunction() {
+      return init();
+    },
+    get metadataDir() {
+      return getRelativeFile(
+        "storage/default/https+++example.com/.metadata-v2"
+      );
+    },
+    async settingForForcingInitFailure() {
+      this.metadataDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
+    },
+    removeSetting() {
+      this.metadataDir.remove(false);
+    },
+    expectedResult: {
+      initFailure: [1, 0],
+      initFailureThenSuccess: [1, 1, 0],
+    },
+  },
+  {
     key: "TemporaryStorage",
     testingInitFunction() {
       return initTemporaryStorage();
     },
     get metadataDir() {
       return getRelativeFile(
         "storage/default/https+++example.com/.metadata-v2"
       );