Bug 1715858 - Part1. Add a new telemetry histogram TAB_UNLOAD_TO_RELOAD. r=NeilDeakin

The new histogram `TAB_UNLOAD_TO_RELOAD` records how long a tab had been
unloaded until it was reload by a user.  With this data, we can evaluate
the selection logic to choose a tab to unload.  For example, if many of
unloaded tabs are reloaded within 30 seconds or so, we unload a wrong tab.

Differential Revision: https://phabricator.services.mozilla.com/D120019
This commit is contained in:
Toshihito Kikuchi 2021-07-22 21:15:00 +00:00
parent f2649915eb
commit a7bf50d1d1
5 changed files with 40 additions and 0 deletions

View File

@ -265,6 +265,22 @@
this._lastAccessed = this.selected ? Infinity : aDate || Date.now();
}
updateLastUnloadedByTabUnloader() {
this._lastUnloaded = Date.now();
}
recordTimeFromUnloadToReload() {
if (!this._lastUnloaded) {
return;
}
const diff_in_msec = Date.now() - this._lastUnloaded;
Services.telemetry
.getHistogramById("TAB_UNLOAD_TO_RELOAD")
.add(diff_in_msec / 1000);
delete this._lastUnloaded;
}
on_mouseover(event) {
if (event.target.classList.contains("tab-close-button")) {
this.mOverCloseButton = true;

View File

@ -1156,6 +1156,7 @@
}
if (!this._previewMode) {
newTab.recordTimeFromUnloadToReload();
newTab.updateLastAccessed();
oldTab.updateLastAccessed();

View File

@ -279,6 +279,7 @@ var TabUnloader = {
Services.console.logStringMessage(
`TabUnloader discarded <${remoteType}>`
);
tabInfo.tab.updateLastUnloadedByTabUnloader();
return true;
}
}

View File

@ -209,6 +209,10 @@ add_task(async function test() {
ok(!pinnedSoundTab.linkedPanel, "unloaded a pinned tab playing sound");
await compareTabOrder([]); // note that no tabs are returned when there are no discardable tabs.
const histogram = TelemetryTestUtils.getAndClearHistogram(
"TAB_UNLOAD_TO_RELOAD"
);
// It's possible that we're already in the memory-pressure state
// and we may receive the "ongoing" message.
const message = await pressureAndObserve("memory-pressure");
@ -224,6 +228,12 @@ add_task(async function test() {
await BrowserTestUtils.switchTab(gBrowser, tab1);
await BrowserTestUtils.switchTab(gBrowser, soundTab);
await BrowserTestUtils.switchTab(gBrowser, pinnedTab);
const hist = histogram.snapshot();
const numEvents = Object.values(hist.values).reduce((a, b) => a + b);
Assert.equal(numEvents, 3, "three tabs have been reloaded.");
// tab0 has never been unloaded. No data is added to the histogram.
await BrowserTestUtils.switchTab(gBrowser, tab0);
// Audio from the first sound tab was stopped when the tab was discarded earlier,

View File

@ -4957,6 +4957,18 @@
"releaseChannelCollection": "opt-out",
"description": "Number of tabs opened across all windows, collected at most every 5 minutes whenever the user interacts with the browser in the following ways: open tab/window, page load."
},
"TAB_UNLOAD_TO_RELOAD": {
"record_in_processes": ["main"],
"products": ["firefox"],
"alert_emails": ["tkikuchi@mozilla.com"],
"bug_numbers": [1715858],
"expires_in_version": "never",
"kind": "exponential",
"high": 100000,
"n_buckets": 50,
"releaseChannelCollection": "opt-out",
"description": "How long (sec) a tab had been unloaded until it was reloaded."
},
"LAZYLOAD_IMAGE_TOTAL": {
"record_in_processes": ["main", "content"],
"products": ["firefox"],