mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-11 05:39:41 +02:00
This patch introduces a new module in widget that implements a simple API to retrieve system information about a process and its threads. This function is wrapped into ChromeUtils.RequestProcInfo to return information about processes started by Firefox. The use case for this API is to monitor Firefox resources usage in projects like the battery usage done by the data science team. Differential Revision: https://phabricator.services.mozilla.com/D10069 --HG-- extra : moz-landing-system : lando
39 lines
1.3 KiB
JavaScript
39 lines
1.3 KiB
JavaScript
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
/* vim: set sts=2 sw=2 et tw=80: */
|
|
"use strict";
|
|
|
|
const ROOT_URL = "http://example.com/browser/widget/tests/browser";
|
|
const DUMMY_URL = ROOT_URL + "/dummy.html";
|
|
const { AppConstants } = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
|
|
const MAC = AppConstants.platform == "macosx";
|
|
|
|
|
|
add_task(async function test_proc_info() {
|
|
waitForExplicitFinish();
|
|
await BrowserTestUtils.withNewTab({ gBrowser, url: DUMMY_URL},
|
|
async function(browser) {
|
|
let cpuThreads = 0;
|
|
let cpuUser = 0;
|
|
for (let z = 0; z < 10; z++) {
|
|
let parentProc = await ChromeUtils.requestProcInfo();
|
|
cpuUser += parentProc.cpuUser;
|
|
|
|
for (var x = 0; x < parentProc.threads.length; x++) {
|
|
cpuThreads += parentProc.threads[x].cpuUser;
|
|
}
|
|
|
|
for (var i = 0; i < parentProc.children.length; i++) {
|
|
let childProc = parentProc.children[i];
|
|
for (var y = 0; y < childProc.threads.length; y++) {
|
|
cpuThreads += childProc.threads[y].cpuUser;
|
|
}
|
|
cpuUser += childProc.cpuUser;
|
|
}
|
|
}
|
|
// see https://bugzilla.mozilla.org/show_bug.cgi?id=1529023
|
|
if (!MAC) {
|
|
Assert.ok(cpuThreads > 0, "Got some cpu time in the threads");
|
|
}
|
|
Assert.ok(cpuUser > 0, "Got some cpu time");
|
|
});
|
|
});
|