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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -47,8 +47,7 @@ function testPixel(ctx, x, y, r, g, b, a, fuzz) {
function reportResult(val) {
try {
let histogram = Services.telemetry.getHistogramById("GRAPHICS_SANITY_TEST");
histogram.add(val);
Services.telemetry.getHistogramById("GRAPHICS_SANITY_TEST").add(val);
} catch (e) {}
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;
if (!typeUuid.test(aType)) {
this._log.error("submitExternalPing - invalid ping type: " + aType);
let histogram = Services.telemetry.getKeyedHistogramById(
"TELEMETRY_INVALID_PING_TYPE_SUBMITTED"
);
histogram.add(aType, 1);
Services.telemetry
.getKeyedHistogramById("TELEMETRY_INVALID_PING_TYPE_SUBMITTED")
.add(aType, 1);
return Promise.reject(new Error("Invalid type string submitted."));
}
// Enforce that the payload is an object.
@@ -558,10 +557,9 @@ var Impl = {
this._log.error(
"submitExternalPing - invalid payload type: " + typeof aPayload
);
let histogram = Services.telemetry.getHistogramById(
"TELEMETRY_INVALID_PAYLOAD_SUBMITTED"
);
histogram.add(1);
Services.telemetry
.getHistogramById("TELEMETRY_INVALID_PAYLOAD_SUBMITTED")
.add(1);
return Promise.reject(new Error("Invalid payload type submitted."));
}