Bug 1322523 - Add telemetry to capture the length of long Safe Browsing V4 prefixes
MozReview-Commit-ID: HhWhyJvyG85
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -4812,16 +4812,25 @@
"URLCLASSIFIER_VLPS_LOAD_CORRUPT": {
"record_in_processes": ["main", "content"],
"alert_emails": ["safebrowsing-telemetry@mozilla.org"],
"expires_in_version": "58",
"kind": "boolean",
"bug_numbers": [1305581],
"description": "Whether or not a variable-length prefix set loaded from disk is corrupted (true = file corrupted)."
},
+ "URLCLASSIFIER_VLPS_LONG_PREFIXES": {
+ "record_in_processes": ["main", "content"],
+ "alert_emails": ["safebrowsing-telemetry@mozilla.org"],
+ "expires_in_version": "61",
+ "kind": "enumerated",
+ "n_values": 32,
+ "bug_numbers": [1322523],
+ "description": "Length of the first 20 long prefixes (> 4 bytes) received in a Safe Browsing V4 table during an update."
+ },
"URLCLASSIFIER_LC_PREFIXES": {
"record_in_processes": ["main", "content"],
"alert_emails": ["safebrowsing-telemetry@mozilla.org"],
"expires_in_version": "never",
"kind": "linear",
"high": 1500000,
"n_buckets": 15,
"description": "Size of the prefix cache in entries"
--- a/toolkit/components/url-classifier/HashStore.cpp
+++ b/toolkit/components/url-classifier/HashStore.cpp
@@ -37,16 +37,17 @@
#include "nsCheckSummedOutputStream.h"
#include "prio.h"
#include "mozilla/Logging.h"
#include "mozilla/IntegerPrintfMacros.h"
#include "mozilla/SizePrintfMacros.h"
#include "zlib.h"
#include "Classifier.h"
#include "nsUrlClassifierDBService.h"
+#include "mozilla/Telemetry.h"
// Main store for SafeBrowsing protocol data. We store
// known add/sub chunks, prefixes and completions in memory
// during an update, and serialize to disk.
// We do not store the add prefixes, those are retrieved by
// decompressing the PrefixSet cache whenever we need to apply
// an update.
//
@@ -147,21 +148,31 @@ TableUpdateV2::NewSubComplete(uint32_t a
sub->complete = aHash;
sub->subChunk = aSubChunk;
return NS_OK;
}
void
TableUpdateV4::NewPrefixes(int32_t aSize, std::string& aPrefixes)
{
+ NS_ENSURE_TRUE_VOID(aSize >= 4 && aSize <= COMPLETE_SIZE);
NS_ENSURE_TRUE_VOID(aPrefixes.size() % aSize == 0);
NS_ENSURE_TRUE_VOID(!mPrefixesMap.Get(aSize));
- if (LOG_ENABLED() && 4 == aSize) {
- int numOfPrefixes = aPrefixes.size() / 4;
+ int numOfPrefixes = aPrefixes.size() / aSize;
+
+ if (aSize > 4) {
+ // TODO Bug 1364043 we may have a better API to record multiple samples into
+ // histograms with one call
+#ifdef NIGHTLY_BUILD
+ for (int i = 0; i < std::min(20, numOfPrefixes); i++) {
+ Telemetry::Accumulate(Telemetry::URLCLASSIFIER_VLPS_LONG_PREFIXES, aSize);
+ }
+#endif
+ } else if (LOG_ENABLED()) {
uint32_t* p = (uint32_t*)aPrefixes.c_str();
// Dump the first/last 10 fixed-length prefixes for debugging.
LOG(("* The first 10 (maximum) fixed-length prefixes: "));
for (int i = 0; i < std::min(10, numOfPrefixes); i++) {
uint8_t* c = (uint8_t*)&p[i];
LOG(("%.2X%.2X%.2X%.2X", c[0], c[1], c[2], c[3]));
}