speedscope/asm-js.ts
Jamie Wong 7f7f5eeefb
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
2018-06-25 15:53:08 -07:00

27 lines
929 B
TypeScript

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
}