Bug 1944631 - Migrate histograms to use Glean APIs for FX_SESSION_RESTORE_* histograms, r=chutten,sessionstore-reviewers,nsharpley.

Differential Revision: https://phabricator.services.mozilla.com/D238095
This commit is contained in:
Florian Quèze
2025-02-19 19:52:06 +00:00
parent 0c5eba3c2b
commit 3f36c09d17
6 changed files with 348 additions and 76 deletions

View File

@@ -271,12 +271,10 @@ var SessionFileInternal = {
path_key: key,
loadfail_reason: "N/A",
});
Services.telemetry
.getHistogramById("FX_SESSION_RESTORE_CORRUPT_FILE")
.add(false);
Services.telemetry
.getHistogramById("FX_SESSION_RESTORE_READ_FILE_MS")
.add(Date.now() - startMs);
Glean.sessionRestore.corruptFile.false.add();
Glean.sessionRestore.readFile.accumulateSingleSample(
Date.now() - startMs
);
lazy.sessionStoreLogger.debug(`Successful file read of ${key} file`);
break;
} catch (ex) {
@@ -324,9 +322,7 @@ var SessionFileInternal = {
} finally {
if (exists) {
noFilesFound = false;
Services.telemetry
.getHistogramById("FX_SESSION_RESTORE_CORRUPT_FILE")
.add(corrupted);
Glean.sessionRestore.corruptFile[corrupted ? "true" : "false"].add();
Glean.sessionRestore.backupCanBeLoadedSessionFile.record({
can_load: (!corrupted).toString(),
path_key: key,
@@ -351,9 +347,7 @@ var SessionFileInternal = {
// All files are corrupted if files found but none could deliver a result.
let allCorrupt = !noFilesFound && !result;
Services.telemetry
.getHistogramById("FX_SESSION_RESTORE_ALL_FILES_CORRUPT")
.add(allCorrupt);
Glean.sessionRestore.allFilesCorrupt[allCorrupt ? "true" : "false"].add();
if (!result) {
// If everything fails, start with an empty session.
@@ -432,7 +426,17 @@ var SessionFileInternal = {
promise = promise.then(
msg => {
// Record how long the write took.
this._recordTelemetry(msg.telemetry);
if (msg.telemetry.writeFileMs) {
Glean.sessionRestore.writeFile.accumulateSingleSample(
msg.telemetry.writeFileMs
);
}
if (msg.telemetry.fileSizeBytes) {
Glean.sessionRestore.fileSizeBytes.accumulate(
msg.telemetry.fileSizeBytes
);
}
this._successes++;
if (msg.result.upgradeBackup) {
// We have just completed a backup-on-upgrade, store the information
@@ -491,20 +495,4 @@ var SessionFileInternal = {
// because the state variables as sent to the writer have changed.
this._initialized = false;
},
_recordTelemetry(telemetry) {
for (let id of Object.keys(telemetry)) {
let value = telemetry[id];
let samples = [];
if (Array.isArray(value)) {
samples.push(...value);
} else {
samples.push(value);
}
let histogram = Services.telemetry.getHistogramById(id);
for (let sample of samples) {
histogram.add(sample);
}
}
},
};

View File

@@ -48,18 +48,6 @@ function notify(subject, topic) {
Services.obs.notifyObservers(subject, topic);
}
// TelemetryStopwatch helper functions.
function stopWatch(method) {
return function (...histograms) {
for (let hist of histograms) {
TelemetryStopwatch[method]("FX_SESSION_RESTORE_" + hist);
}
};
}
var stopWatchStart = stopWatch("start");
var stopWatchFinish = stopWatch("finish");
/**
* The external API implemented by the SessionSaver module.
*/
@@ -249,7 +237,7 @@ var SessionSaverInternal = {
return Promise.resolve();
}
stopWatchStart("COLLECT_DATA_MS");
let timerId = Glean.sessionRestore.collectData.start();
let state = lazy.SessionStore.getCurrentState(forceUpdateAllWindows);
lazy.PrivacyFilter.filterPrivateWindowsAndTabs(state);
@@ -284,7 +272,7 @@ var SessionSaverInternal = {
// Clear cookies and storage on clean shutdown.
this._maybeClearCookiesAndStorage(state);
stopWatchFinish("COLLECT_DATA_MS");
Glean.sessionRestore.collectData.stopAndAccumulate(timerId);
return this._writeState(state);
},

View File

@@ -1199,7 +1199,7 @@ var SessionStoreInternal = {
* Initialize the session using the state provided by SessionStartup
*/
initSession() {
TelemetryStopwatch.start("FX_SESSION_RESTORE_STARTUP_INIT_SESSION_MS");
let timerId = Glean.sessionRestore.startupInitSession.start();
let state;
let ss = lazy.SessionStartup;
let willRestore = ss.willRestore();
@@ -1326,7 +1326,7 @@ var SessionStoreInternal = {
this._prefBranch.setBoolPref("sessionstore.resume_session_once", false);
}
TelemetryStopwatch.finish("FX_SESSION_RESTORE_STARTUP_INIT_SESSION_MS");
Glean.sessionRestore.startupInitSession.stopAndAccumulate(timerId);
return state;
},
@@ -1581,9 +1581,7 @@ var SessionStoreInternal = {
return null;
}
TelemetryStopwatch.start(
"FX_SESSION_RESTORE_COLLECT_SESSION_HISTORY_MS"
);
let timerId = Glean.sessionRestore.collectSessionHistory.start();
let fromIndex = collectFull ? -1 : this._fromIndex;
this._fromIndex = kNoIndex;
@@ -1605,9 +1603,7 @@ var SessionStoreInternal = {
});
}
TelemetryStopwatch.finish(
"FX_SESSION_RESTORE_COLLECT_SESSION_HISTORY_MS"
);
Glean.sessionRestore.collectSessionHistory.stopAndAccumulate(timerId);
return historychange;
}
@@ -2190,12 +2186,10 @@ var SessionStoreInternal = {
if (initialState) {
Services.obs.notifyObservers(null, NOTIFY_RESTORING_ON_STARTUP);
}
TelemetryStopwatch.start(
"FX_SESSION_RESTORE_STARTUP_ONLOAD_INITIAL_WINDOW_MS"
);
let timerId = Glean.sessionRestore.startupOnloadInitialWindow.start();
this.initializeWindow(aWindow, initialState);
TelemetryStopwatch.finish(
"FX_SESSION_RESTORE_STARTUP_ONLOAD_INITIAL_WINDOW_MS"
Glean.sessionRestore.startupOnloadInitialWindow.stopAndAccumulate(
timerId
);
// Let everyone know we're done.
@@ -5196,7 +5190,7 @@ var SessionStoreInternal = {
var activeWindow = this._getTopWindow();
TelemetryStopwatch.start("FX_SESSION_RESTORE_COLLECT_ALL_WINDOWS_DATA_MS");
let timerId = Glean.sessionRestore.collectAllWindowsData.start();
if (lazy.RunState.isRunning) {
// update the data for all windows with activities since the last save operation.
let index = 0;
@@ -5215,7 +5209,7 @@ var SessionStoreInternal = {
}
DirtyWindows.clear();
}
TelemetryStopwatch.finish("FX_SESSION_RESTORE_COLLECT_ALL_WINDOWS_DATA_MS");
Glean.sessionRestore.collectAllWindowsData.stopAndAccumulate(timerId);
// An array that at the end will hold all current window data.
var total = [];
@@ -5479,7 +5473,7 @@ var SessionStoreInternal = {
this.onLoad(aWindow);
}
TelemetryStopwatch.start("FX_SESSION_RESTORE_RESTORE_WINDOW_MS");
let timerId = Glean.sessionRestore.restoreWindow.start();
// We're not returning from this before we end up calling restoreTabs
// for this window, so make sure we send the SSWindowStateBusy event.
@@ -5656,7 +5650,7 @@ var SessionStoreInternal = {
// set smoothScroll back to the original value
arrowScrollbox.smoothScroll = smoothScroll;
TelemetryStopwatch.finish("FX_SESSION_RESTORE_RESTORE_WINDOW_MS");
Glean.sessionRestore.restoreWindow.stopAndAccumulate(timerId);
this._setWindowStateReady(aWindow);

View File

@@ -232,8 +232,8 @@ const SessionWriterInternal = {
fileStat = await IOUtils.stat(this.Paths.recovery);
}
telemetry.FX_SESSION_RESTORE_WRITE_FILE_MS = Date.now() - startWriteMs;
telemetry.FX_SESSION_RESTORE_FILE_SIZE_BYTES = fileStat.size;
telemetry.writeFileMs = Date.now() - startWriteMs;
telemetry.fileSizeBytes = fileStat.size;
} catch (ex) {
// Don't throw immediately
exn = exn || ex;

View File

@@ -105,11 +105,9 @@ export var StartupPerformance = {
// Once we are done restoring tabs, update Telemetry.
let delta = this._latestRestoredTimeStamp - this._startTimeStamp;
if (isAutoRestore) {
Services.telemetry
.getHistogramById(
"FX_SESSION_RESTORE_AUTO_RESTORE_DURATION_UNTIL_EAGER_TABS_RESTORED_MS"
)
.add(delta);
Glean.sessionRestore.autoRestoreDurationUntilEagerTabsRestored.accumulateSingleSample(
delta
);
} else {
Services.telemetry
.getHistogramById(
@@ -117,15 +115,15 @@ export var StartupPerformance = {
)
.add(delta);
}
Services.telemetry
.getHistogramById("FX_SESSION_RESTORE_NUMBER_OF_EAGER_TABS_RESTORED")
.add(this._totalNumberOfEagerTabs);
Services.telemetry
.getHistogramById("FX_SESSION_RESTORE_NUMBER_OF_TABS_RESTORED")
.add(this._totalNumberOfTabs);
Services.telemetry
.getHistogramById("FX_SESSION_RESTORE_NUMBER_OF_WINDOWS_RESTORED")
.add(this._totalNumberOfWindows);
Glean.sessionRestore.numberOfEagerTabsRestored.accumulateSingleSample(
this._totalNumberOfEagerTabs
);
Glean.sessionRestore.numberOfTabsRestored.accumulateSingleSample(
this._totalNumberOfTabs
);
Glean.sessionRestore.numberOfWindowsRestored.accumulateSingleSample(
this._totalNumberOfWindows
);
// Reset
this._startTimeStamp = null;

View File

@@ -63,6 +63,310 @@ session_restore:
type: string
telemetry_mirror: Session_restore_ShutdownSuccess_SessionStartup
startup_init_session:
type: timing_distribution
description: >
Session restore: Time it takes to prepare the data structures for
restoring a session (ms)
This metric was generated to correspond to the Legacy Telemetry
exponential histogram FX_SESSION_RESTORE_STARTUP_INIT_SESSION_MS.
time_unit: millisecond
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1489524
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1489524
notification_emails:
- session-restore-telemetry-alerts@mozilla.com
expires: never
telemetry_mirror: FX_SESSION_RESTORE_STARTUP_INIT_SESSION_MS
startup_onload_initial_window:
type: timing_distribution
description: >
Session restore: Time it takes to finish restoration once we have first
opened a window (ms)
This metric was generated to correspond to the Legacy Telemetry
exponential histogram FX_SESSION_RESTORE_STARTUP_ONLOAD_INITIAL_WINDOW_MS.
time_unit: millisecond
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1489524
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1489524
notification_emails:
- session-restore-telemetry-alerts@mozilla.com
expires: never
telemetry_mirror: FX_SESSION_RESTORE_STARTUP_ONLOAD_INITIAL_WINDOW_MS
collect_all_windows_data:
type: timing_distribution
description: >
Session restore: Time to collect all window data (ms)
This metric was generated to correspond to the Legacy Telemetry
exponential histogram FX_SESSION_RESTORE_COLLECT_ALL_WINDOWS_DATA_MS.
time_unit: millisecond
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1944631
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1944631
notification_emails:
- session-restore-telemetry-alerts@mozilla.com
expires: never
telemetry_mirror: FX_SESSION_RESTORE_COLLECT_ALL_WINDOWS_DATA_MS
collect_data:
type: timing_distribution
description: >
Session restore: Time to collect all window and tab data (ms)
This metric was generated to correspond to the Legacy Telemetry
exponential histogram FX_SESSION_RESTORE_COLLECT_DATA_MS.
time_unit: millisecond
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1944631
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1944631
notification_emails:
- session-restore-telemetry-alerts@mozilla.com
expires: never
telemetry_mirror: FX_SESSION_RESTORE_COLLECT_DATA_MS
collect_session_history:
type: timing_distribution
description: >
Session restore: Duration of session history collection in the parent
process (ms).
This metric was generated to correspond to the Legacy Telemetry
exponential histogram FX_SESSION_RESTORE_COLLECT_SESSION_HISTORY_MS.
time_unit: millisecond
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1810704
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1810704
notification_emails:
- session-restore-telemetry-alerts@mozilla.com
- farre@mozilla.com
expires: never
telemetry_mirror: FX_SESSION_RESTORE_COLLECT_SESSION_HISTORY_MS
read_file:
type: timing_distribution
description: >
Session restore: Time to read the session data from the file on disk (ms)
This metric was generated to correspond to the Legacy Telemetry
exponential histogram FX_SESSION_RESTORE_READ_FILE_MS.
time_unit: millisecond
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1944631
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1944631
notification_emails:
- session-restore-telemetry-alerts@mozilla.com
expires: never
telemetry_mirror: FX_SESSION_RESTORE_READ_FILE_MS
write_file:
type: timing_distribution
description: >
Session restore: Time to write the session data to the file on disk (ms)
This metric was generated to correspond to the Legacy Telemetry
exponential histogram FX_SESSION_RESTORE_WRITE_FILE_MS.
time_unit: millisecond
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1944631
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1944631
notification_emails:
- session-restore-telemetry-alerts@mozilla.com
expires: never
telemetry_mirror: FX_SESSION_RESTORE_WRITE_FILE_MS
file_size_bytes:
type: memory_distribution
description: >
Session restore: The size of file sessionstore.js (bytes)
This metric was generated to correspond to the Legacy Telemetry
exponential histogram FX_SESSION_RESTORE_FILE_SIZE_BYTES.
memory_unit: byte
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1944631
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1944631
notification_emails:
- session-restore-telemetry-alerts@mozilla.com
expires: never
telemetry_mirror: FX_SESSION_RESTORE_FILE_SIZE_BYTES
corrupt_file:
type: labeled_counter
description: >
Session restore: Whether the file read on startup contained parse-able
JSON
This metric was generated to correspond to the Legacy Telemetry boolean
histogram FX_SESSION_RESTORE_CORRUPT_FILE.
labels:
- "false"
- "true"
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1944631
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1944631
notification_emails:
- session-restore-telemetry-alerts@mozilla.com
expires: never
telemetry_mirror: h#FX_SESSION_RESTORE_CORRUPT_FILE
all_files_corrupt:
type: labeled_counter
description: >
Session restore: Whether none of the backup files contained parse-able
JSON
This metric was generated to correspond to the Legacy Telemetry boolean
histogram FX_SESSION_RESTORE_ALL_FILES_CORRUPT.
labels:
- "false"
- "true"
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1944631
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1944631
notification_emails:
- session-restore-telemetry-alerts@mozilla.com
expires: never
telemetry_mirror: h#FX_SESSION_RESTORE_ALL_FILES_CORRUPT
restore_window:
type: timing_distribution
description: >
Session restore: Time spent blocking the main thread while restoring a
window state (ms)
This metric was generated to correspond to the Legacy Telemetry
exponential histogram FX_SESSION_RESTORE_RESTORE_WINDOW_MS.
time_unit: millisecond
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1489524
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1489524
notification_emails:
- session-restore-telemetry-alerts@mozilla.com
expires: never
telemetry_mirror: FX_SESSION_RESTORE_RESTORE_WINDOW_MS
auto_restore_duration_until_eager_tabs_restored:
type: timing_distribution
description: >
Session restore: If the browser is setup to auto-restore tabs, this probe
measures the time elapsed between the instant we start Session Restore and
the instant we have finished restoring tabs eagerly. At this stage, the
tabs that are restored on demand are not restored yet.
This metric was generated to correspond to the Legacy Telemetry
exponential histogram
FX_SESSION_RESTORE_AUTO_RESTORE_DURATION_UNTIL_EAGER_TABS_RESTORED_MS.
time_unit: millisecond
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1944631
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1944631
notification_emails:
- session-restore-telemetry-alerts@mozilla.com
expires: never
telemetry_mirror: FX_SESSION_RESTORE_AUTO_RESTORE_DURATION_UNTIL_EAGER_TABS_RESTORED_MS
manual_restore_duration_until_eager_tabs_restored:
type: timing_distribution
description: >
Session restore: If a session is restored by the user clicking on 'Restore
Session', this probe measures the time elapsed between the instant the
user has clicked and the instant we have finished restoring tabs eagerly.
At this stage, the tabs that are restored on demand are not restored yet.
This metric was generated to correspond to the Legacy Telemetry
exponential histogram
FX_SESSION_RESTORE_MANUAL_RESTORE_DURATION_UNTIL_EAGER_TABS_RESTORED_MS.
time_unit: millisecond
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1944631
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1944631
notification_emails:
- session-restore-telemetry-alerts@mozilla.com
expires: never
telemetry_mirror: FX_SESSION_RESTORE_MANUAL_RESTORE_DURATION_UNTIL_EAGER_TABS_RESTORED_MS
number_of_tabs_restored:
type: custom_distribution
description: >
Session restore: Number of tabs in the session that has just been
restored.
This metric was generated to correspond to the Legacy Telemetry
exponential histogram FX_SESSION_RESTORE_NUMBER_OF_TABS_RESTORED.
range_min: 1
range_max: 500
bucket_count: 20
histogram_type: exponential
unit: tabs
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1944631
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1944631
notification_emails:
- session-restore-telemetry-alerts@mozilla.com
expires: never
telemetry_mirror: FX_SESSION_RESTORE_NUMBER_OF_TABS_RESTORED
number_of_windows_restored:
type: custom_distribution
description: >
Session restore: Number of windows in the session that has just been
restored.
This metric was generated to correspond to the Legacy Telemetry enumerated
histogram FX_SESSION_RESTORE_NUMBER_OF_WINDOWS_RESTORED.
range_min: 0
range_max: 50
bucket_count: 51
histogram_type: linear
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1944631
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1944631
notification_emails:
- session-restore-telemetry-alerts@mozilla.com
expires: never
telemetry_mirror: FX_SESSION_RESTORE_NUMBER_OF_WINDOWS_RESTORED
number_of_eager_tabs_restored:
type: custom_distribution
description: >
Session restore: Number of tabs restored eagerly in the session that has
just been restored.
This metric was generated to correspond to the Legacy Telemetry enumerated
histogram FX_SESSION_RESTORE_NUMBER_OF_EAGER_TABS_RESTORED.
range_min: 0
range_max: 50
bucket_count: 51
histogram_type: linear
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1944631
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1944631
notification_emails:
- session-restore-telemetry-alerts@mozilla.com
expires: never
telemetry_mirror: FX_SESSION_RESTORE_NUMBER_OF_EAGER_TABS_RESTORED
browser.engagement:
sessionrestore_interstitial:
type: labeled_counter