Bug 1935420 - rewrite JS code storing histograms in local variables to make automatic glean migration easier, r=chutten,fxview-reviewers,sync-reviewers,anti-tracking-reviewers,places-reviewers,markh,nsharpley.

Differential Revision: https://phabricator.services.mozilla.com/D234008
This commit is contained in:
Florian Quèze
2025-01-24 16:18:32 +00:00
parent eb2f90f870
commit 1ee252004d
16 changed files with 88 additions and 114 deletions

View File

@@ -995,11 +995,9 @@ var gXPInstallObserver = {
options.removeOnDismissal = true; options.removeOnDismissal = true;
options.persistent = false; options.persistent = false;
Services.telemetry
let secHistogram = Services.telemetry.getHistogramById("SECURITY_UI"); .getHistogramById("SECURITY_UI")
secHistogram.add( .add(Ci.nsISecurityUITelemetry.WARNING_ADDON_ASKING_PREVENTED);
Ci.nsISecurityUITelemetry.WARNING_ADDON_ASKING_PREVENTED
);
let popup = PopupNotifications.show( let popup = PopupNotifications.show(
browser, browser,
aTopic, aTopic,
@@ -1090,11 +1088,9 @@ var gXPInstallObserver = {
let learnMore = doc.getElementById("addon-install-blocked-info"); let learnMore = doc.getElementById("addon-install-blocked-info");
learnMore.setAttribute("support-page", article); learnMore.setAttribute("support-page", article);
}; };
Services.telemetry
let secHistogram = Services.telemetry.getHistogramById("SECURITY_UI"); .getHistogramById("SECURITY_UI")
secHistogram.add( .add(Ci.nsISecurityUITelemetry.WARNING_ADDON_ASKING_PREVENTED);
Ci.nsISecurityUITelemetry.WARNING_ADDON_ASKING_PREVENTED
);
const [ const [
installMsg, installMsg,
@@ -1109,10 +1105,12 @@ var gXPInstallObserver = {
]); ]);
const action = buildNotificationAction(installMsg, () => { const action = buildNotificationAction(installMsg, () => {
secHistogram.add( Services.telemetry
Ci.nsISecurityUITelemetry .getHistogramById("SECURITY_UI")
.WARNING_ADDON_ASKING_PREVENTED_CLICK_THROUGH .add(
); Ci.nsISecurityUITelemetry
.WARNING_ADDON_ASKING_PREVENTED_CLICK_THROUGH
);
installInfo.install(); installInfo.install();
}); });

View File

@@ -481,10 +481,9 @@ var gIdentityHandler = {
disableMixedContentProtection() { disableMixedContentProtection() {
// Use telemetry to measure how often unblocking happens // Use telemetry to measure how often unblocking happens
const kMIXED_CONTENT_UNBLOCK_EVENT = 2; const kMIXED_CONTENT_UNBLOCK_EVENT = 2;
let histogram = Services.telemetry.getHistogramById( Services.telemetry
"MIXED_CONTENT_UNBLOCK_COUNTER" .getHistogramById("MIXED_CONTENT_UNBLOCK_COUNTER")
); .add(kMIXED_CONTENT_UNBLOCK_EVENT);
histogram.add(kMIXED_CONTENT_UNBLOCK_EVENT);
SitePermissions.setForPrincipal( SitePermissions.setForPrincipal(
gBrowser.contentPrincipal, gBrowser.contentPrincipal,

View File

@@ -142,10 +142,9 @@ class HistoryInView extends ViewPage {
Glean.firefoxviewNext.historyVisits.record(); Glean.firefoxviewNext.historyVisits.record();
if (this.controller.searchQuery) { if (this.controller.searchQuery) {
const searchesHistogram = Services.telemetry.getKeyedHistogramById( Services.telemetry
"FIREFOX_VIEW_CUMULATIVE_SEARCHES" .getKeyedHistogramById("FIREFOX_VIEW_CUMULATIVE_SEARCHES")
); .add("history", this.cumulativeSearches);
searchesHistogram.add("history", this.cumulativeSearches);
this.cumulativeSearches = 0; this.cumulativeSearches = 0;
} }
} }

View File

@@ -497,13 +497,12 @@ class OpenTabsInViewCard extends ViewPageContent {
window: this.title || "Window 1 (Current)", window: this.title || "Window 1 (Current)",
}); });
if (this.searchQuery) { if (this.searchQuery) {
const searchesHistogram = Services.telemetry.getKeyedHistogramById( Services.telemetry
"FIREFOX_VIEW_CUMULATIVE_SEARCHES" .getKeyedHistogramById("FIREFOX_VIEW_CUMULATIVE_SEARCHES")
); .add(
searchesHistogram.add( this.recentBrowsing ? "recentbrowsing" : "opentabs",
this.recentBrowsing ? "recentbrowsing" : "opentabs", this.cumulativeSearches
this.cumulativeSearches );
);
this.cumulativeSearches = 0; this.cumulativeSearches = 0;
} }
} }

