Bug 808268 - Report % of dirty keys in a scope during a flush. r=taras
authorVladan Djeric <vdjeric@mozilla.com>
Mon, 05 Nov 2012 15:49:38 -0500
changeset 112350 dfe6972056d658a674394f4d28b81dc020447b1f
parent 112349 20ae9d34616397ef4b9ba385818e9b77c916ff22
child 112351 5bd42ae5efd23bb82e6891055bbab7f74b5708ea
push id23812
push useremorley@mozilla.com
push dateTue, 06 Nov 2012 14:01:34 +0000
treeherdermozilla-central@f4aeed115e54 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstaras
bugs808268
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 808268 - Report % of dirty keys in a scope during a flush. r=taras
dom/src/storage/nsDOMStoragePersistentDB.cpp
toolkit/components/telemetry/Histograms.json
--- a/dom/src/storage/nsDOMStoragePersistentDB.cpp
+++ b/dom/src/storage/nsDOMStoragePersistentDB.cpp
@@ -269,16 +269,42 @@ nsDOMStoragePersistentDB::FlushTemporary
 
   if (!data->mForce && 
       ((TimeStamp::Now() - aData).ToSeconds() < TEMP_TABLE_MAX_AGE))
     return PL_DHASH_NEXT;
 
   {
     nsCOMPtr<mozIStorageStatement> stmt =
       data->mDB->mStatements.GetCachedStatement(
+        "SELECT SUM(modified) * 100.0 / COUNT(*) FROM webappsstore2_temp "
+        "WHERE scope = :scope"
+      );
+    mozStorageStatementScoper scope(stmt);
+
+    nsresult rv;
+    bool exists;
+    double percentFlushed;
+    if (stmt) {
+      rv = stmt->BindUTF8StringByName(NS_LITERAL_CSTRING("scope"), aKey);
+      if (NS_SUCCEEDED(rv)) {
+        rv = stmt->ExecuteStep(&exists);
+        if (NS_SUCCEEDED(rv) && exists) {
+          rv = stmt->GetDouble(0, &percentFlushed);
+          if (NS_SUCCEEDED(rv) && percentFlushed > 0.0) {
+            Telemetry::Accumulate(Telemetry::LOCALDOMSTORAGE_PERCENT_FLUSHED,
+                                  uint32_t(percentFlushed));
+          }
+        }
+      }
+    }
+  }
+
+  {
+    nsCOMPtr<mozIStorageStatement> stmt =
+      data->mDB->mStatements.GetCachedStatement(
         "INSERT OR REPLACE INTO webappsstore2 "
          "SELECT scope, key, value, secure, owner FROM webappsstore2_temp "
          "WHERE scope = :scope AND modified = 1"
       );
     NS_ENSURE_TRUE(stmt, PL_DHASH_STOP);
     mozStorageStatementScoper scope(stmt);
 
     data->mRV = stmt->BindUTF8StringByName(NS_LITERAL_CSTRING("scope"), aKey);
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -2164,16 +2164,22 @@
     "description": "Time to fetch quota use stats for a TLD (ms)"
   },
   "LOCALDOMSTORAGE_TIMER_FLUSH_MS": {
     "kind": "exponential",
     "high": "3000",
     "n_buckets": 10,
     "description": "Time to flush dirty entries from the cache (ms)"
   },
+  "LOCALDOMSTORAGE_PERCENT_FLUSHED": {
+    "kind": "linear",
+    "high": "100",
+    "n_buckets": 12,
+    "description": "Percentage of dirty entries during a flush"
+  },
   "LOCALDOMSTORAGE_KEY_SIZE_BYTES": {
     "kind": "exponential",
     "low": 1024,
     "high": "32768",
     "n_buckets": 10,
     "description": "DOM storage: size of keys stored in localStorage"
   },
   "LOCALDOMSTORAGE_VALUE_SIZE_BYTES": {