-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for dropping asm.js symbol maps (#76)
This imports symbol maps generated by emscripten using the `--emit-symbol-map` flag. It allows you to visualize a profile captured in a release build as long as you also have the associated symbol map. To do this, first drop the profile into speedscope and then drop the symbol map. After the second drop, the symbols will be remapped to their original names. This is a fixed up version of #75
- Loading branch information
Showing
4 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import {importAsmJsSymbolMap} from './asm-js' | ||
|
||
test('importAsmJSSymbolMap', () => { | ||
// Valid symbol map | ||
expect( | ||
importAsmJsSymbolMap( | ||
[ | ||
/* prettier: ignore */ | ||
'a:A', | ||
'b:B', | ||
'c:C', | ||
].join('\n'), | ||
), | ||
).toEqual(new Map([['a', 'A'], ['b', 'B'], ['c', 'C']])) | ||
|
||
// Valid symbol map with trailing newline | ||
expect( | ||
importAsmJsSymbolMap( | ||
[ | ||
/* prettier: ignore */ | ||
'a:A', | ||
'b:B', | ||
'c:C', | ||
'', | ||
].join('\n'), | ||
), | ||
).toEqual(new Map([['a', 'A'], ['b', 'B'], ['c', 'C']])) | ||
|
||
// Valid symbol map with non-alpha characters | ||
|
||
expect(importAsmJsSymbolMap('u6:__ZN8tinyxml210XMLCommentD0Ev\n')).toEqual( | ||
new Map([['u6', '__ZN8tinyxml210XMLCommentD0Ev']]), | ||
) | ||
|
||
// Invalid symbol map | ||
expect( | ||
importAsmJsSymbolMap( | ||
[ | ||
/* prettier: ignore */ | ||
'a:A', | ||
'b:B', | ||
'c', | ||
'', | ||
].join('\n'), | ||
), | ||
).toEqual(null) | ||
|
||
// Collapsed stack format should not be imported as an asm.js symbol map | ||
expect( | ||
importAsmJsSymbolMap( | ||
[ | ||
/* prettier: ignore */ | ||
'a;b 1', | ||
'a;c 3', | ||
'', | ||
].join('\n'), | ||
), | ||
).toEqual(null) | ||
|
||
// Unrelated files | ||
expect(importAsmJsSymbolMap('')).toEqual(null) | ||
expect(importAsmJsSymbolMap('\n')).toEqual(null) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
type AsmJsSymbolMap = Map<string, string> | ||
|
||
// This imports symbol maps generated by emscripten using the "--emit-symbol-map" flag. | ||
// It allows you to visualize a profile captured in a release build as long as you also | ||
// have the associated symbol map. To do this, first drop the profile into speedscope | ||
// and then drop the symbol map. After the second drop, the symbols will be remapped to | ||
// their original names. | ||
export function importAsmJsSymbolMap(contents: string): AsmJsSymbolMap | null { | ||
const lines = contents.split('\n') | ||
if (!lines.length) return null | ||
|
||
// Remove a trailing blank line if there is one | ||
if (lines[lines.length - 1] === '') lines.pop() | ||
if (!lines.length) return null | ||
|
||
const map: AsmJsSymbolMap = new Map() | ||
const regex = /^([\$\w]+):([\$\w]+)$/ | ||
|
||
for (const line of lines) { | ||
const match = regex.exec(line) | ||
if (!match) return null | ||
map.set(match[1], match[2]) | ||
} | ||
|
||
return map | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters