Bug 1498736 - Log the number of prefixes loaded from disk. r=dimi
authorFrancois Marier <francois@mozilla.com>
Sat, 13 Oct 2018 20:21:45 +0000
changeset 499762 de0c544a16b95a244d1113a2e03f13c83a632e8c
parent 499761 ba86672c033d9578ec99d0aa70eecbfedac28b46
child 499763 84ceb42728e4509c23f5167eb0ef166986efad4a
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdimi
bugs1498736
milestone64.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 1498736 - Log the number of prefixes loaded from disk. r=dimi Differential Revision: https://phabricator.services.mozilla.com/D8622
toolkit/components/url-classifier/VariableLengthPrefixSet.cpp
toolkit/components/url-classifier/VariableLengthPrefixSet.h
toolkit/components/url-classifier/nsUrlClassifierPrefixSet.cpp
--- a/toolkit/components/url-classifier/VariableLengthPrefixSet.cpp
+++ b/toolkit/components/url-classifier/VariableLengthPrefixSet.cpp
@@ -34,16 +34,17 @@ VariableLengthPrefixSet::VariableLengthP
   : mLock("VariableLengthPrefixSet.mLock")
   , mFixedPrefixSet(new nsUrlClassifierPrefixSet)
 {
 }
 
 nsresult
 VariableLengthPrefixSet::Init(const nsACString& aName)
 {
+  mName = aName;
   mMemoryReportPath =
     nsPrintfCString(
       "explicit/storage/prefix-set/%s",
       (!aName.IsEmpty() ? PromiseFlatCString(aName).get() : "?!")
     );
 
   RegisterWeakMemoryReporter(this);
 
@@ -299,54 +300,64 @@ VariableLengthPrefixSet::LoadPrefixes(ns
   uint32_t magic;
   uint32_t read;
 
   nsresult rv = in->Read(reinterpret_cast<char*>(&magic), sizeof(uint32_t), &read);
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(read == sizeof(uint32_t), NS_ERROR_FAILURE);
 
   if (magic != PREFIXSET_VERSION_MAGIC) {
-    LOG(("Version magic mismatch, not loading"));
+    LOG(("[%s] Version magic mismatch, not loading", mName.get()));
     return NS_ERROR_FILE_CORRUPTED;
   }
 
   mVLPrefixSet.Clear();
 
   uint32_t count;
   rv = in->Read(reinterpret_cast<char*>(&count), sizeof(uint32_t), &read);
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(read == sizeof(uint32_t), NS_ERROR_FAILURE);
 
+  uint32_t totalPrefixes = 0;
   for(;count > 0; count--) {
     uint8_t prefixSize;
     rv = in->Read(reinterpret_cast<char*>(&prefixSize), sizeof(uint8_t), &read);
     NS_ENSURE_SUCCESS(rv, rv);
     NS_ENSURE_TRUE(read == sizeof(uint8_t), NS_ERROR_FAILURE);
 
     if (prefixSize < PREFIX_SIZE || prefixSize > COMPLETE_SIZE) {
       return NS_ERROR_FILE_CORRUPTED;
     }
 
     uint32_t stringLength;
     rv = in->Read(reinterpret_cast<char*>(&stringLength), sizeof(uint32_t), &read);
     NS_ENSURE_SUCCESS(rv, rv);
     NS_ENSURE_TRUE(read == sizeof(uint32_t), NS_ERROR_FAILURE);
 
+    NS_ENSURE_TRUE(stringLength % prefixSize == 0, NS_ERROR_FILE_CORRUPTED);
+    uint32_t prefixCount = stringLength / prefixSize;
+
     nsCString* vlPrefixes = new nsCString();
     if (!vlPrefixes->SetLength(stringLength, fallible)) {
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     rv = in->Read(reinterpret_cast<char*>(vlPrefixes->BeginWriting()), stringLength, &read);
     NS_ENSURE_SUCCESS(rv, rv);
     NS_ENSURE_TRUE(read == stringLength, NS_ERROR_FAILURE);
 
     mVLPrefixSet.Put(prefixSize, vlPrefixes);
+    totalPrefixes += prefixCount;
+    LOG(("[%s] Loaded %u %u-byte prefixes", mName.get(), prefixCount,
+         prefixSize));
   }
 
+  LOG(("[%s] Loading VLPrefixSet successful (%u total prefixes)", mName.get(),
+       totalPrefixes));
+
   return NS_OK;
 }
 
 uint32_t
 VariableLengthPrefixSet::CalculatePreallocateSize() const
 {
   uint32_t fileSize = 0;
 
--- a/toolkit/components/url-classifier/VariableLengthPrefixSet.h
+++ b/toolkit/components/url-classifier/VariableLengthPrefixSet.h
@@ -57,15 +57,16 @@ private:
   // of the operations) and the main thread (which does memory reporting).
   // It should be held for all operations between Init() and destruction that
   // touch this class's data members.
   mutable mozilla::Mutex mLock;
 
   const RefPtr<nsUrlClassifierPrefixSet> mFixedPrefixSet;
   mozilla::safebrowsing::PrefixStringMap mVLPrefixSet;
 
+  nsCString mName;
   nsCString mMemoryReportPath;
 };
 
 } // namespace safebrowsing
 } // namespace mozilla
 
 #endif
--- a/toolkit/components/url-classifier/nsUrlClassifierPrefixSet.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierPrefixSet.cpp
@@ -514,17 +514,18 @@ nsUrlClassifierPrefixSet::LoadPrefixes(n
       }
     }
   } else {
     LOG(("[%s] Version magic mismatch, not loading", mName.get()));
     return NS_ERROR_FILE_CORRUPTED;
   }
 
   MOZ_ASSERT(mIndexPrefixes.Length() == mIndexDeltas.Length());
-  LOG(("[%s] Loading PrefixSet successful", mName.get()));
+  LOG(("[%s] Loading PrefixSet successful (%u total prefixes)", mName.get(),
+       mTotalPrefixes));
 
   return NS_OK;
 }
 
 uint32_t
 nsUrlClassifierPrefixSet::CalculatePreallocateSize() const
 {
   uint32_t fileSize = 4 * sizeof(uint32_t);