Skip to content

Commit 1e68fd6

Browse files
committed
Demangle symbols when reading them out of the symbol table.
This also adds our first wasm module and updates the configuration so that that's possible. I've used wasm-pack to publish a gecko-profiler-demangle module to npm instead of copying the generated code into this repository. I'm not sure if that was a good or a bad idea; I mostly did it so that our Flow and ESLint rules wouldn't be applied to the wasm-bindgen generated code. I've also needed to autogenerate a flow libdef for this module. wasm-bindgen doesn't create those automatically yet: wasm-bindgen/wasm-bindgen#180 I could have created one manually and included it in the published package, but I don't know if wasm-pack would have included my additional files in the published package (via `wasm-pack publish`).
1 parent a79df7f commit 1e68fd6

File tree

9 files changed

+247
-22
lines changed

9 files changed

+247
-22
lines changed

.babelrc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
// obeys the spec more, but we get a bundle that's 8kB larger. That was the
1010
// default in babel v6.
1111
["@babel/plugin-proposal-class-properties", { loose: true }],
12-
["@babel/plugin-proposal-object-rest-spread", { useBuiltIns: true }]
12+
["@babel/plugin-proposal-object-rest-spread", { useBuiltIns: true }],
13+
"syntax-dynamic-import"
1314
],
1415
env: {
1516
test: {
@@ -20,8 +21,9 @@
2021
],
2122
plugins: [
2223
["@babel/plugin-proposal-class-properties", { loose: true }],
23-
["@babel/plugin-proposal-object-rest-spread", { useBuiltIns: true }]
24-
]
24+
["@babel/plugin-proposal-object-rest-spread", { useBuiltIns: true }],
25+
"dynamic-import-node"
26+
],
2527
}
2628
}
2729
}

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,20 @@
3939
"dependencies": {
4040
"array-move": "^1.0.0",
4141
"array-range": "^1.0.1",
42+
"babel-plugin-dynamic-import-node": "^2.0.0",
43+
"babel-plugin-syntax-dynamic-import": "^6.18.0",
44+
"babel-runtime": "^6.26.0",
4245
"bisection": "0.0.3",
4346
"clamp": "^1.0.1",
4447
"classnames": "^2.2.5",
4548
"common-tags": "^1.7.2",
4649
"copy-to-clipboard": "^3.0.8",
4750
"escape-string-regexp": "^1.0.5",
51+
"gecko-profiler-demangle": "^0.1.0",
4852
"jszip": "^3.1.5",
4953
"memoize-immutable": "^3.0.0",
5054
"mixedtuplemap": "^1.0.0",
51-
"offline-plugin": "^5.0.5",
55+
"@mstange/offline-plugin": "^5.0.6",
5256
"photon-colors": "2.0.1",
5357
"prop-types": "^15.6.0",
5458
"query-string": "^5.1.0",
@@ -134,7 +138,8 @@
134138
],
135139
"moduleNameMapper": {
136140
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/src/test/fixtures/mocks/file-mock.js",
137-
"\\.(css|less)$": "<rootDir>/src/test/fixtures/mocks/style-mock.js"
141+
"\\.(css|less)$": "<rootDir>/src/test/fixtures/mocks/style-mock.js",
142+
"^gecko-profiler-demangle$": "<rootDir>/src/test/gecko-profiler-demangle-mock.js"
138143
},
139144
"restoreMocks": true,
140145
"resetMocks": true,

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if (process.env.NODE_ENV === 'development') {
2727
}
2828

