forked from mirrors/gecko-dev
Most are brought over straightforwardly, their Telemetry callsites reworded to use Glean, with mirroring to the Telemetry probes taken care of by the Glean Interface For Firefox Telemetry (see the telemetry_mirror property). There were some special cases: * HistogramStopwatch becomes GleanStopwatch. After migration it was only serving Glean consumers. Could've used standard Glean APIs, but having something to hold the TimerIds was convenient. * GV_STARTUP_MODULES_MS was removed. It was configured to only report for the `firefox` product, but could only have a value in `geckoview_streaming`, so never reported data. * MEDIA_DECODING_PROCESS_CRASH was removed. It was configured to only report for the `firefox` product, but could only have a value in `geckoview_streaming`, so never reported data. * GV_CONTENT_PROCESS_LIFETIME_MS was removed. It was configured to only report for the `geckoview_streaming` product, meaning it only reported data when used with GVST to reach the Glean `geckoview.content_process_lifetime` metric. This is now accomplished directly. * GV_STARTUP_RUNTIME_MS was removed. Though it was configured to report data for both `firefox` and `geckoview_streaming` products, it only ever had values in geckoview. Its data continues to be reported via `geckoview.startup_runtime`. * gecko.version and gecko.build_id (Scalars) were removed. In Firefox Desktop this information is available in the `application` section of the Environment. In geckoview-using products, this information continues to be available via `geckoview.version` and `geckoview.build_id`. * GV_STARTUP_RUNTIME_MS and GV_CONTENT_PROCESS_LIFETIME_MS are handled oddly. Since those probes were recorded in the Java portion of the code, and that portion doesn't include Glean, we use `nativeAddHistogram` to relay the samples for those two pieces of instrumentation. If there will be more instrumentation landing in that part of the code, I recommend you review the instructions for including the Glean SDK in a library, and retire this use of JNI. Differential Revision: https://phabricator.services.mozilla.com/D200094
70 lines
2.2 KiB
JavaScript
70 lines
2.2 KiB
JavaScript
/* -*- mode: js; indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
/* 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/. */
|
|
|
|
export var BrowserTelemetryUtils = {
|
|
recordSiteOriginTelemetry(aWindows, aIsGeckoView) {
|
|
Services.tm.idleDispatchToMainThread(() => {
|
|
this._recordSiteOriginTelemetry(aWindows, aIsGeckoView);
|
|
});
|
|
},
|
|
|
|
computeSiteOriginCount(aWindows, aIsGeckoView) {
|
|
// Geckoview and Desktop work differently. On desktop, aBrowser objects
|
|
// holds an array of tabs which we can use to get the <browser> objects.
|
|
// In Geckoview, it is apps' responsibility to keep track of the tabs, so
|
|
// there isn't an easy way for us to get the tabs.
|
|
let tabs = [];
|
|
if (aIsGeckoView) {
|
|
// To get all active windows; Each tab has its own window
|
|
tabs = aWindows;
|
|
} else {
|
|
for (const win of aWindows) {
|
|
tabs = tabs.concat(win.gBrowser.tabs);
|
|
}
|
|
}
|
|
|
|
let topLevelBCs = [];
|
|
|
|
for (const tab of tabs) {
|
|
let browser;
|
|
if (aIsGeckoView) {
|
|
browser = tab.browser;
|
|
} else {
|
|
browser = tab.linkedBrowser;
|
|
}
|
|
|
|
if (browser.browsingContext) {
|
|
// This is the top level browsingContext
|
|
topLevelBCs.push(browser.browsingContext);
|
|
}
|
|
}
|
|
|
|
return CanonicalBrowsingContext.countSiteOrigins(topLevelBCs);
|
|
},
|
|
|
|
_recordSiteOriginTelemetry(aWindows, aIsGeckoView) {
|
|
let currentTime = Date.now();
|
|
|
|
// default is 5 minutes
|
|
if (!this.min_interval) {
|
|
this.min_interval = Services.prefs.getIntPref(
|
|
"telemetry.number_of_site_origin.min_interval",
|
|
300000
|
|
);
|
|
}
|
|
|
|
let originCount = this.computeSiteOriginCount(aWindows, aIsGeckoView);
|
|
|
|
// Discard the first load because most of the time the first load only has 1
|
|
// tab and 1 window open, so it is useless to report it.
|
|
if (!this._lastRecordSiteOrigin) {
|
|
this._lastRecordSiteOrigin = currentTime;
|
|
} else if (currentTime >= this._lastRecordSiteOrigin + this.min_interval) {
|
|
this._lastRecordSiteOrigin = currentTime;
|
|
|
|
Glean.geckoview.documentSiteOrigins.accumulateSamples([originCount]);
|
|
}
|
|
},
|
|
};
|