View File

@@ -225,13 +225,12 @@ class RecentlyClosedTabsInView extends ViewPage {
page: this.recentBrowsing ? "recentbrowsing" : "recentlyclosed", page: this.recentBrowsing ? "recentbrowsing" : "recentlyclosed",
}); });
if (this.searchQuery) { if (this.searchQuery) {
const searchesHistogram = Services.telemetry.getKeyedHistogramById( Services.telemetry
"FIREFOX_VIEW_CUMULATIVE_SEARCHES" .getKeyedHistogramById("FIREFOX_VIEW_CUMULATIVE_SEARCHES")
); .add(
searchesHistogram.add( this.recentBrowsing ? "recentbrowsing" : "recentlyclosed",
this.recentBrowsing ? "recentbrowsing" : "recentlyclosed", this.cumulativeSearches
this.cumulativeSearches );
);
this.cumulativeSearches = 0; this.cumulativeSearches = 0;
} }
} }

View File

@@ -168,13 +168,12 @@ class SyncedTabsInView extends ViewPage {
}); });
if (this.controller.searchQuery) { if (this.controller.searchQuery) {
const searchesHistogram = Services.telemetry.getKeyedHistogramById( Services.telemetry
"FIREFOX_VIEW_CUMULATIVE_SEARCHES" .getKeyedHistogramById("FIREFOX_VIEW_CUMULATIVE_SEARCHES")
); .add(
searchesHistogram.add( this.recentBrowsing ? "recentbrowsing" : "syncedtabs",
this.recentBrowsing ? "recentbrowsing" : "syncedtabs", this.cumulativeSearches
this.cumulativeSearches );
);
this.cumulativeSearches = 0; this.cumulativeSearches = 0;
} }
} }

View File

@@ -82,10 +82,9 @@ function searchBookmarks(event) {
} }
function updateTelemetry(urlsOpened = []) { function updateTelemetry(urlsOpened = []) {
let searchesHistogram = Services.telemetry.getHistogramById( Services.telemetry
"PLACES_BOOKMARKS_SEARCHBAR_CUMULATIVE_SEARCHES" .getHistogramById("PLACES_BOOKMARKS_SEARCHBAR_CUMULATIVE_SEARCHES")
); .add(gCumulativeSearches);
searchesHistogram.add(gCumulativeSearches);
clearCumulativeCounter(); clearCumulativeCounter();
Glean.sidebar.link.bookmarks.add(urlsOpened.length); Glean.sidebar.link.bookmarks.add(urlsOpened.length);

View File

@@ -105,14 +105,12 @@ function GroupBy(groupingType) {
} }
function updateTelemetry(urlsOpened = []) { function updateTelemetry(urlsOpened = []) {
let searchesHistogram = Services.telemetry.getHistogramById( Services.telemetry
"PLACES_SEARCHBAR_CUMULATIVE_SEARCHES" .getHistogramById("PLACES_SEARCHBAR_CUMULATIVE_SEARCHES")
); .add(gCumulativeSearches);
searchesHistogram.add(gCumulativeSearches); Services.telemetry
let filterCountHistogram = Services.telemetry.getHistogramById( .getHistogramById("PLACES_SEARCHBAR_CUMULATIVE_FILTER_COUNT")
"PLACES_SEARCHBAR_CUMULATIVE_FILTER_COUNT" .add(gCumulativeFilterCount);
);
filterCountHistogram.add(gCumulativeFilterCount);
clearCumulativeCounters(); clearCumulativeCounters();
Glean.sidebar.link.history.add(urlsOpened.length); Glean.sidebar.link.history.add(urlsOpened.length);

View File

@@ -1069,10 +1069,9 @@ function updateTelemetry(urlsOpened) {
link => !link.isBookmark && !PlacesUtils.nodeIsBookmark(link) link => !link.isBookmark && !PlacesUtils.nodeIsBookmark(link)
); );
if (!historyLinks.length) { if (!historyLinks.length) {
let searchesHistogram = Services.telemetry.getHistogramById( Services.telemetry
"PLACES_LIBRARY_CUMULATIVE_BOOKMARK_SEARCHES" .getHistogramById("PLACES_LIBRARY_CUMULATIVE_BOOKMARK_SEARCHES")
); .add(PlacesSearchBox.cumulativeBookmarkSearches);
searchesHistogram.add(PlacesSearchBox.cumulativeBookmarkSearches);
// Clear cumulative search counter // Clear cumulative search counter
PlacesSearchBox.cumulativeBookmarkSearches = 0; PlacesSearchBox.cumulativeBookmarkSearches = 0;
@@ -1082,10 +1081,9 @@ function updateTelemetry(urlsOpened) {
} }
// Record cumulative search count before selecting History link from Library // Record cumulative search count before selecting History link from Library
let searchesHistogram = Services.telemetry.getHistogramById( Services.telemetry
"PLACES_LIBRARY_CUMULATIVE_HISTORY_SEARCHES" .getHistogramById("PLACES_LIBRARY_CUMULATIVE_HISTORY_SEARCHES")
); .add(PlacesSearchBox.cumulativeHistorySearches);
searchesHistogram.add(PlacesSearchBox.cumulativeHistorySearches);
// Clear cumulative search counter // Clear cumulative search counter
PlacesSearchBox.cumulativeHistorySearches = 0; PlacesSearchBox.cumulativeHistorySearches = 0;

View File

@@ -285,10 +285,9 @@ let ShellServiceInternal = {
throw ex; throw ex;
} finally { } finally {
try { try {
const histogram = Services.telemetry.getHistogramById( Services.telemetry
"BROWSER_SET_DEFAULT_USER_CHOICE_RESULT" .getHistogramById("BROWSER_SET_DEFAULT_USER_CHOICE_RESULT")
); .add(telemetryResult);
histogram.add(telemetryResult);
} catch (ex) {} } catch (ex) {}
} }
}, },
@@ -320,10 +319,11 @@ let ShellServiceInternal = {
throw ex; throw ex;
} finally { } finally {
try { try {
const histogram = Services.telemetry.getHistogramById( Services.telemetry
"BROWSER_SET_DEFAULT_PDF_HANDLER_USER_CHOICE_RESULT" .getHistogramById(
); "BROWSER_SET_DEFAULT_PDF_HANDLER_USER_CHOICE_RESULT"
histogram.add(telemetryResult); )
.add(telemetryResult);
} catch (ex) {} } catch (ex) {}
} }
}, },

