Bug 1533363 - Part 2: Add HTTP Traffic category Telemetry; r=chutten a=pascalc
☠☠ backed out by ca196717df07 ☠ ☠
authorLiang-Heng Chen <xeonchen@gmail.com>
Thu, 04 Apr 2019 21:36:39 +0000
changeset 526176 e27ad01b9daa2da02cca20e94b9d60ca862a21d4
parent 526175 a258da1f2a67b56af0f3fe8d817eb84a433c53c6
child 526177 cacfa16943741680d75d8e4812c15a63de1b5084
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschutten, pascalc
bugs1533363
milestone67.0
Bug 1533363 - Part 2: Add HTTP Traffic category Telemetry; r=chutten a=pascalc Differential Revision: https://phabricator.services.mozilla.com/D25135
netwerk/protocol/http/HttpTrafficAnalyzer.cpp
toolkit/components/telemetry/Histograms.json
toolkit/components/telemetry/Scalars.yaml
--- a/netwerk/protocol/http/HttpTrafficAnalyzer.cpp
+++ b/netwerk/protocol/http/HttpTrafficAnalyzer.cpp
@@ -2,16 +2,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "HttpTrafficAnalyzer.h"
 #include "HttpLog.h"
 
 #include "mozilla/StaticPrefs.h"
+#include "mozilla/Telemetry.h"
 #include "mozilla/Unused.h"
 
 namespace mozilla {
 namespace net {
 
 #define DEFINE_CATEGORY(_name, _idx) NS_LITERAL_CSTRING("Y=" #_idx "|" #_name),
 static const nsCString gKeyName[] = {
 #include "HttpTrafficAnalyzer.inc"
@@ -97,28 +98,33 @@ nsresult HttpTrafficAnalyzer::IncrementH
     HttpTrafficCategory aCategory) {
   MOZ_ASSERT(OnSocketThread(), "not on socket thread");
   MOZ_ASSERT(StaticPrefs::network_traffic_analyzer_enabled());
   MOZ_ASSERT(aCategory != HttpTrafficCategory::eInvalid, "invalid category");
 
   LOG(("HttpTrafficAnalyzer::IncrementHttpTransaction [%s] [this=%p]\n",
        gKeyName[aCategory].get(), this));
 
+  Telemetry::AccumulateCategoricalKeyed(
+      gKeyName[aCategory],
+      Telemetry::LABELS_HTTP_TRAFFIC_ANALYSIS::Transaction);
   return NS_OK;
 }
 
 nsresult HttpTrafficAnalyzer::IncrementHttpConnection(
     HttpTrafficCategory aCategory) {
   MOZ_ASSERT(OnSocketThread(), "not on socket thread");
   MOZ_ASSERT(StaticPrefs::network_traffic_analyzer_enabled());
   MOZ_ASSERT(aCategory != HttpTrafficCategory::eInvalid, "invalid category");
 
   LOG(("HttpTrafficAnalyzer::IncrementHttpConnection [%s] [this=%p]\n",
        gKeyName[aCategory].get(), this));
 
+  Telemetry::AccumulateCategoricalKeyed(
+      gKeyName[aCategory], Telemetry::LABELS_HTTP_TRAFFIC_ANALYSIS::Connection);
   return NS_OK;
 }
 
 nsresult HttpTrafficAnalyzer::IncrementHttpConnection(
     nsTArray<HttpTrafficCategory> &&aCategories) {
   MOZ_ASSERT(OnSocketThread(), "not on socket thread");
   MOZ_ASSERT(StaticPrefs::network_traffic_analyzer_enabled());
   MOZ_ASSERT(!aCategories.IsEmpty(), "empty category");
@@ -140,23 +146,30 @@ nsresult HttpTrafficAnalyzer::IncrementH
   if ((best == 0 || best == 11) && categories.Length() > 1) {
     best = categories[1];
   }
   Unused << IncrementHttpConnection(best);
 
   return NS_OK;
 }
 
+#define CLAMP_U32(num) \
+  Clamp<uint32_t>(num, 0, std::numeric_limits<uint32_t>::max())
+
 nsresult HttpTrafficAnalyzer::AccumulateHttpTransferredSize(
     HttpTrafficCategory aCategory, uint64_t aBytesRead, uint64_t aBytesSent) {
   MOZ_ASSERT(OnSocketThread(), "not on socket thread");
   MOZ_ASSERT(StaticPrefs::network_traffic_analyzer_enabled());
   MOZ_ASSERT(aCategory != HttpTrafficCategory::eInvalid, "invalid category");
 
   LOG(("HttpTrafficAnalyzer::AccumulateHttpTransferredSize [%s] rb=%" PRIu64 " "
        "sb=%" PRIu64 " [this=%p]\n",
        gKeyName[aCategory].get(), aBytesRead, aBytesSent, this));
 
+  // Telemetry supports uint32_t only.
+  auto total = CLAMP_U32(CLAMP_U32(aBytesRead) + CLAMP_U32(aBytesSent));
+  Telemetry::ScalarAdd(Telemetry::ScalarID::NETWORKING_DATA_TRANSFERRED,
+                       NS_ConvertUTF8toUTF16(gKeyName[aCategory]), total);
   return NS_OK;
 }
 
 }  // namespace net
 }  // namespace mozilla
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -14601,10 +14601,24 @@
           "IDB_InitDirectory",
           "IDB_GetFileSize",
           "IDB_GetWalFileSize",
           "IDB_GetUsage",
           "IDB_RemoveDBFiles"
       ],
       "keyed": true,
       "description": "Getting the number of errors in QuotaManager initialization."
