From 9e59876bd7327033cd01277c3bd488caa39f3cb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Qu=C3=A8ze?= Date: Wed, 15 Dec 2021 22:18:32 +0000 Subject: [PATCH] Bug 1745444 - Merge TestTriggerGPUMetrics and TestTriggerRDDMetrics into a method taking a process type as parameter, r=chutten. Differential Revision: https://phabricator.services.mozilla.com/D133508 --- gfx/ipc/GPUParent.cpp | 4 ++- gfx/ipc/GPUParent.h | 3 +- gfx/ipc/GPUProcessManager.cpp | 8 +++-- gfx/ipc/GPUProcessManager.h | 3 +- gfx/ipc/PGPU.ipdl | 3 +- toolkit/components/glean/ipc/FOGIPC.cpp | 29 +++++++++++++------ toolkit/components/glean/ipc/FOGIPC.h | 13 +++------ .../glean/tests/browser/browser_fog_gpu.js | 2 +- .../glean/tests/browser/browser_fog_rdd.js | 2 +- toolkit/components/glean/xpcom/FOG.cpp | 12 ++------ toolkit/components/glean/xpcom/nsIFOG.idl | 14 ++++----- 11 files changed, 50 insertions(+), 43 deletions(-) diff --git a/gfx/ipc/GPUParent.cpp b/gfx/ipc/GPUParent.cpp index 3017fecea864..8e8d96352da0 100644 --- a/gfx/ipc/GPUParent.cpp +++ b/gfx/ipc/GPUParent.cpp @@ -625,8 +625,10 @@ mozilla::ipc::IPCResult GPUParent::RecvFlushFOGData( return IPC_OK(); } -mozilla::ipc::IPCResult GPUParent::RecvTestTriggerMetrics() { +mozilla::ipc::IPCResult GPUParent::RecvTestTriggerMetrics( + TestTriggerMetricsResolver&& aResolve) { mozilla::glean::test_only_ipc::a_counter.Add(45326); + aResolve(true); return IPC_OK(); } diff --git a/gfx/ipc/GPUParent.h b/gfx/ipc/GPUParent.h index aad128dd880a..debe7dfcae2a 100644 --- a/gfx/ipc/GPUParent.h +++ b/gfx/ipc/GPUParent.h @@ -99,7 +99,8 @@ class GPUParent final : public PGPUParent { mozilla::ipc::IPCResult RecvFlushFOGData(FlushFOGDataResolver&& aResolver); - mozilla::ipc::IPCResult RecvTestTriggerMetrics(); + mozilla::ipc::IPCResult RecvTestTriggerMetrics( + TestTriggerMetricsResolver&& aResolve); mozilla::ipc::IPCResult RecvCrashProcess(); diff --git a/gfx/ipc/GPUProcessManager.cpp b/gfx/ipc/GPUProcessManager.cpp index 89c7c8214208..9c494f063b8b 100644 --- a/gfx/ipc/GPUProcessManager.cpp +++ b/gfx/ipc/GPUProcessManager.cpp @@ -1273,10 +1273,14 @@ RefPtr GPUProcessManager::GetProcessMemoryReporter() { return new GPUMemoryReporter(); } -void GPUProcessManager::TestTriggerMetrics() { +RefPtr +GPUProcessManager::TestTriggerMetrics() { if (!NS_WARN_IF(!mGPUChild)) { - mGPUChild->SendTestTriggerMetrics(); + return mGPUChild->SendTestTriggerMetrics(); } + + return PGPUChild::TestTriggerMetricsPromise::CreateAndReject( + ipc::ResponseRejectReason::SendError, __func__); } } // namespace gfx diff --git a/gfx/ipc/GPUProcessManager.h b/gfx/ipc/GPUProcessManager.h index 503935923e26..69e284ca716d 100644 --- a/gfx/ipc/GPUProcessManager.h +++ b/gfx/ipc/GPUProcessManager.h @@ -12,6 +12,7 @@ #include "mozilla/UniquePtr.h" #include "mozilla/dom/ipc/IdType.h" #include "mozilla/gfx/GPUProcessHost.h" +#include "mozilla/gfx/PGPUChild.h" #include "mozilla/gfx/Point.h" #include "mozilla/ipc/ProtocolUtils.h" #include "mozilla/ipc/TaskFactory.h" @@ -200,7 +201,7 @@ class GPUProcessManager final : public GPUProcessHost::Listener { * * Trigger GPU-process test metric instrumentation. */ - void TestTriggerMetrics(); + RefPtr TestTriggerMetrics(); private: // Called from our xpcom-shutdown observer. diff --git a/gfx/ipc/PGPU.ipdl b/gfx/ipc/PGPU.ipdl index 8b332be00a12..33211a85edbc 100644 --- a/gfx/ipc/PGPU.ipdl +++ b/gfx/ipc/PGPU.ipdl @@ -120,7 +120,8 @@ parent: // Test-only method. // Asks the gpu process to trigger test-only instrumentation. - async TestTriggerMetrics(); + // The unused returned value is to have a promise we can await. + async TestTriggerMetrics() returns (bool unused); // Causes the GPU process to crash. Used for tests and diagnostics. async CrashProcess(); diff --git a/toolkit/components/glean/ipc/FOGIPC.cpp b/toolkit/components/glean/ipc/FOGIPC.cpp index 4c5909a80b26..0e0fb65df451 100644 --- a/toolkit/components/glean/ipc/FOGIPC.cpp +++ b/toolkit/components/glean/ipc/FOGIPC.cpp @@ -21,6 +21,7 @@ #include "mozilla/RDDParent.h" #include "mozilla/RDDProcessManager.h" #include "mozilla/Unused.h" +#include "nsIXULRuntime.h" #include "nsTArray.h" #include "nsThreadUtils.h" @@ -202,15 +203,25 @@ RefPtr FlushAndUseFOGData() { return ret; } -void TestTriggerGPUMetrics() { - gfx::GPUProcessManager::Get()->TestTriggerMetrics(); -} - -void TestTriggerRDDMetrics(const RefPtr& promise) { - RDDProcessManager::Get()->TestTriggerMetrics()->Then( - GetCurrentSerialEventTarget(), __func__, - [promise]() { promise->MaybeResolveWithUndefined(); }, - [promise]() { promise->MaybeRejectWithUndefined(); }); +void TestTriggerMetrics(uint32_t aProcessType, + const RefPtr& promise) { + switch (aProcessType) { + case nsIXULRuntime::PROCESS_TYPE_GPU: + gfx::GPUProcessManager::Get()->TestTriggerMetrics()->Then( + GetCurrentSerialEventTarget(), __func__, + [promise]() { promise->MaybeResolveWithUndefined(); }, + [promise]() { promise->MaybeRejectWithUndefined(); }); + break; + case nsIXULRuntime::PROCESS_TYPE_RDD: + RDDProcessManager::Get()->TestTriggerMetrics()->Then( + GetCurrentSerialEventTarget(), __func__, + [promise]() { promise->MaybeResolveWithUndefined(); }, + [promise]() { promise->MaybeRejectWithUndefined(); }); + break; + default: + promise->MaybeRejectWithUndefined(); + break; + } } } // namespace glean diff --git a/toolkit/components/glean/ipc/FOGIPC.h b/toolkit/components/glean/ipc/FOGIPC.h index ed37edb2da35..66cea2e25afd 100644 --- a/toolkit/components/glean/ipc/FOGIPC.h +++ b/toolkit/components/glean/ipc/FOGIPC.h @@ -62,19 +62,14 @@ RefPtr FlushAndUseFOGData(); /** * ** Test-only Method ** * - * Trigger GPU-process test instrumentation. - */ -void TestTriggerGPUMetrics(); - -/** - * ** Test-only Method ** - * - * Trigger RDD-process test instrumentation. + * Trigger GPU or RDD process test instrumentation. * + * @param processType - one of the PROCESS_TYPE_* constant from nsIXULRuntime. * @param promise - a promise that will be resolved when the data has made it to * the RDD process. */ -void TestTriggerRDDMetrics(const RefPtr& promise); +void TestTriggerMetrics(uint32_t processType, + const RefPtr& promise); } // namespace glean } // namespace mozilla diff --git a/toolkit/components/glean/tests/browser/browser_fog_gpu.js b/toolkit/components/glean/tests/browser/browser_fog_gpu.js index 10ca1db4f849..04707ef2fddf 100644 --- a/toolkit/components/glean/tests/browser/browser_fog_gpu.js +++ b/toolkit/components/glean/tests/browser/browser_fog_gpu.js @@ -26,7 +26,7 @@ add_task(async () => { "Ensure we begin without value." ); - Services.fog.testTriggerGPUMetrics(); + await Services.fog.testTriggerMetrics(Ci.nsIXULRuntime.PROCESS_TYPE_GPU); await Services.fog.testFlushAllChildren(); is( diff --git a/toolkit/components/glean/tests/browser/browser_fog_rdd.js b/toolkit/components/glean/tests/browser/browser_fog_rdd.js index ee5a044f2e91..97d185067823 100644 --- a/toolkit/components/glean/tests/browser/browser_fog_rdd.js +++ b/toolkit/components/glean/tests/browser/browser_fog_rdd.js @@ -47,7 +47,7 @@ add_task(async () => { await TestUtils.waitForCondition(async () => { try { - await Services.fog.testTriggerRDDMetrics(); + await Services.fog.testTriggerMetrics(Ci.nsIXULRuntime.PROCESS_TYPE_RDD); return true; } catch (e) { return false; diff --git a/toolkit/components/glean/xpcom/FOG.cpp b/toolkit/components/glean/xpcom/FOG.cpp index 609553b44362..1f8a08b55d3d 100644 --- a/toolkit/components/glean/xpcom/FOG.cpp +++ b/toolkit/components/glean/xpcom/FOG.cpp @@ -299,14 +299,8 @@ FOG::TestResetFOG(const nsACString& aDataPathOverride, } NS_IMETHODIMP -FOG::TestTriggerGPUMetrics() { - glean::TestTriggerGPUMetrics(); - return NS_OK; -} - -NS_IMETHODIMP -FOG::TestTriggerRDDMetrics(JSContext* aCx, - mozilla::dom::Promise** aOutPromise) { +FOG::TestTriggerMetrics(uint32_t aProcessType, JSContext* aCx, + mozilla::dom::Promise** aOutPromise) { NS_ENSURE_ARG(aOutPromise); *aOutPromise = nullptr; nsIGlobalObject* global = xpc::CurrentNativeGlobal(aCx); @@ -320,7 +314,7 @@ FOG::TestTriggerRDDMetrics(JSContext* aCx, return erv.StealNSResult(); } - glean::TestTriggerRDDMetrics(promise); + glean::TestTriggerMetrics(aProcessType, promise); promise.forget(aOutPromise); return NS_OK; diff --git a/toolkit/components/glean/xpcom/nsIFOG.idl b/toolkit/components/glean/xpcom/nsIFOG.idl index 350a9d1218bf..a23e0e40adb4 100644 --- a/toolkit/components/glean/xpcom/nsIFOG.idl +++ b/toolkit/components/glean/xpcom/nsIFOG.idl @@ -122,17 +122,15 @@ interface nsIFOG : nsISupports /** * ** Test-only Method ** * - * Trigger test metric instrumentation on the GPU process. - */ - void testTriggerGPUMetrics(); - - /** - * ** Test-only Method ** + * Trigger test metric instrumentation on the GPU, RDD or Socket process. * - * Trigger test metric instrumentation on the RDD process. + * @param aProcessType - A PROCESS_TYPE_* value from the constants defined + * in the nsIXULRuntime interface. * * @returns A promise that resolves when the test data has been added. + * The promise will be rejected if the process type is not supported + * or if sending the IPC to the child process fails. */ [implicit_jscontext] - Promise testTriggerRDDMetrics(); + Promise testTriggerMetrics(in unsigned long aProcessType); };