View File

@@ -118,10 +118,9 @@ class TextRecognitionModal {
* @param {number} textLength * @param {number} textLength
*/ */
static recordTextLengthTelemetry(textLength) { static recordTextLengthTelemetry(textLength) {
const histogram = Services.telemetry.getHistogramById( Services.telemetry
"TEXT_RECOGNITION_TEXT_LENGTH" .getHistogramById("TEXT_RECOGNITION_TEXT_LENGTH")
); .add(textLength);
histogram.add(textLength);
} }
setupCloseHandler() { setupCloseHandler() {

View File

@@ -450,8 +450,7 @@ Inspector.prototype = {
if (this.toolbox && this.toolbox.currentToolId == "inspector") { if (this.toolbox && this.toolbox.currentToolId == "inspector") {
const delay = this.panelWin.performance.now() - this._newRootStart; const delay = this.panelWin.performance.now() - this._newRootStart;
const telemetryKey = "DEVTOOLS_INSPECTOR_NEW_ROOT_TO_RELOAD_DELAY_MS"; const telemetryKey = "DEVTOOLS_INSPECTOR_NEW_ROOT_TO_RELOAD_DELAY_MS";
const histogram = this.telemetry.getHistogramById(telemetryKey); this.telemetry.getHistogramById(telemetryKey).add(delay);
histogram.add(delay);
} }
delete this._newRootStart; delete this._newRootStart;
} }

View File

@@ -1345,17 +1345,13 @@ Sync11Service.prototype = {
return this._lock( return this._lock(
"service.js: sync", "service.js: sync",
this._notify("sync", JSON.stringify({ why }), async function onNotify() { this._notify("sync", JSON.stringify({ why }), async function onNotify() {
let histogram = Services.telemetry.getHistogramById("WEAVE_START_COUNT").add(1);
Services.telemetry.getHistogramById("WEAVE_START_COUNT");
histogram.add(1);
let synchronizer = new EngineSynchronizer(this); let synchronizer = new EngineSynchronizer(this);
await synchronizer.sync(engineNamesToSync, why); // Might throw! await synchronizer.sync(engineNamesToSync, why); // Might throw!
Services.telemetry
histogram = Services.telemetry.getHistogramById( .getHistogramById("WEAVE_COMPLETE_SUCCESS_COUNT")
"WEAVE_COMPLETE_SUCCESS_COUNT" .add(1);
);
histogram.add(1);
// We successfully synchronized. // We successfully synchronized.
// Check if the identity wants to pre-fetch a migration sentinel from // Check if the identity wants to pre-fetch a migration sentinel from

View File

@@ -160,10 +160,11 @@ PurgeTrackerService.prototype = {
let timeRemaining = Math.floor( let timeRemaining = Math.floor(
(expireTimeMs - Date.now()) / 1000 / 60 / 60 / 24 (expireTimeMs - Date.now()) / 1000 / 60 / 60 / 24
); );
let permissionAgeHistogram = Services.telemetry.getHistogramById( Services.telemetry
"COOKIE_PURGING_TRACKERS_USER_INTERACTION_REMAINING_DAYS" .getHistogramById(
); "COOKIE_PURGING_TRACKERS_USER_INTERACTION_REMAINING_DAYS"
permissionAgeHistogram.add(timeRemaining); )
.add(timeRemaining);
this._telemetryData.notPurged.add(principal.baseDomain); this._telemetryData.notPurged.add(principal.baseDomain);
@@ -239,25 +240,19 @@ PurgeTrackerService.prototype = {
"privacy.purge_trackers.last_purge", "privacy.purge_trackers.last_purge",
now.toString() now.toString()
); );
Services.telemetry
let purgedHistogram = Services.telemetry.getHistogramById( .getHistogramById("COOKIE_PURGING_ORIGINS_PURGED")
"COOKIE_PURGING_ORIGINS_PURGED" .add(purged.size);
); Services.telemetry
purgedHistogram.add(purged.size); .getHistogramById("COOKIE_PURGING_TRACKERS_WITH_USER_INTERACTION")
.add(notPurged.size);
let notPurgedHistogram = Services.telemetry.getHistogramById(
"COOKIE_PURGING_TRACKERS_WITH_USER_INTERACTION"
);
notPurgedHistogram.add(notPurged.size);
let duration = durationIntervals let duration = durationIntervals
.map(([start, end]) => end - start) .map(([start, end]) => end - start)
.reduce((acc, cur) => acc + cur, 0); .reduce((acc, cur) => acc + cur, 0);
Services.telemetry
let durationHistogram = Services.telemetry.getHistogramById( .getHistogramById("COOKIE_PURGING_DURATION_MS")
"COOKIE_PURGING_DURATION_MS" .add(duration);
);
durationHistogram.add(duration);
}, },
/* /*

View File

@@ -47,8 +47,7 @@ function testPixel(ctx, x, y, r, g, b, a, fuzz) {
function reportResult(val) { function reportResult(val) {
try { try {
let histogram = Services.telemetry.getHistogramById("GRAPHICS_SANITY_TEST"); Services.telemetry.getHistogramById("GRAPHICS_SANITY_TEST").add(val);
histogram.add(val);
} catch (e) {} } catch (e) {}
Services.prefs.setBoolPref(RUNNING_PREF, false); Services.prefs.setBoolPref(RUNNING_PREF, false);

View File

@@ -543,10 +543,9 @@ var Impl = {
const typeUuid = /^[a-z0-9][a-z0-9-]+[a-z0-9]$/i; const typeUuid = /^[a-z0-9][a-z0-9-]+[a-z0-9]$/i;
if (!typeUuid.test(aType)) { if (!typeUuid.test(aType)) {
this._log.error("submitExternalPing - invalid ping type: " + aType); this._log.error("submitExternalPing - invalid ping type: " + aType);
let histogram = Services.telemetry.getKeyedHistogramById( Services.telemetry
"TELEMETRY_INVALID_PING_TYPE_SUBMITTED" .getKeyedHistogramById("TELEMETRY_INVALID_PING_TYPE_SUBMITTED")
); .add(aType, 1);
histogram.add(aType, 1);
return Promise.reject(new Error("Invalid type string submitted.")); return Promise.reject(new Error("Invalid type string submitted."));
} }
// Enforce that the payload is an object. // Enforce that the payload is an object.
@@ -558,10 +557,9 @@ var Impl = {
this._log.error( this._log.error(
"submitExternalPing - invalid payload type: " + typeof aPayload "submitExternalPing - invalid payload type: " + typeof aPayload
); );
let histogram = Services.telemetry.getHistogramById( Services.telemetry
"TELEMETRY_INVALID_PAYLOAD_SUBMITTED" .getHistogramById("TELEMETRY_INVALID_PAYLOAD_SUBMITTED")
); .add(1);
histogram.add(1);
return Promise.reject(new Error("Invalid payload type submitted.")); return Promise.reject(new Error("Invalid payload type submitted."));
} }