Bug 1074789 - Adjust DNS renewal time telemetry to take TTL experiments into consideration r=mcmanus
authorSteve Workman <sworkman@mozilla.com>
Tue, 07 Oct 2014 14:57:48 -0700
changeset 210823 b2162376e0656484eafa8b61418979084786b347
parent 210822 9951cc945fcbade4b818828368dcf894b7c1e630
child 210824 c0d3ea180fe0442d932285e443c1f51d04d97d6a
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersmcmanus
bugs1074789
milestone36.0a1
Bug 1074789 - Adjust DNS renewal time telemetry to take TTL experiments into consideration r=mcmanus
netwerk/dns/nsHostResolver.cpp
toolkit/components/telemetry/Histograms.json
--- a/netwerk/dns/nsHostResolver.cpp
+++ b/netwerk/dns/nsHostResolver.cpp
@@ -261,16 +261,57 @@ GetBlacklistCountHistogram(DnsExpiration
         case DNS_EXP_VARIANT_UNSET:
             ; // Fall through
     }
 
     MOZ_ASSERT_UNREACHABLE("Invalid variant.");
     return DNS_BLACKLIST_COUNT_VAR_CONTROL_LOW;
 }
 
+static mozilla::Telemetry::ID
+GetRenewalTimeHistogram(DnsExpirationVariant aVariant)
+{
+    using namespace mozilla::Telemetry;
+
+#ifdef TTL_AVAILABLE
+    switch (sDnsVariant) {
+        case DNS_EXP_VARIANT_CONTROL:
+            return DNS_RENEWAL_TIME;
+        case DNS_EXP_VARIANT_TTL_ONLY:
+            return DNS_RENEWAL_TIME__TTL_ONLY_EXPT;
+        case DNS_EXP_VARIANT_TTL_PLUS_CONST_GRACE:
+            return DNS_RENEWAL_TIME__TTL_PLUS_CONST_GRACE_EXPT;
+        default:
+            MOZ_ASSERT_UNREACHABLE("Invalid variant.");
+    }
+#endif
+    return DNS_RENEWAL_TIME;
+}
+
+static mozilla::Telemetry::ID
+GetRenewalTimeForTTLHistogram(DnsExpirationVariant aVariant)
+{
+    using namespace mozilla::Telemetry;
+
+#ifdef TTL_AVAILABLE
+    switch (sDnsVariant) {
+        case DNS_EXP_VARIANT_CONTROL:
+            MOZ_ASSERT_UNREACHABLE("No TTL for Control Expt.");
+            return DNS_RENEWAL_TIME;
+        case DNS_EXP_VARIANT_TTL_ONLY:
+            return DNS_RENEWAL_TIME_FOR_TTL__TTL_ONLY_EXPT;
+        case DNS_EXP_VARIANT_TTL_PLUS_CONST_GRACE:
+            return DNS_RENEWAL_TIME_FOR_TTL__TTL_PLUS_CONST_GRACE_EXPT;
+        default:
+            MOZ_ASSERT_UNREACHABLE("Invalid variant.");
+    }
+#endif
+    return DNS_RENEWAL_TIME;
+}
+
 // this macro filters out any flags that are not used when constructing the
 // host key.  the significant flags are those that would affect the resulting
 // host record (i.e., the flags that are passed down to PR_GetAddrInfoByName).
 #define RES_KEY_FLAGS(_f) ((_f) & nsHostResolver::RES_CANON_NAME)
 
 nsHostRecord::nsHostRecord(const nsHostKey *key)
     : addr_info_lock("nsHostRecord.addr_info_lock")
     , addr_info_gencnt(0)
