Bug 1336909 - Restrict URLCLASSIFIER_PREFIX_MATCH to profiles that have working V4. r=francois
authordimi <dlee@mozilla.com>
Wed, 08 Feb 2017 15:18:35 +0800
changeset 341421 2f0968db9234a6e63f6fef6a82a9133b8f99aae5
parent 341420 734ac707469b7bf17fa38efc02b19f106eb2a1ec
child 341422 3305ef5e8faa24988d6835f34c75e9e9eb29821d
push id86727
push userkwierso@gmail.com
push dateThu, 09 Feb 2017 00:21:26 +0000
treeherdermozilla-inbound@55a4f5189115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfrancois
bugs1336909
milestone54.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 1336909 - Restrict URLCLASSIFIER_PREFIX_MATCH to profiles that have working V4. r=francois MozReview-Commit-ID: L3lKgiohalH
toolkit/components/url-classifier/Classifier.cpp
toolkit/components/url-classifier/LookupCache.cpp
toolkit/components/url-classifier/LookupCache.h
toolkit/components/url-classifier/LookupCacheV4.cpp
toolkit/components/url-classifier/LookupCacheV4.h
--- a/toolkit/components/url-classifier/Classifier.cpp
+++ b/toolkit/components/url-classifier/Classifier.cpp
@@ -447,16 +447,26 @@ Classifier::Check(const nsACString& aSpe
     LookupCache *cache = GetLookupCache(activeTables[i]);
     if (cache) {
       cacheArray.AppendElement(cache);
     } else {
       return NS_ERROR_FAILURE;
     }
   }
 
+  // Only record telemetry when both v2 and v4 have data.
+  bool isV2Empty = true, isV4Empty = true;
+  for (auto&& cache : cacheArray) {
+    bool& ref = LookupCache::Cast<LookupCacheV2>(cache) ? isV2Empty : isV4Empty;
+    ref = ref ? cache->IsEmpty() : false;
+    if (!isV2Empty && !isV4Empty) {
+      break;
+    }
+  }
+
   PrefixMatch matchingStatistics = PrefixMatch::eNoMatch;
 
   // Now check each lookup fragment against the entries in the DB.
   for (uint32_t i = 0; i < fragments.Length(); i++) {
     Completion lookupHash;
     lookupHash.FromPlaintext(fragments[i], mCryptoHash);
 
     if (LOG_ENABLED()) {
@@ -501,18 +511,20 @@ Classifier::Check(const nsACString& aSpe
           result->mProtocolV2 = false;
         } else {
           matchingStatistics |= PrefixMatch::eMatchV2Prefix;
           result->mProtocolV2 = true;
         }
       }
     }
 
-    Telemetry::Accumulate(Telemetry::URLCLASSIFIER_PREFIX_MATCH,
-                          static_cast<uint8_t>(matchingStatistics));
+    if (!isV2Empty && !isV4Empty) {
+      Telemetry::Accumulate(Telemetry::URLCLASSIFIER_PREFIX_MATCH,
+                            static_cast<uint8_t>(matchingStatistics));
+    }
   }
 
   return NS_OK;
 }
 
 nsresult
 Classifier::ApplyUpdates(nsTArray<TableUpdate*>* aUpdates)
 {
--- a/toolkit/components/url-classifier/LookupCache.cpp
+++ b/toolkit/components/url-classifier/LookupCache.cpp
@@ -465,16 +465,24 @@ LookupCacheV2::IsHashEntryConfirmed(cons
     int64_t now = (PR_Now() / PR_USEC_PER_SEC);
     MOZ_ASSERT(age <= now);
 
     // Considered completion as unsafe if its table is up-to-date.
     *aConfirmed = (now - age) < aFreshnessGuarantee;
   }
 }
 
