Demangle C++ symbols (#2)

This adds support for demangling C++ symbols automatically (they'll have a name prefix of `__Z`).
This commit is contained in:
Jamie Wong 2018-04-05 00:27:03 -07:00 committed by GitHub
parent 1987e83bde
commit 5104e5cdcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 4 deletions

View File

@ -206,7 +206,7 @@ export class Application extends ReloadableComponent<{}, ApplicationState> {
}
}
loadFromString(fileName: string, contents: string) {
async loadFromString(fileName: string, contents: string) {
if (!this.canvasContext) return
console.time('import')
@ -218,6 +218,8 @@ export class Application extends ReloadableComponent<{}, ApplicationState> {
return
}
await profile.demangle()
profile.setName(fileName)
document.title = `${fileName} - speedscope`

32
demangle-cpp.ts Normal file

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"serve": "parcel dev.html --open --no-autoinstall",
"serve": "parcel index.html --open --no-autoinstall",
"release": "./release.sh"
},
"browserslist": [

View File

@ -1,4 +1,8 @@
import { lastOf, getOrInsert } from './utils'
const demangleCppModule = import('./demangle-cpp')
// Force eager loading of the module
demangleCppModule.then(() => console.log('CPP demangler loaded'))
export interface FrameInfo {
key: string | number
@ -337,6 +341,7 @@ export class Profile {
this.groupedOrderStack.pop()
}
}
leaveFrame(frameInfo: FrameInfo, value: number) {
const frame = getOrInsert(this.frames, frameInfo.key, () => new Frame(frameInfo))
this.addWeightsToFrames(value)
@ -354,4 +359,20 @@ export class Profile {
}
this.lastValue = value
}
}
// Demangle symbols for readability
async demangle() {
let demangleCpp: ((name: string) => string) | null = null
for (let frame of this.frames.values()) {
// This function converts a mangled C++ name such as "__ZNK7Support6ColorFeqERKS0_"
// into a human-readable symbol (in this case "Support::ColorF::==(Support::ColorF&)")
if (frame.name.startsWith('__Z')) {
if (!demangleCpp) {
demangleCpp = (await demangleCppModule).demangleCpp
}
frame.name = demangleCpp(frame.name)
}
}
}
}

View File

@ -1,6 +1,6 @@
{
"compilerOptions": {
"module": "commonjs",
"module": "es2015",
"strict": true,
"jsx": "react",
"noUnusedLocals": true,