Bug 1799727: Migrate the page load event to a custom ping that strips client id r=chutten,smaug

Differential Revision: https://phabricator.services.mozilla.com/D162311
This commit is contained in:
Denis Palmeiro 2022-12-12 18:45:57 +00:00
Родитель 1880ccce68
Коммит 7c67144ec5
12 изменённых файлов: 132 добавлений и 39 удалений

Просмотреть файл

@ -2042,7 +2042,11 @@ void Document::RecordPageLoadEventTelemetry(
}
aEventTelemetryData.loadType = mozilla::Some(loadTypeStr);
mozilla::glean::perf::page_load.Record(mozilla::Some(aEventTelemetryData));
// Sending a glean ping must be done on the parent process.
if (ContentChild* cc = ContentChild::GetSingleton()) {
cc->SendRecordPageLoadEvent(aEventTelemetryData);
}
}
void Document::AccumulatePageLoadTelemetry(

Просмотреть файл

@ -18,23 +18,31 @@ add_task(async function() {
Services.telemetry.clearEvents();
TelemetryTestUtils.assertNumberOfEvents(0);
// Perform page load
BrowserTestUtils.loadURI(browser, "https://example.com");
await BrowserTestUtils.browserLoaded(browser);
// Add checks for pageload ping and pageload event
let pingSubmitted = false;
GleanPings.pageload.testBeforeNextSubmit(reason => {
pingSubmitted = true;
Assert.equal(reason, "threshold");
let record = Glean.perf.pageLoad.testGetValue();
Assert.greaterOrEqual(
record.length,
30,
"Should have at least 30 page load events"
);
Assert.ok(record[0].extra.load_type === "NORMAL");
Assert.ok(record[0].extra.load_time > 0);
});
// Check that a page load event exists
let event_found = await TestUtils.waitForCondition(() => {
let events = Services.telemetry.snapshotEvents(ALL_CHANNELS, true).content;
if (events && events.length) {
events = events.filter(e => e[1] == "page_load");
if (events.length >= 1) {
return true;
}
}
return false;
}, "waiting for page load event to be flushed.");
// Perform page load 30 times to trigger the ping being sent
for (let i = 0; i < 30; i++) {
BrowserTestUtils.loadURI(browser, "https://example.com");
await BrowserTestUtils.browserLoaded(browser);
}
Assert.ok(event_found);
await BrowserTestUtils.waitForCondition(
() => pingSubmitted,
"Page load ping should have been submitted."
);
BrowserTestUtils.removeTab(tab);
});

Просмотреть файл

@ -88,6 +88,7 @@
#include "mozilla/StorageAccessAPIHelper.h"
#include "mozilla/StyleSheet.h"
#include "mozilla/StyleSheetInlines.h"
#include "mozilla/TaskController.h"
#include "mozilla/Telemetry.h"
#include "mozilla/TelemetryIPC.h"
#include "mozilla/Unused.h"
@ -142,6 +143,7 @@
#include "mozilla/extensions/StreamFilterParent.h"
#include "mozilla/gfx/GPUProcessManager.h"
#include "mozilla/gfx/gfxVars.h"
#include "mozilla/glean/GleanPings.h"
#include "mozilla/hal_sandbox/PHalParent.h"
#include "mozilla/intl/L10nRegistry.h"
#include "mozilla/intl/LocaleService.h"
@ -379,6 +381,9 @@ Maybe<TimeStamp> ContentParent::sLastContentProcessLaunch = Nothing();
/* static */
LogModule* ContentParent::GetLog() { return gProcessLog; }
/* static */
uint32_t ContentParent::sPageLoadEventCounter = 0;
#define NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC "ipc:network:set-offline"
#define NS_IPC_IOSERVICE_SET_CONNECTIVITY_TOPIC "ipc:network:set-connectivity"
@ -6508,6 +6513,23 @@ mozilla::ipc::IPCResult ContentParent::RecvRecordDiscardedData(
return IPC_OK();
}
mozilla::ipc::IPCResult ContentParent::RecvRecordPageLoadEvent(
const mozilla::glean::perf::PageLoadExtra& aPageLoadEventExtra) {
mozilla::glean::perf::page_load.Record(mozilla::Some(aPageLoadEventExtra));
// Send the PageLoadPing after every 30 page loads, or on startup.
if (++sPageLoadEventCounter >= 30) {
NS_SUCCEEDED(NS_DispatchToMainThreadQueue(
NS_NewRunnableFunction(
"PageLoadPingIdleTask",
[] { mozilla::glean_pings::Pageload.Submit("threshold"_ns); }),
EventQueuePriority::Idle));
sPageLoadEventCounter = 0;
}
return IPC_OK();
}
//////////////////////////////////////////////////////////////////
// PURLClassifierParent

Просмотреть файл

@ -1238,6 +1238,8 @@ class ContentParent final : public PContentParent,
nsTArray<ChildEventData>&& events);
mozilla::ipc::IPCResult RecvRecordDiscardedData(
const DiscardedData& aDiscardedData);
mozilla::ipc::IPCResult RecvRecordPageLoadEvent(
const mozilla::glean::perf::PageLoadExtra& aPageLoadEventExtra);
mozilla::ipc::IPCResult RecvRecordOrigin(const uint32_t& aMetricId,
const nsACString& aOrigin);
mozilla::ipc::IPCResult RecvReportContentBlockingLog(
@ -1655,6 +1657,7 @@ class ContentParent final : public PContentParent,
UniquePtr<mozilla::ipc::SharedPreferenceSerializer> mPrefSerializer;
static uint32_t sMaxContentProcesses;
static uint32_t sPageLoadEventCounter;
static Maybe<TimeStamp> sLastContentProcessLaunch;
bool mIsNotifiedShutdownSuccess = false;

Просмотреть файл

@ -73,7 +73,9 @@ include "mozilla/dom/CSPMessageUtils.h";
include "mozilla/dom/DocShellMessageUtils.h";
include "mozilla/dom/FeaturePolicyUtils.h";
include "mozilla/dom/MediaSessionIPCUtils.h";
include "mozilla/dom/PageLoadEventUtils.h";
include "mozilla/dom/ReferrerInfoUtils.h";
include "mozilla/glean/GleanMetrics.h";
include "mozilla/ipc/ByteBufUtils.h";
include "mozilla/ipc/TransportSecurityInfoUtils.h";
include "mozilla/ipc/URIUtils.h";
@ -118,6 +120,7 @@ using mozilla::Telemetry::ChildEventData from "mozilla/TelemetryComms.h";
#endif // defined(XP_WIN)
using mozilla::Telemetry::DiscardedData from "mozilla/TelemetryComms.h";
using mozilla::glean::perf::PageLoadExtra from "mozilla/glean/GleanMetrics.h";
[MoveOnly] using mozilla::CrossProcessMutexHandle from "mozilla/ipc/CrossProcessMutex.h";
using mozilla::dom::MaybeDiscardedBrowsingContext from "mozilla/dom/BrowsingContext.h";
using mozilla::dom::BrowsingContextTransaction from "mozilla/dom/BrowsingContext.h";
@ -1615,6 +1618,11 @@ parent:
async UnstoreAndBroadcastBlobURLUnregistration(nsCString url, nsIPrincipal principal);
/**
* Messages for communicating child Glean data to the parent process
*/
async RecordPageLoadEvent(PageLoadExtra event);
/**
* Messages for communicating child Telemetry to the parent process
*/

Просмотреть файл

@ -0,0 +1,38 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef mozilla_dom_page_load_event_utils_h__
#define mozilla_dom_page_load_event_utils_h__
#include "ipc/IPCMessageUtils.h"
#include "mozilla/glean/GleanMetrics.h"
namespace IPC {
template <>
struct ParamTraits<mozilla::glean::perf::PageLoadExtra> {
typedef mozilla::glean::perf::PageLoadExtra paramType;
static void Write(MessageWriter* aWriter, const paramType& aParam) {
WriteParam(aWriter, aParam.fcpTime);
WriteParam(aWriter, aParam.jsExecTime);
WriteParam(aWriter, aParam.loadTime);
WriteParam(aWriter, aParam.loadType);
WriteParam(aWriter, aParam.responseTime);
}
static bool Read(MessageReader* aReader, paramType* aResult) {
return ReadParam(aReader, &aResult->fcpTime) &&
ReadParam(aReader, &aResult->jsExecTime) &&
ReadParam(aReader, &aResult->loadTime) &&
ReadParam(aReader, &aResult->loadType) &&
ReadParam(aReader, &aResult->responseTime);
}
};
} // namespace IPC
#endif // mozilla_dom_page_load_event_utils_h__

Просмотреть файл

@ -62,6 +62,7 @@ EXPORTS.mozilla.dom += [
"MaybeDiscarded.h",
"MemoryReportRequest.h",
"NativeThreadId.h",
"PageLoadEventUtils.h",
"PermissionMessageUtils.h",
"ProcessActor.h",
"ProcessIsolation.h",

Просмотреть файл

@ -48,4 +48,5 @@ perf:
description:
"One of normal,reload,stop,link,history,error or other."
type: string
telemetry_mirror: Page_load_Toplevel_Content
send_in_pings:
- pageload

25
dom/pings.yaml Normal file
Просмотреть файл

@ -0,0 +1,25 @@
# 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/.
---
$schema: moz://mozilla.org/schemas/glean/pings/2-0-0
pageload:
description: |
Instrumentation collected during a page load.
reasons:
startup: |
Page load ping sent during startup.
threshold: |
Page load ping sent when a threshold limit
of page loads has been reached.
include_client_id: false
send_if_empty: false
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1759744
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1759744#c5
notification_emails:
- perf-telemetry-alerts@mozilla.com
- dpalmeiro@mozilla.com

Просмотреть файл

@ -65,6 +65,7 @@ metrics_yamls = (
# (Firefox Desktop, Firefox for Android, Focus for Android, etc.).
# Order is lexicographical, enforced by t/c/glean/tests/pytest/test_yaml_indices.py
gecko_pings = [
"dom/pings.yaml",
"toolkit/components/glean/pings.yaml",
]

Просмотреть файл

@ -2975,28 +2975,6 @@ slow_script_warning:
uri_type: The kind of script URL that hung.
uptime: How long the notification was up (ms).
page_load:
toplevel:
bug_numbers:
- 1759744
description: >
Recorded when a top level content document has been loaded.
products:
- "firefox"
record_in_processes: ["content"]
release_channel_collection: opt-out
expiry_version: "never"
notification_emails:
- dpalmeiro@mozilla.com
- perf-telemetry-alerts@mozilla.com
objects: ["content"]
extra_keys:
load_time: Time between loadEventStart and navigationStart, in ms.
response_time: Time between responseStart and navigationStart, in ms.
fcp_time: Time between firstContentfulPaint and navigationStart, in ms.
js_exec_time: Time spent executing JS during page load, in ms.
load_type: One of normal,reload,stop,link,history,error or other.
webrtc.ui:
share_display:
objects:

Просмотреть файл

@ -34,6 +34,7 @@
#include "mozilla/intl/LocaleService.h"
#include "mozilla/JSONWriter.h"
#include "mozilla/gfx/gfxVars.h"
#include "mozilla/glean/GleanPings.h"
#include "mozilla/widget/TextRecognition.h"
#include "BaseProfiler.h"
@ -5250,6 +5251,9 @@ int XREMain::XRE_mainStartup(bool* aExitFlag) {
flagFile->Remove(true);
}
// Flush any pending page load events.
mozilla::glean_pings::Pageload.Submit("startup"_ns);
return 0;
}