+bool
+LookupCacheV2::IsEmpty()
+{
+  bool isEmpty;
+  mPrefixSet->IsEmpty(&isEmpty);
+  return isEmpty;
+}
+
 nsresult
 LookupCacheV2::Build(AddPrefixArray& aAddPrefixes,
                      AddCompleteArray& aAddCompletes)
 {
   Telemetry::Accumulate(Telemetry::URLCLASSIFIER_LC_COMPLETIONS,
                         static_cast<uint32_t>(aAddCompletes.Length()));
 
   mUpdateCompletions.Clear();
--- a/toolkit/components/url-classifier/LookupCache.h
+++ b/toolkit/components/url-classifier/LookupCache.h
@@ -143,16 +143,18 @@ public:
                        bool* aHas, uint32_t* aMatchLength,
                        bool* aFromCache) = 0;
 
   virtual void IsHashEntryConfirmed(const Completion& aEntry,
                                     const TableFreshnessMap& aTableFreshness,
                                     uint32_t aFreshnessGuarantee,
                                     bool* aConfirmed) = 0;
 
+  virtual bool IsEmpty() = 0;
+
   virtual void ClearAll();
 
   template<typename T>
   static T* Cast(LookupCache* aThat) {
     return ((aThat && T::VER == aThat->Ver()) ? reinterpret_cast<T*>(aThat) : nullptr);
   }
 
 private:
@@ -195,16 +197,18 @@ public:
                        bool* aHas, uint32_t* aMatchLength,
                        bool* aFromCache) override;
 
   virtual void IsHashEntryConfirmed(const Completion& aEntry,
                                     const TableFreshnessMap& aTableFreshness,
                                     uint32_t aFreshnessGuarantee,
                                     bool* aConfirmed) override;
 
+  virtual bool IsEmpty() override;
+
   nsresult Build(AddPrefixArray& aAddPrefixes,
                  AddCompleteArray& aAddCompletes);
 
   nsresult GetPrefixes(FallibleTArray<uint32_t>& aAddPrefixes);
 
 #if DEBUG
   void DumpCompletions();
 #endif
--- a/toolkit/components/url-classifier/LookupCacheV4.cpp
+++ b/toolkit/components/url-classifier/LookupCacheV4.cpp
@@ -112,16 +112,24 @@ LookupCacheV4::IsHashEntryConfirmed(cons
                                     const TableFreshnessMap& aTableFreshness,
                                     uint32_t aFreshnessGuarantee,
                                     bool* aConfirmed)
 {
   // TODO : Bug 1311935 - Implement v4 caching
   *aConfirmed = true;
 }
 
+bool
+LookupCacheV4::IsEmpty()
+{
+  bool isEmpty;
+  mVLPrefixSet->IsEmpty(&isEmpty);
+  return isEmpty;
+}
+
 nsresult
 LookupCacheV4::Build(PrefixStringMap& aPrefixMap)
 {
   Telemetry::AutoTimer<Telemetry::URLCLASSIFIER_VLPS_CONSTRUCT_TIME> timer;
 
   return mVLPrefixSet->SetPrefixes(aPrefixMap);
 }
 
--- a/toolkit/components/url-classifier/LookupCacheV4.h
+++ b/toolkit/components/url-classifier/LookupCacheV4.h
@@ -28,16 +28,18 @@ public:
                        bool* aHas, uint32_t* aMatchLength,
                        bool* aFromCache) override;
 
   virtual void IsHashEntryConfirmed(const Completion& aEntry,
                                     const TableFreshnessMap& aTableFreshness,
                                     uint32_t aFreshnessGuarantee,
                                     bool* aConfirmed) override;
 
+  virtual bool IsEmpty() override;
+
   nsresult Build(PrefixStringMap& aPrefixMap);
 
   nsresult GetPrefixes(PrefixStringMap& aPrefixMap);
 
   // ApplyUpdate will merge data stored in aTableUpdate with prefixes in aInputMap.
   nsresult ApplyUpdate(TableUpdateV4* aTableUpdate,
                        PrefixStringMap& aInputMap,
                        PrefixStringMap& aOutputMap);