@@ -1605,22 +1646,29 @@ nsHostResolver::ThreadFunc(void *arg)
             status = GetAddrInfo(rec->host, af, flags, &ai, getTtl);
         }
 #endif
 
         TimeDuration elapsed = TimeStamp::Now() - startTime;
         uint32_t millis = static_cast<uint32_t>(elapsed.ToMilliseconds());
 
         if (NS_SUCCEEDED(status)) {
-            Telemetry::Accumulate(!rec->addr_info_gencnt ?
-                                    Telemetry::DNS_LOOKUP_TIME :
-                                    Telemetry::DNS_RENEWAL_TIME,
-                                  millis);
-        }
-        else {
+            Telemetry::ID histogramID;
+            if (!rec->addr_info_gencnt) {
+                // Time for initial lookup.
+                histogramID = Telemetry::DNS_LOOKUP_TIME;
+            } else if (!getTtl) {
+                // Time for renewal; categorized by expiration strategy.
+                histogramID = GetRenewalTimeHistogram(sDnsVariant);
+            } else {
+                // Time to get TTL; categorized by expiration strategy.
+                histogramID = GetRenewalTimeForTTLHistogram(sDnsVariant);
+            }
+            Telemetry::Accumulate(histogramID, millis);
+        } else {
             Telemetry::Accumulate(Telemetry::DNS_FAILED_LOOKUP_TIME, millis);
         }
 
         // OnLookupComplete may release "rec", long before we lose it.
         LOG(("DNS lookup thread - lookup completed for host [%s]: %s.\n",
              rec->host, ai ? "success" : "failure: unknown host"));
         if (LOOKUP_RESOLVEAGAIN == resolver->OnLookupComplete(rec, status, ai)) {
             // leave 'rec' assigned and loop to make a renewed host resolve
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -2140,16 +2140,56 @@
   "DNS_RENEWAL_TIME": {
     "expires_in_version": "never",
     "kind": "exponential",
     "high": "60000",
     "n_buckets": 50,
     "extended_statistics_ok": true,
     "description": "Time for a renewed DNS OS resolution (msec)"
   },
+  "DNS_RENEWAL_TIME_FOR_TTL": {
+    "expires_in_version": "never",
+    "kind": "exponential",
+    "high": "60000",
+    "n_buckets": 50,
+    "extended_statistics_ok": true,
+    "description": "Time for a DNS OS resolution (msec) used to get TTL"
+  },
+  "DNS_RENEWAL_TIME_FOR_TTL__TTL_ONLY_EXPT": {
+    "expires_in_version": "never",
+    "kind": "exponential",
+    "high": "60000",
+    "n_buckets": 50,
+    "extended_statistics_ok": true,
+    "description": "Time for a DNS OS resolution (msec) used to get TTL - TTL Only Experiment"
+  },
+  "DNS_RENEWAL_TIME_FOR_TTL__TTL_PLUS_CONST_GRACE_EXPT": {
+    "expires_in_version": "never",
+    "kind": "exponential",
+    "high": "60000",
+    "n_buckets": 50,
+    "extended_statistics_ok": true,
+    "description": "Time for a DNS OS resolution (msec) used to get TTL - TTL + Const Grace Period Experiment"
+  },
+  "DNS_RENEWAL_TIME__TTL_ONLY_EXPT": {
+    "expires_in_version": "never",
+    "kind": "exponential",
+    "high": "60000",
+    "n_buckets": 50,
+    "extended_statistics_ok": true,
+    "description": "Time for a renewed DNS OS resolution (msec) - TTL Only Experiment"
+  },
+  "DNS_RENEWAL_TIME__TTL_PLUS_CONST_GRACE_EXPT": {
+    "expires_in_version": "never",
+    "kind": "exponential",
+    "high": "60000",
+    "n_buckets": 50,
+    "extended_statistics_ok": true,
+    "description": "Time for a renewed DNS OS resolution (msec) - TTL + Const Grace Period Experiment"
+  },
   "DNS_FAILED_LOOKUP_TIME": {
     "expires_in_version": "never",
     "kind": "exponential",
     "high": "60000",
     "n_buckets": 50,
     "extended_statistics_ok": true,
     "description": "Time for an unsuccessful DNS OS resolution (msec)"
   },