forked from mirrors/gecko-dev
In order to rewrite the Gecko Profiler add-on as a WebExtension, we need an API for the profiler which allows us to control the nsIProfiler, and symbolicate the stacks that it provides. This is the implementation of the simpler parts of that API. TODO: - Support profiling of remote targets through a new devtools API. - Support the dump_syms breakpad code which was asm.js in the old extension by directly calling into native code. - Figure out a faster way to send the large volume of data from getSymbols all the way from our extension down to the content process and then into the page's context. MozReview-Commit-ID: JzDbV4l2eXd --HG-- extra : rebase_source : fee9acfaa522372c22c61f9b0f1cab13d5da2a86
49 lines
1.3 KiB
JavaScript
49 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";
|
|
|
|
/* exported ParseSymbols */
|
|
|
|
var EXPORTED_SYMBOLS = ["ParseSymbols"];
|
|
|
|
function convertStringArrayToUint8BufferWithIndex(array, approximateLength) {
|
|
const index = new Uint32Array(array.length + 1);
|
|
|
|
const textEncoder = new TextEncoder();
|
|
let buffer = new Uint8Array(approximateLength);
|
|
let pos = 0;
|
|
|
|
for (let i = 0; i < array.length; i++) {
|
|
const encodedString = textEncoder.encode(array[i]);
|
|
|
|
let size = pos + buffer.length;
|
|
if (size < buffer.length) {
|
|
size = 2 << Math.log(size) / Math.log(2);
|
|
let newBuffer = new Uint8Array(size);
|
|
newBuffer.set(buffer);
|
|
buffer = newBuffer;
|
|
}
|
|
|
|
buffer.set(encodedString, pos);
|
|
index[i] = pos;
|
|
pos += encodedString.length;
|
|
}
|
|
index[array.length] = pos;
|
|
|
|
return {index, buffer};
|
|
}
|
|
|
|
function convertSymsMapToExpectedSymFormat(syms, approximateSymLength) {
|
|
const addresses = Array.from(syms.keys());
|
|
addresses.sort((a, b) => a - b);
|
|
|
|
const symsArray = addresses.map(addr => syms.get(addr));
|
|
const {index, buffer} =
|
|
convertStringArrayToUint8BufferWithIndex(symsArray, approximateSymLength);
|
|
|
|
return [new Uint32Array(addresses), index, buffer];
|
|
}
|
|
|
|
var ParseSymbols = {
|
|
convertSymsMapToExpectedSymFormat,
|
|
};
|