2929
if (process.env.NODE_ENV === 'production') {
30-
const runtime = require('offline-plugin/runtime');
30+
const runtime = require('@mstange/offline-plugin/runtime');
3131
runtime.install({
3232
onUpdateReady: () => {
3333
runtime.applyUpdate();

src/profile-logic/symbol-store.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import SymbolStoreDB from './symbol-store-db';
77
import { SymbolsNotFoundError } from './errors';
88
import bisection from 'bisection';
99

10+
const demangleModulePromise = import('gecko-profiler-demangle');
11+
1012
import type { RequestedLib } from '../types/actions';
1113
import type { SymbolTableAsTuple } from './symbol-store-db';
1214

@@ -113,7 +115,8 @@ export class SymbolStore {
113115
// This format is documented at the SymbolTableAsTuple flow type definition.
114116
_readSymbolsFromSymbolTable(
115117
addresses: Set<number>,
116-
symbolTable: SymbolTableAsTuple
118+
symbolTable: SymbolTableAsTuple,
119+
demangleCallback: string => string
117120
): Map<number, AddressResult> {
118121
const [symbolTableAddrs, symbolTableIndex, symbolTableBuffer] = symbolTable;
119122
const addressArray = Uint32Array.from(addresses);
@@ -150,7 +153,9 @@ export class SymbolStore {
150153
const startOffset = symbolTableIndex[symbolIndex];
151154
const endOffset = symbolTableIndex[symbolIndex + 1];
152155
const subarray = symbolTableBuffer.subarray(startOffset, endOffset);
153-
currentSymbol = decoder.decode(subarray);
156+
// C++ or rust symbols in the symbol table may have mangled names.
157+
// Demangle them here.
158+
currentSymbol = demangleCallback(decoder.decode(subarray));
154159
currentSymbolIndex = symbolIndex;
155160
}
156161
results.set(address, {
@@ -268,10 +273,16 @@ export class SymbolStore {
268273
// symbolication for the libraries for which we found symbol tables in the
269274
// database. This is delayed until after the request has been kicked off
270275
// because it can take some time.
276+
// We also need a demangling function for this, which is in an async module.
277+
const demangleCallback = (await demangleModulePromise).demangle_any;
271278
for (const { request, symbolTable } of requestsForCachedLibs) {
272279
successCb(
273280
request,
274-
this._readSymbolsFromSymbolTable(request.addresses, symbolTable)
281+
this._readSymbolsFromSymbolTable(
282+
request.addresses,
283+
symbolTable,
284+
demangleCallback
285+
)
275286
);
276287
}
277288

@@ -312,7 +323,11 @@ export class SymbolStore {
312323
// Did not throw, option 3 was successful!
313324
successCb(
314325
request,
315-
this._readSymbolsFromSymbolTable(addresses, symbolTable)
326+
this._readSymbolsFromSymbolTable(
327+
addresses,
328+
symbolTable,
329+
demangleCallback
330+
)
316331
);
317332

318333
// Store the symbol table in the database.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This module replaces the wasm-pack generated module 'gecko-profiler-demangle'
2+
// in our tests.
3+
// The reason for this replacement is the fact that wasm-pack (or rather,
4+
// wasm-bindgen), when targeting the browser + webpack, generates an ES6 module
5+
// that node cannot deal with. Most importantly, it uses the syntax
6+
// "import * as wasm from './gecko_profiler_demangle_bg';" in order to load
7+
// the wasm module, which is currently only supported by webpack.
8+
9+
// @flow
10+
11+
// There's only one exported function.
12+
// Do the simplest thing possible: no demangling.
13+
export function demangle_any(s: string): string {
14+
return s;
15+
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
// flow-typed signature: f84c93c5335ad9c36684cc95ca54b099
2+
// flow-typed version: <<STUB>>/@mstange/offline-plugin_v^5.0.6/flow_v0.70.0
3+
4+
/**
5+
* This is an autogenerated libdef stub for:
6+
*
7+
* '@mstange/offline-plugin'
8+
*
9+
* Fill this stub out by replacing all the `any` types.
10+
*
11+
* Once filled out, we encourage you to share your work with the
12+
* community by sending a pull request to:
13+
* https://github.com/flowtype/flow-typed
14+
*/
15+
16+
declare module '@mstange/offline-plugin' {
17+
declare module.exports: any;
18+
}
19+
20+
/**
21+
* We include stubs for each file inside this npm package in case you need to
22+
* require those files directly. Feel free to delete any files that aren't
23+
* needed.
24+
*/
25+
declare module '@mstange/offline-plugin/lib/app-cache' {
26+
declare module.exports: any;
27+
}
28+
29+
declare module '@mstange/offline-plugin/lib/default-options' {
30+
declare module.exports: any;
31+
}
32+
33+
declare module '@mstange/offline-plugin/lib/index' {
34+
declare module.exports: any;
35+
}
36+
37+
declare module '@mstange/offline-plugin/lib/loaders/fonts-css' {
38+
declare module.exports: any;
39+
}
40+
41+
declare module '@mstange/offline-plugin/lib/loaders/index' {
42+
declare module.exports: any;
43+
}
44+
45+
declare module '@mstange/offline-plugin/lib/misc/async-waituntil' {
46+
declare module.exports: any;
47+
}
48+
49+
declare module '@mstange/offline-plugin/lib/misc/get-uglify-plugin' {
50+
declare module.exports: any;
51+
}
52+
53+
declare module '@mstange/offline-plugin/lib/misc/runtime-loader' {
54+
declare module.exports: any;
55+
}
56+
57+
declare module '@mstange/offline-plugin/lib/misc/sw-loader' {
58+
declare module.exports: any;
59+
}
60+
61+
declare module '@mstange/offline-plugin/lib/misc/sw-polyfill' {
62+
declare module.exports: any;
63+
}
64+
65+
declare module '@mstange/offline-plugin/lib/misc/sw-template' {
66+
declare module.exports: any;
67+
}
68+
69+
declare module '@mstange/offline-plugin/lib/misc/utils' {
70+
declare module.exports: any;
71+
}
72+
73+
declare module '@mstange/offline-plugin/lib/service-worker' {
74+
declare module.exports: any;
75+
}
76+
77+
declare module '@mstange/offline-plugin/runtime' {
78+
declare module.exports: any;
79+
}
80+
81+
declare module '@mstange/offline-plugin/tpls/empty-entry' {
82+
declare module.exports: any;
83+
}
84+
85+
declare module '@mstange/offline-plugin/tpls/runtime-template' {
86+
declare module.exports: any;
87+
}
88+
89+
// Filename aliases
90+
declare module '@mstange/offline-plugin/lib/app-cache.js' {
91+
declare module.exports: $Exports<'@mstange/offline-plugin/lib/app-cache'>;
92+
}
93+
declare module '@mstange/offline-plugin/lib/default-options.js' {
94+
declare module.exports: $Exports<'@mstange/offline-plugin/lib/default-options'>;
95+
}
96+
declare module '@mstange/offline-plugin/lib/index.js' {
97+
declare module.exports: $Exports<'@mstange/offline-plugin/lib/index'>;
98+
}
99+
declare module '@mstange/offline-plugin/lib/loaders/fonts-css.js' {
100+
declare module.exports: $Exports<'@mstange/offline-plugin/lib/loaders/fonts-css'>;
101+
}
102+
declare module '@mstange/offline-plugin/lib/loaders/index.js' {
103+
declare module.exports: $Exports<'@mstange/offline-plugin/lib/loaders/index'>;
104+
}
105+
declare module '@mstange/offline-plugin/lib/misc/async-waituntil.js' {
106+
declare module.exports: $Exports<'@mstange/offline-plugin/lib/misc/async-waituntil'>;
107+
}
108+
declare module '@mstange/offline-plugin/lib/misc/get-uglify-plugin.js' {
109+
declare module.exports: $Exports<'@mstange/offline-plugin/lib/misc/get-uglify-plugin'>;
110+
}
111+
declare module '@mstange/offline-plugin/lib/misc/runtime-loader.js' {
112+
declare module.exports: $Exports<'@mstange/offline-plugin/lib/misc/runtime-loader'>;
113+
}
114+
declare module '@mstange/offline-plugin/lib/misc/sw-loader.js' {
115+
declare module.exports: $Exports<'@mstange/offline-plugin/lib/misc/sw-loader'>;
116+
}
117+
declare module '@mstange/offline-plugin/lib/misc/sw-polyfill.js' {
118+
declare module.exports: $Exports<'@mstange/offline-plugin/lib/misc/sw-polyfill'>;
119+
}
120+
declare module '@mstange/offline-plugin/lib/misc/sw-template.js' {
121+
declare module.exports: $Exports<'@mstange/offline-plugin/lib/misc/sw-template'>;
122+
}
123+
declare module '@mstange/offline-plugin/lib/misc/utils.js' {
124+
declare module.exports: $Exports<'@mstange/offline-plugin/lib/misc/utils'>;
125+
}
126+
declare module '@mstange/offline-plugin/lib/service-worker.js' {
127+
declare module.exports: $Exports<'@mstange/offline-plugin/lib/service-worker'>;
128+
}
129+
declare module '@mstange/offline-plugin/runtime.js' {
130+
declare module.exports: $Exports<'@mstange/offline-plugin/runtime'>;
131+
}
132+
declare module '@mstange/offline-plugin/tpls/empty-entry.js' {
133+
declare module.exports: $Exports<'@mstange/offline-plugin/tpls/empty-entry'>;
134+
}
135+
declare module '@mstange/offline-plugin/tpls/runtime-template.js' {
136+
declare module.exports: $Exports<'@mstange/offline-plugin/tpls/runtime-template'>;
137+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// flow-typed signature: e6f43a673a1ad489aea31817e5e11e45
2+
// flow-typed version: <<STUB>>/gecko-profiler-demangle_v^0.1.0/flow_v0.70.0
3+
4+
/**
5+
* This is an autogenerated libdef stub for:
6+
*
7+
* 'gecko-profiler-demangle'
8+
*
9+
* Fill this stub out by replacing all the `any` types.
10+
*
11+
* Once filled out, we encourage you to share your work with the
12+
* community by sending a pull request to:
13+
* https://github.com/flowtype/flow-typed
14+
*/
15+
16+
declare module 'gecko-profiler-demangle' {
17+
declare module.exports: any;
18+
}
19+
20+
/**
21+
* We include stubs for each file inside this npm package in case you need to
22+
* require those files directly. Feel free to delete any files that aren't
23+
* needed.
24+
*/
25+
declare module 'gecko-profiler-demangle/gecko_profiler_demangle' {
26+
declare module.exports: any;
27+
}
28+
29+
// Filename aliases
30+
declare module 'gecko-profiler-demangle/gecko_profiler_demangle.js' {
31+
declare module.exports: $Exports<'gecko-profiler-demangle/gecko_profiler_demangle'>;
32+
}

webpack.config.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const path = require('path');
33
const webpack = require('webpack');
44
const HtmlWebpackPlugin = require('html-webpack-plugin');
5-
const OfflinePlugin = require('offline-plugin');
5+
const OfflinePlugin = require('@mstange/offline-plugin');
66
const CopyWebpackPlugin = require('copy-webpack-plugin');
77
const includes = [path.join(__dirname, 'src'), path.join(__dirname, 'res')];
88

@@ -18,7 +18,7 @@ const config = {
1818
'redux-devtools': path.join(__dirname, '..', '..', 'src'),
1919
react: path.join(__dirname, 'node_modules', 'react'),
2020
},
21-
extensions: ['.js'],
21+
extensions: ['.js', '.wasm'],
2222
},
2323
devtool: 'source-map',
2424
module: {
@@ -79,6 +79,10 @@ const config = {
7979
chunkFilename: '[id].[hash].bundle.js',
8080
publicPath: '/',
8181
},
82+
optimization: {
83+
// Workaround for https://github.com/webpack/webpack/issues/7760
84+
usedExports: false,
85+
},
8286
};
8387

8488
if (process.env.NODE_ENV === 'development') {

0 commit comments

Comments
 (0)