+  },
+  "HTTP_TRAFFIC_ANALYSIS": {
+    "record_in_processes": ["main"],
+    "alert_emails": ["gachen@mozilla.com"],
+    "bug_numbers": [1533363],
+    "expires_in_version": "73",
+    "kind": "categorical",
+    "n_values": 8,
+    "labels": [
+      "Connection",
+      "Transaction"
+    ],
+    "keyed": true,
+    "description": "Numbers of HTTP transactions and connections by type. There are some categories separated by keys based on 4 parameters: 1. normal browsing or private browsing 2. first party or third party 3. class of service 4. tracking classification. Available keys are: ['Y=0|NormalFirstParty', 'Y=1|NormalThirdPartyOther', 'Y=2|NormalThirdPartyContentLeader', 'Y=3|NormalThirdPartyContentBackground', 'Y=4|NormalThirdPartyContentOther', 'Y=5|NormalThirdPartyBasicLeader', 'Y=6|NormalThirdPartyBasicBackground', 'Y=7|NormalThirdPartyBasicOther', 'Y=8|NormalThirdPartyFingerprintingLeader', 'Y=9|NormalThirdPartyFingerprintingBackground', 'Y=10|NormalThirdPartyFingerprintingOther', 'Y=11|PrivateFirstParty', 'Y=12|PrivateThirdPartyOther', 'Y=13|PrivateThirdPartyContentLeader', 'Y=14|PrivateThirdPartyContentBackground', 'Y=15|PrivateThirdPartyContentOther', 'Y=16|PrivateThirdPartyBasicLeader', 'Y=17|PrivateThirdPartyBasicBackground', 'Y=18|PrivateThirdPartyBasicOther', 'Y=19|PrivateThirdPartyFingerprintingLeader', 'Y=20|PrivateThirdPartyFingerprintingBackground', 'Y=21|PrivateThirdPartyFingerprintingOther']."
   }
 }
--- a/toolkit/components/telemetry/Scalars.yaml
+++ b/toolkit/components/telemetry/Scalars.yaml
@@ -2655,16 +2655,59 @@ script.preloader:
     kind: uint
     notification_emails:
       - dothayer@mozilla.com
     release_channel_collection: opt-out
     record_in_processes:
       - 'main'
       - 'content'
 
+networking:
+  data_transferred:
+    bug_numbers:
+      - 1533363
+    description: >
+      How many bytes of HTTP data transferred by type, there are some categories
+      separated by keys based on 4 parameters:
+        1. normal browsing or private browsing
+        2. first party or third party
+        3. class of service
+        4. tracking classification
+
+      Available keys are:
+        Y=0|NormalFirstParty
+        Y=1|NormalThirdPartyOther
+        Y=2|NormalThirdPartyContentLeader
+        Y=3|NormalThirdPartyContentBackground
+        Y=4|NormalThirdPartyContentOther
+        Y=5|NormalThirdPartyBasicLeader
+        Y=6|NormalThirdPartyBasicBackground
+        Y=7|NormalThirdPartyBasicOther
+        Y=8|NormalThirdPartyFingerprintingLeader
+        Y=9|NormalThirdPartyFingerprintingBackground
+        Y=10|NormalThirdPartyFingerprintingOther
+        Y=11|PrivateFirstParty
+        Y=12|PrivateThirdPartyOther
+        Y=13|PrivateThirdPartyContentLeader
+        Y=14|PrivateThirdPartyContentBackground
+        Y=15|PrivateThirdPartyContentOther
+        Y=16|PrivateThirdPartyBasicLeader
+        Y=17|PrivateThirdPartyBasicBackground
+        Y=18|PrivateThirdPartyBasicOther
+        Y=19|PrivateThirdPartyFingerprintingLeader
+        Y=20|PrivateThirdPartyFingerprintingBackground
+        Y=21|PrivateThirdPartyFingerprintingOther
+    expires: "73"
+    keyed: true
+    kind: uint
+    notification_emails:
+      - gachen@mozilla.com
+    record_in_processes:
+      - 'main'
+
 # The following section is for probes testing the Telemetry system. They will not be
 # submitted in pings and are only used for testing.
 telemetry.test:
   unsigned_int_kind:
     bug_numbers:
       - 1276190
     description: >
       This is a test uint type with a really long description, maybe spanning even multiple