Bug 1794409 - Add UtilityProcess support for Telemetry r=chutten

Differential Revision: https://phabricator.services.mozilla.com/D158960
This commit is contained in:
Alexandre Lissy 2022-10-13 06:08:28 +00:00
parent a61030988f
commit 3b6b8e904e
10 changed files with 94 additions and 3 deletions

View File

@ -17,6 +17,14 @@ include "mozilla/ipc/ByteBufUtils.h";
using mozilla::dom::NativeThreadId from "mozilla/dom/NativeThreadId.h";
// Telemetry
using mozilla::Telemetry::HistogramAccumulation from "mozilla/TelemetryComms.h";
using mozilla::Telemetry::KeyedHistogramAccumulation from "mozilla/TelemetryComms.h";
using mozilla::Telemetry::ScalarAction from "mozilla/TelemetryComms.h";
using mozilla::Telemetry::KeyedScalarAction from "mozilla/TelemetryComms.h";
using mozilla::Telemetry::ChildEventData from "mozilla/TelemetryComms.h";
using mozilla::Telemetry::DiscardedData from "mozilla/TelemetryComms.h";
namespace mozilla {
namespace ipc {
@ -37,6 +45,14 @@ parent:
// https://firefox-source-docs.mozilla.org/toolkit/components/glean/dev/ipc.html
async FOGData(ByteBuf buf);
// Messages for sending telemetry to parent process.
async AccumulateChildHistograms(HistogramAccumulation[] accumulations);
async AccumulateChildKeyedHistograms(KeyedHistogramAccumulation[] accumulations);
async UpdateChildScalars(ScalarAction[] actions);
async UpdateChildKeyedScalars(KeyedScalarAction[] actions);
async RecordChildEvents(ChildEventData[] events);
async RecordDiscardedData(DiscardedData data);
async InitCompleted();
child:

View File

@ -15,6 +15,9 @@
#include "mozilla/ipc/ProcessChild.h"
#include "mozilla/FOGIPC.h"
#include "mozilla/Telemetry.h"
#include "mozilla/TelemetryIPC.h"
#include "nsHashPropertyBag.h"
#include "mozilla/Services.h"
#include "nsIObserverService.h"
@ -62,6 +65,48 @@ mozilla::ipc::IPCResult UtilityProcessParent::RecvFOGData(ByteBuf&& aBuf) {
return IPC_OK();
}
mozilla::ipc::IPCResult UtilityProcessParent::RecvAccumulateChildHistograms(
nsTArray<HistogramAccumulation>&& aAccumulations) {
TelemetryIPC::AccumulateChildHistograms(Telemetry::ProcessID::Utility,
aAccumulations);
return IPC_OK();
}
mozilla::ipc::IPCResult
UtilityProcessParent::RecvAccumulateChildKeyedHistograms(
nsTArray<KeyedHistogramAccumulation>&& aAccumulations) {
TelemetryIPC::AccumulateChildKeyedHistograms(Telemetry::ProcessID::Utility,
aAccumulations);
return IPC_OK();
}
mozilla::ipc::IPCResult UtilityProcessParent::RecvUpdateChildScalars(
nsTArray<ScalarAction>&& aScalarActions) {
TelemetryIPC::UpdateChildScalars(Telemetry::ProcessID::Utility,
aScalarActions);
return IPC_OK();
}
mozilla::ipc::IPCResult UtilityProcessParent::RecvUpdateChildKeyedScalars(
nsTArray<KeyedScalarAction>&& aScalarActions) {
TelemetryIPC::UpdateChildKeyedScalars(Telemetry::ProcessID::Utility,
aScalarActions);
return IPC_OK();
}
mozilla::ipc::IPCResult UtilityProcessParent::RecvRecordChildEvents(
nsTArray<mozilla::Telemetry::ChildEventData>&& aEvents) {
TelemetryIPC::RecordChildEvents(Telemetry::ProcessID::Utility, aEvents);
return IPC_OK();
}
mozilla::ipc::IPCResult UtilityProcessParent::RecvRecordDiscardedData(
const mozilla::Telemetry::DiscardedData& aDiscardedData) {
TelemetryIPC::RecordDiscardedData(Telemetry::ProcessID::Utility,
aDiscardedData);
return IPC_OK();
}
mozilla::ipc::IPCResult UtilityProcessParent::RecvInitCompleted() {
MOZ_ASSERT(mHost);
mHost->ResolvePromise();

View File

@ -38,6 +38,19 @@ class UtilityProcessParent final
mozilla::ipc::IPCResult RecvFOGData(ByteBuf&& aBuf);
mozilla::ipc::IPCResult RecvAccumulateChildHistograms(
nsTArray<HistogramAccumulation>&& aAccumulations);
mozilla::ipc::IPCResult RecvAccumulateChildKeyedHistograms(
nsTArray<KeyedHistogramAccumulation>&& aAccumulations);
mozilla::ipc::IPCResult RecvUpdateChildScalars(
nsTArray<ScalarAction>&& aScalarActions);
mozilla::ipc::IPCResult RecvUpdateChildKeyedScalars(
nsTArray<KeyedScalarAction>&& aScalarActions);
mozilla::ipc::IPCResult RecvRecordChildEvents(
nsTArray<ChildEventData>&& events);
mozilla::ipc::IPCResult RecvRecordDiscardedData(
const DiscardedData& aDiscardedData);
mozilla::ipc::IPCResult RecvInitCompleted();
void ActorDestroy(ActorDestroyReason aWhy) override;

View File

@ -31,3 +31,6 @@ dynamic:
socket:
gecko_enum: GeckoProcessType_Socket
description: This is the process that handles networking requests.
utility:
gecko_enum: GeckoProcessType_Utility
description: This is a process that will hold arbitrary IPC actors requiring specific sandboxing.

View File

@ -21,6 +21,7 @@ KNOWN_PROCESS_FLAGS = {
"content": "Content",
"gpu": "Gpu",
"socket": "Socket",
"utility": "Utility",
# Historical Values
"all_childs": "AllChildren", # Supporting files from before bug 1363725
}

View File

@ -1132,7 +1132,7 @@ already_AddRefed<nsITelemetry> TelemetryImpl::CreateTelemetryInstance() {
bool useTelemetry = false;
#ifndef FUZZING
if (XRE_IsParentProcess() || XRE_IsContentProcess() || XRE_IsGPUProcess() ||
XRE_IsSocketProcess()) {
XRE_IsSocketProcess() || XRE_IsUtilityProcess()) {
useTelemetry = true;
}
#endif

View File

@ -28,6 +28,7 @@ enum class RecordedProcessType : uint16_t {
Content = (1 << GeckoProcessType_Content),
Gpu = (1 << GeckoProcessType_GPU),
Socket = (1 << GeckoProcessType_Socket),
Utility = (1 << GeckoProcessType_Utility),
AllChildren = 0xFFFF - 1, // All the child processes (i.e. content, gpu, ...)
// Always `All-Main` to allow easy matching.
All = 0xFFFF // All the processes

View File

@ -11,6 +11,7 @@
#include "mozilla/dom/ContentChild.h"
#include "mozilla/gfx/GPUParent.h"
#include "mozilla/net/SocketProcessChild.h"
#include "mozilla/ipc/UtilityProcessChild.h"
#include "mozilla/SchedulerGroup.h"
#include "mozilla/StaticMutex.h"
#include "mozilla/StaticPrefs_toolkit.h"
@ -314,6 +315,10 @@ void TelemetryIPCAccumulator::IPCTimerFired(nsITimer* aTimer, void* aClosure) {
case GeckoProcessType_Socket:
SendAccumulatedData(mozilla::net::SocketProcessChild::GetSingleton());
break;
case GeckoProcessType_Utility:
SendAccumulatedData(
mozilla::ipc::UtilityProcessChild::GetSingleton().get());
break;
default:
MOZ_ASSERT_UNREACHABLE("Unsupported process type");
break;

View File

@ -650,6 +650,10 @@ var Impl = {
key => "socket" in measurements[key]
);
let measurementsContainUtility = Object.keys(measurements).some(
key => "utility" in measurements[key]
);
payloadObj.processes = {};
let processTypes = ["parent", "content", "extension", "dynamic"];
// Only include the GPU process if we've accumulated data for it.
@ -659,6 +663,9 @@ var Impl = {
if (measurementsContainSocket) {
processTypes.push("socket");
}
if (measurementsContainUtility) {
processTypes.push("utility");
}
// Collect per-process measurements.
for (const processType of processTypes) {

View File

@ -34,7 +34,7 @@ class TestParser(unittest.TestCase):
def test_valid_histogram(self):
SAMPLE_HISTOGRAM = {
"TEST_VALID_HISTOGRAM": {
"record_in_processes": ["main", "content", "socket"],
"record_in_processes": ["main", "content", "socket", "utility"],
"alert_emails": ["team@mozilla.xyz"],
"bug_numbers": [1383793],
"expires_in_version": "never",
@ -534,7 +534,7 @@ class TestParser(unittest.TestCase):
def test_enumerated_histogram_with_100_buckets(self):
SAMPLE_HISTOGRAM = {
"TEST_100_BUCKETS_HISTOGRAM": {
"record_in_processes": ["main", "content", "socket"],
"record_in_processes": ["main", "content", "socket", "utility"],
"alert_emails": ["team@mozilla.xyz"],
"bug_numbers": [1383793],
"expires_in_version": "never",