Bug 1838856 - Add a telemetry for measuring the calculating time of canvas random noises. r=tjr

Differential Revision: https://phabricator.services.mozilla.com/D181574
This commit is contained in:
Tim Huang 2023-06-26 08:36:59 +00:00
parent 4a67e420ee
commit 012fc1965d
6 changed files with 85 additions and 1 deletions

View File

@ -27,6 +27,7 @@ gecko_metrics = [
"toolkit/components/extensions/metrics.yaml",
"toolkit/components/glean/metrics.yaml",
"toolkit/components/pdfjs/metrics.yaml",
"toolkit/components/resistfingerprinting/metrics.yaml",
"toolkit/mozapps/extensions/metrics.yaml",
"toolkit/components/processtools/metrics.yaml",
"toolkit/components/translations/metrics.yaml",

View File

@ -0,0 +1,27 @@
# 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/.
# Adding a new metric? We have docs for that!
# https://firefox-source-docs.mozilla.org/toolkit/components/glean/user/new_definitions_file.html
$schema: moz://mozilla.org/schemas/glean/metrics/2-0-0
$tags:
- 'Core :: Privacy: Anti-Tracking'
fingerprinting.protection:
canvas_noise_calculate_time:
type: timing_distribution
time_unit: millisecond
description: >
Counts how long to generate canvas random noises.
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1838856
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1838856#c1
notification_emails:
- tihuang@mozilla.com
- tom@mozilla.com
- tschuster@mozilla.com
expires: never
telemetry_mirror: FINGERPRINTING_PROTECTION_CANVAS_NOISE_CALCULATE_TIME_MS

View File

@ -24,6 +24,7 @@
#include "mozilla/Atomics.h"
#include "mozilla/Casting.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/glean/GleanMetrics.h"
#include "mozilla/HashFunctions.h"
#include "mozilla/HelperMacros.h"
#include "mozilla/Likely.h"
@ -1296,10 +1297,17 @@ nsresult nsRFPService::RandomizePixels(nsICookieJarSettings* aCookieJarSettings,
return NS_OK;
}
auto timerId =
glean::fingerprinting_protection::canvas_noise_calculate_time.Start();
nsTArray<uint8_t> canvasKey;
nsresult rv = GenerateCanvasKeyFromImageData(aCookieJarSettings, aData, aSize,
canvasKey);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) {
glean::fingerprinting_protection::canvas_noise_calculate_time.Cancel(
std::move(timerId));
return rv;
}
// Calculate the number of pixels based on the given data size. One pixel uses
// 4 bytes that contains ARGB information.
@ -1352,5 +1360,8 @@ nsresult nsRFPService::RandomizePixels(nsICookieJarSettings* aCookieJarSettings,
aData[idx] = aData[idx] ^ (bit & 0x1);
}
glean::fingerprinting_protection::canvas_noise_calculate_time
.StopAndAccumulate(std::move(timerId));
return NS_OK;
}

View File

@ -510,6 +510,10 @@ async function runTest(enabled) {
for (let test of TEST_CASES) {
info(`Testing ${test.name}`);
// Clear telemetry before starting test.
Services.fog.testResetFOG();
let data = await test.extractCanvasData(tab.linkedBrowser);
let result = test.isDataRandomized(data[0], test.originalData);
@ -549,6 +553,17 @@ async function runTest(enabled) {
enabled ? "different" : "the same"
}.`
);
// Verify the telemetry is recorded if canvas randomization is enabled.
if (enabled) {
await Services.fog.testFlushAllChildren();
ok(
Glean.fingerprintingProtection.canvasNoiseCalculateTime.testGetValue()
.sum > 0,
"The telemetry of canvas randomization is recorded."
);
}
}
BrowserTestUtils.removeTab(tab);

View File

@ -235,6 +235,10 @@ async function runTest(enabled) {
for (let test of TEST_CASES) {
info(`Testing ${test.name} in the worker`);
// Clear telemetry before starting test.
Services.fog.testResetFOG();
let data = await await runFunctionInWorker(
tab.linkedBrowser,
test.extractCanvasData
@ -282,6 +286,17 @@ async function runTest(enabled) {
);
}
// Verify the telemetry is recorded if canvas randomization is enabled.
if (enabled) {
await Services.fog.testFlushAllChildren();
ok(
Glean.fingerprintingProtection.canvasNoiseCalculateTime.testGetValue()
.sum > 0,
"The telemetry of canvas randomization is recorded."
);
}
BrowserTestUtils.removeTab(tab);
BrowserTestUtils.removeTab(privateTab);
await BrowserTestUtils.closeWindow(privateWindow);

View File

@ -663,6 +663,21 @@
"releaseChannelCollection": "opt-out",
"description": "GPU Device Reset Reason (ok, hung, removed, reset, internal error, invalid call, out of memory)"
},
"FINGERPRINTING_PROTECTION_CANVAS_NOISE_CALCULATE_TIME_MS": {
"record_in_processes": ["content"],
"products": ["firefox"],
"alert_emails": [
"tihuang@mozilla.com",
"tom@mozilla.com",
"tschuster@mozilla.com"
],
"expires_in_version": "never",
"bug_numbers": [1838856],
"kind": "exponential",
"high": 600000,
"n_buckets": 100,
"description": "Counts how long to generate canvas random noises."
},
"FORCED_DEVICE_RESET_REASON": {
"record_in_processes": ["main", "content", "gpu"],
"products": ["firefox", "fennec"],