Skip to content

Commit

Permalink
Bug 1362800 - Expose geckoProfiler.getProfileAsArrayBuffer. r=kmag
Browse files Browse the repository at this point in the history
MozReview-Commit-ID: 7uFPWAhh25L

--HG--
extra : rebase_source : e34a37c10ea4fcdd2d886519536c047e9c715197
  • Loading branch information
mstange committed May 11, 2017
1 parent 7221a12 commit 37feda6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
15 changes: 14 additions & 1 deletion browser/components/extensions/ext-geckoProfiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const PREF_GET_SYMBOL_RULES = "extensions.geckoProfiler.getSymbolRules";

const ASYNC_STACKS_ENABLED = Services.prefs.getBoolPref(PREF_ASYNC_STACK, false);

var {
ExtensionError,
} = ExtensionUtils;

function parseSym(data) {
const worker = new ChromeWorker("resource://app/modules/ParseSymbols-worker.js");
const promise = new Promise((resolve, reject) => {
Expand Down Expand Up @@ -295,13 +299,22 @@ this.geckoProfiler = class extends ExtensionAPI {

async getProfile() {
if (!Services.profiler.IsActive()) {
throw new Error("The profiler is stopped. " +
throw new ExtensionError("The profiler is stopped. " +
"You need to start the profiler before you can capture a profile.");
}

return Services.profiler.getProfileDataAsync();
},

async getProfileAsArrayBuffer() {
if (!Services.profiler.IsActive()) {
throw new ExtensionError("The profiler is stopped. " +
"You need to start the profiler before you can capture a profile.");
}

return Services.profiler.getProfileDataAsArrayBuffer();
},

async getSymbols(debugName, breakpadId) {
if (symbolCache.size === 0) {
primeSymbolStore(Services.profiler.sharedLibraries);
Expand Down
7 changes: 7 additions & 0 deletions browser/components/extensions/schemas/geckoProfiler.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@
"async": true,
"parameters": []
},
{
"name": "getProfileAsArrayBuffer",
"type": "function",
"description": "Gathers the profile data from the current profiling session. The returned promise resolves to an array buffer that contains a JSON string.",
"async": true,
"parameters": []
},
{
"name": "getSymbols",
"type": "function",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ let getExtension = () => {
"The profile contains a GeckoMain thread.");
browser.test.sendMessage("tested profile");
break;
case "test profile as array buffer":
let arrayBuffer = await browser.geckoProfiler.getProfileAsArrayBuffer();
browser.test.assertTrue(arrayBuffer.byteLength >= 2, "The profile array buffer contains data.");
let textDecoder = new TextDecoder();
let profile = JSON.parse(textDecoder.decode(arrayBuffer));
browser.test.assertTrue("libs" in profile, "The profile contains libs.");
browser.test.assertTrue("meta" in profile, "The profile contains meta.");
browser.test.assertTrue("threads" in profile, "The profile contains threads.");
browser.test.assertTrue(profile.threads.some(t => t.name == "GeckoMain"),
"The profile contains a GeckoMain thread.");
browser.test.sendMessage("tested profile as array buffer");
break;
case "remove runningListener":
browser.geckoProfiler.onRunning.removeListener(runningListener);
browser.test.sendMessage("removed runningListener");
Expand Down Expand Up @@ -86,6 +98,9 @@ add_task(async function testProfilerControl() {
extension.sendMessage("test profile");
await extension.awaitMessage("tested profile");

extension.sendMessage("test profile as array buffer");
await extension.awaitMessage("tested profile as array buffer");

extension.sendMessage("pause");
await extension.awaitMessage("paused");

Expand Down

0 comments on commit 37feda6

Please sign in to comment.