Bug 1494488 - Stop demangling in the geckoProfiler WebExtension API because perf.html knows how to demangle now. r=dthayer
authorMarkus Stange <mstange@themasta.com>
Mon, 01 Oct 2018 22:39:28 +0000
changeset 494811 d0bd55d771e4097e7958434199f6b6fed2448106
parent 494810 3a9818cd5ffa027282bcc610d2845c6ef6524792
child 494812 b05bfd129c6b097b772d1c2db27434631d475f6d
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdthayer
bugs1494488
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1494488 - Stop demangling in the geckoProfiler WebExtension API because perf.html knows how to demangle now. r=dthayer Differential Revision: https://phabricator.services.mozilla.com/D7335
browser/components/extensions/ParseCppFiltSymbols-worker.js
browser/components/extensions/ParseNMSymbols-worker.js
browser/components/extensions/ParseSymbols.jsm
browser/components/extensions/moz.build
browser/components/extensions/parent/ext-geckoProfiler.js
deleted file mode 100644
--- a/browser/components/extensions/ParseCppFiltSymbols-worker.js
+++ /dev/null
@@ -1,64 +0,0 @@
-/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
-/* vim: set sts=2 sw=2 et tw=80: */
-/* eslint-env worker */
-
-"use strict";
-
-importScripts("resource:///modules/ParseSymbols.jsm");
-
-class WorkerCppFiltParser {
-  constructor(length) {
-    this._decoder = new TextDecoder();
-    this._index = 0;
-    this._approximateLength = 0;
-    this._results = new Array(length);
-  }
-
-  consume(arrayBuffer) {
-    const data = this._decoder.decode(arrayBuffer, {stream: true});
-    const lineRegex = /.*\n?/g;
-    const buffer = this._currentLine + data;
-
-    let match;
-    while ((match = lineRegex.exec(buffer))) {
-      let [line] = match;
-      if (line[line.length - 1] === "\n") {
-        this._processLine(line);
-      } else {
-        this._currentLine = line;
-        break;
-      }
-    }
-  }
-
-  finish() {
-    this._processLine(this._currentLine);
-    return {symsArray: this._results, approximateLength: this._approximateLength};
-  }
-
-  _processLine(line) {
-    const trimmed = line.trimRight();
-    this._approximateLength += trimmed.length;
-    this._results[this._index++] = trimmed;
-  }
-}
-
-let cppFiltParser;
-onmessage = async e => {
-  try {
-    if (!cppFiltParser) {
-      cppFiltParser = new WorkerCppFiltParser();
-    }
-    if (e.data.finish) {
-      const {symsArray, approximateLength} = cppFiltParser.finish();
-      const result = ParseSymbols.convertSymsArrayToExpectedSymFormat(symsArray, approximateLength);
-
-      postMessage({result}, result.map(r => r.buffer));
-      close();
-    } else {
-      cppFiltParser.consume(e.data.buffer);
-    }
-  } catch (error) {
-    postMessage({error: error.toString()});
-  }
-};
--- a/browser/components/extensions/ParseNMSymbols-worker.js
+++ b/browser/components/extensions/ParseNMSymbols-worker.js
@@ -62,22 +62,18 @@ class WorkerNMParser {
 let nmParser;
 onmessage = async e => {
   try {
     if (!nmParser) {
       nmParser = new WorkerNMParser();
     }
     if (e.data.finish) {
       const {syms, approximateLength} = nmParser.finish();
-      let result;
-      if (e.data.isDarwin) {
-        result = ParseSymbols.convertSymsMapToDemanglerFormat(syms);
-      } else {
-        result = ParseSymbols.convertSymsMapToExpectedSymFormat(syms, approximateLength);
-      }
+      const result =
+        ParseSymbols.convertSymsMapToExpectedSymFormat(syms, approximateLength);
 
       postMessage({result}, result.map(r => r.buffer));
       close();
     } else {
       nmParser.consume(e.data.buffer);
     }
   } catch (error) {
     postMessage({error: error.toString()});
--- a/browser/components/extensions/ParseSymbols.jsm
+++ b/browser/components/extensions/ParseSymbols.jsm
@@ -39,30 +39,11 @@ function convertSymsMapToExpectedSymForm
 
   const symsArray = addresses.map(addr => syms.get(addr));
   const {index, buffer} =
     convertStringArrayToUint8BufferWithIndex(symsArray, approximateSymLength);
 
   return [new Uint32Array(addresses), index, buffer];
 }
 
-function convertSymsArrayToExpectedSymFormat(symsArray, approximateSymLength) {
-  const {index, buffer} =
-    convertStringArrayToUint8BufferWithIndex(symsArray, approximateSymLength);
-  return [index, buffer];
-}
-
-function convertSymsMapToDemanglerFormat(syms) {
-  const addresses = Array.from(syms.keys());
-  addresses.sort((a, b) => a - b);
-
-  const symsArray = addresses.map(addr => syms.get(addr));
-  const textEncoder = new TextEncoder();
-  const buffer = textEncoder.encode(symsArray.join("\n"));
-
-  return [new Uint32Array(addresses), buffer];
-}
-
 var ParseSymbols = {
   convertSymsMapToExpectedSymFormat,
-  convertSymsArrayToExpectedSymFormat,
-  convertSymsMapToDemanglerFormat,
 };
--- a/browser/components/extensions/moz.build
+++ b/browser/components/extensions/moz.build
@@ -12,17 +12,16 @@ JAR_MANIFESTS += ['jar.mn']
 EXTRA_COMPONENTS += [
     'extensions-browser.manifest',
 ]
 
 EXTRA_JS_MODULES += [
     'ExtensionControlledPopup.jsm',
     'ExtensionPopups.jsm',
     'ParseBreakpadSymbols-worker.js',
-    'ParseCppFiltSymbols-worker.js',
     'ParseNMSymbols-worker.js',
     'ParseSymbols.jsm',
 ]
 
 DIRS += ['schemas']
 
 BROWSER_CHROME_MANIFESTS += [
     'test/browser/browser-remote.ini',
--- a/browser/components/extensions/parent/ext-geckoProfiler.js
+++ b/browser/components/extensions/parent/ext-geckoProfiler.js
@@ -48,43 +48,16 @@ class NMParser {
           reject(e.data.error);
         } else {
           resolve(e.data.result);
         }
       };
     });
     this._worker.postMessage({
       finish: true,
-      isDarwin: Services.appinfo.OS === "Darwin",
-    });
-    return promise;
-  }
-}
-
-class CppFiltParser {
-  constructor() {
-    this._worker = new ChromeWorker("resource://app/modules/ParseCppFiltSymbols-worker.js");
-  }
-
-  consume(buffer) {
-    this._worker.postMessage({buffer}, [buffer]);
-  }
-
-  finish() {
-    const promise = new Promise((resolve, reject) => {
-      this._worker.onmessage = (e) => {
-        if (e.data.error) {
-          reject(e.data.error);
-        } else {
-          resolve(e.data.result);
-        }
-      };
-    });
-    this._worker.postMessage({
-      finish: true,
     });
     return promise;
   }
 }
 
 const joinBuffers = function(buffers) {
   const byteLengthSum =
     buffers.reduce((accum, buffer) => accum + buffer.byteLength, 0);
@@ -133,36 +106,24 @@ const runCommandAndGetOutputAsString = a
 };
 
 const getSymbolsFromNM = async function(path, arch) {
   const parser = new NMParser();
 
   const args = [path];
   if (Services.appinfo.OS === "Darwin") {
     args.unshift("-arch", arch);
-  } else {
-    // Mac's `nm` doesn't support the demangle option, so we have to
-    // post-process the symbols with c++filt.
-    args.unshift("--demangle");
   }
 
   await spawnProcess("nm", args, data => parser.consume(data));
-  await spawnProcess("nm", ["-D", ...args], data => parser.consume(data));
-  let result = await parser.finish();
   if (Services.appinfo.OS !== "Darwin") {
-    return result;
+    // Darwin nm does not support the -D option.
+    await spawnProcess("nm", ["-D", ...args], data => parser.consume(data));
   }
-
-  const [addresses, symbolsJoinedBuffer] = result;
-  const decoder = new TextDecoder();
-  const symbolsJoined = decoder.decode(symbolsJoinedBuffer);
-  const demangler = new CppFiltParser(addresses.length);
-  await spawnProcess("c++filt", [], data => demangler.consume(data), symbolsJoined);
-  const [newIndex, newBuffer] = await demangler.finish();
-  return [addresses, newIndex, newBuffer];
+  return parser.finish();
 };
 
 const getEnvVarCaseInsensitive = function(env, name) {
   for (const [varname, value] of Object.entries(env)) {
     if (varname.toLowerCase() == name.toLowerCase()) {
       return value;
     }
   }