Skip to content

Commit

Permalink
Bug 1729026 - Test that GPU-process FOG metrics work r=Dexter,nical
Browse files Browse the repository at this point in the history
  • Loading branch information
chutten committed Dec 1, 2021
1 parent 76b90dc commit ec0960b
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 1 deletion.
6 changes: 6 additions & 0 deletions gfx/ipc/GPUParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "mozilla/dom/MemoryReportRequest.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/gfxVars.h"
#include "mozilla/glean/GleanMetrics.h"
#include "mozilla/image/ImageMemoryReporter.h"
#include "mozilla/ipc/CrashReporterClient.h"
#include "mozilla/ipc/ProcessChild.h"
Expand Down Expand Up @@ -624,6 +625,11 @@ mozilla::ipc::IPCResult GPUParent::RecvFlushFOGData(
return IPC_OK();
}

mozilla::ipc::IPCResult GPUParent::RecvTestTriggerMetrics() {
mozilla::glean::test_only_ipc::a_counter.Add(45326);
return IPC_OK();
}

void GPUParent::ActorDestroy(ActorDestroyReason aWhy) {
if (AbnormalShutdown == aWhy) {
NS_WARNING("Shutting down GPU process early due to a crash!");
Expand Down
2 changes: 2 additions & 0 deletions gfx/ipc/GPUParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class GPUParent final : public PGPUParent {

mozilla::ipc::IPCResult RecvFlushFOGData(FlushFOGDataResolver&& aResolver);

mozilla::ipc::IPCResult RecvTestTriggerMetrics();

void ActorDestroy(ActorDestroyReason aWhy) override;

private:
Expand Down
6 changes: 6 additions & 0 deletions gfx/ipc/GPUProcessManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1265,5 +1265,11 @@ RefPtr<MemoryReportingProcess> GPUProcessManager::GetProcessMemoryReporter() {
return new GPUMemoryReporter();
}

void GPUProcessManager::TestTriggerMetrics() {
if (!NS_WARN_IF(!mGPUChild)) {
mGPUChild->SendTestTriggerMetrics();
}
}

} // namespace gfx
} // namespace mozilla
7 changes: 7 additions & 0 deletions gfx/ipc/GPUProcessManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ class GPUProcessManager final : public GPUProcessHost::Listener {
// Returns the process host
GPUProcessHost* Process() { return mProcess; }

/*
* ** Test-only Method **
*
* Trigger GPU-process test metric instrumentation.
*/
void TestTriggerMetrics();

private:
// Called from our xpcom-shutdown observer.
void OnXPCOMShutdown();
Expand Down
4 changes: 4 additions & 0 deletions gfx/ipc/PGPU.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ parent:
// https://firefox-source-docs.mozilla.org/toolkit/components/glean/dev/ipc.html
async FlushFOGData() returns (ByteBuf buf);

// Test-only method.
// Asks the gpu process to trigger test-only instrumentation.
async TestTriggerMetrics();

child:
// Sent when the GPU process has initialized devices. This occurs once, after
// Init().
Expand Down
19 changes: 18 additions & 1 deletion toolkit/components/glean/docs/dev/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ To run all the things, here's the tl;dr:
&& ./mach rusttests && ./mach gtest FOG*
&& python3 ./mach python-test toolkit/components/glean/tests/pytest
&& ./mach test toolkit/components/glean/tests/xpcshell
&& ./mach telemetry-tests-client toolkit/components/telemetry/tests/marionette/tests/client/test_fog* --gecko-log "-"`
&& ./mach telemetry-tests-client toolkit/components/telemetry/tests/marionette/tests/client/test_fog* --gecko-log "-"
&& ./mach test toolkit/components/glean/tests/browser
`

## Logging

Expand Down Expand Up @@ -162,6 +164,21 @@ or the test runner will not be able to find it.
To run FOG's JS tests, run:
`./mach test toolkit/components/glean/tests/xpcshell`

## Non-content-process multiprocess (Browser Chrome Mochitests with Treeherder symbol `M(bcN)` for some number `N`)

To test e.g. the GPU process support you need a full Firefox browser:
xpcshell doesn't have the flexibility.
To test that and have access to privileged JS (i.e. `Glean` and `FOG` APIs),
we use browser-chrome-flavoured mochitests you can find in
[`browser/`](https://hg.mozilla.org/mozilla-central/file/tip/toolkit/components/glean/tests/browser).

If you need to add a new test file, remember to add it to the
[`browser.ini`](https://hg.mozilla.org/mozilla-central/file/tip/toolkit/components/glean/tests/browser/browser.ini)
manifest, or the test runner will not be able to find it.

To run FOG's browser chrome tests, run:
`./mach test toolkit/components/glean/tests/browser`

## Integration (Marionette, borrowing `telemetry-tests-client` Treeherder symbol `tt(c)`)

To test pings (See [bug 1681742](https://bugzilla.mozilla.org/show_bug.cgi?id=1681742))
Expand Down
4 changes: 4 additions & 0 deletions toolkit/components/glean/ipc/FOGIPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,9 @@ RefPtr<GenericPromise> FlushAndUseFOGData() {
return ret;
}

void TestTriggerGPUMetrics() {
gfx::GPUProcessManager::Get()->TestTriggerMetrics();
}

} // namespace glean
} // namespace mozilla
7 changes: 7 additions & 0 deletions toolkit/components/glean/ipc/FOGIPC.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ void SendFOGData(ipc::ByteBuf&& buf);
*/
RefPtr<GenericPromise> FlushAndUseFOGData();

/**
* ** Test-only Method **
*
* Trigger GPU-process test instrumentation.
*/
void TestTriggerGPUMetrics();

} // namespace glean
} // namespace mozilla

Expand Down
4 changes: 4 additions & 0 deletions toolkit/components/glean/tests/browser/browser.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[DEFAULT]
support-files =

[browser_fog_gpu.js]
36 changes: 36 additions & 0 deletions toolkit/components/glean/tests/browser/browser_fog_gpu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Glean's here on `window`, but eslint doesn't know that. bug 1715542.
/* global Glean:false */

add_task(async () => {
if (
!(await ChromeUtils.requestProcInfo()).children.some(p => p.type == "gpu")
) {
ok(
true,
'No GPU process? No test. Try again with --setpref "layers.gpu-process.force-enabled=true".'
);
return;
}
ok(true, "GPU Process found: Let's test.");

is(
undefined,
Glean.testOnlyIpc.aCounter.testGetValue(),
"Ensure we begin without value."
);

let FOG = Cc["@mozilla.org/toolkit/glean;1"].createInstance(Ci.nsIFOG);
FOG.testTriggerGPUMetrics();
await FOG.testFlushAllChildren();

is(
45326, // See gfx/ipc/GPUParent.cpp's RecvTestTriggerMetrics().
Glean.testOnlyIpc.aCounter.testGetValue(),
"Ensure the GPU-process-set value shows up in the parent process."
);
});
2 changes: 2 additions & 0 deletions toolkit/components/glean/tests/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ TEST_DIRS += ["gtest"]

XPCSHELL_TESTS_MANIFESTS += ["xpcshell/xpcshell.ini"]

BROWSER_CHROME_MANIFESTS += ["browser/browser.ini"]

with Files("**"):
BUG_COMPONENT = ("Toolkit", "Telemetry")
6 changes: 6 additions & 0 deletions toolkit/components/glean/xpcom/FOG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,12 @@ FOG::TestResetFOG(const nsACString& aDataPathOverride,
return glean::impl::fog_test_reset(&aDataPathOverride, &aAppIdOverride);
}

NS_IMETHODIMP
FOG::TestTriggerGPUMetrics() {
glean::TestTriggerGPUMetrics();
return NS_OK;
}

NS_IMPL_ISUPPORTS(FOG, nsIFOG, nsIObserver)

} // namespace mozilla
7 changes: 7 additions & 0 deletions toolkit/components/glean/xpcom/nsIFOG.idl
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,11 @@ interface nsIFOG : nsISupports
* Reset FOG and the Glean SDK, clearing storage.
*/
void testResetFOG([optional] in AUTF8String aDataPathOverride, [optional] in AUTF8String aAppIdOverride);

/**
* ** Test-only Method **
*
* Trigger test metric instrumentation on the GPU process.
*/
void testTriggerGPUMetrics();
};

0 comments on commit ec0960b

Please sign in to comment.