mirror of
https://github.com/jlfwong/speedscope.git
synced 2024-12-04 16:43:54 +03:00
404aacfa46
* Switch to `bracketSpacing: false`. * Add prettier-ignore in one case.
31 lines
876 B
TypeScript
31 lines
876 B
TypeScript
// https://github.com/brendangregg/FlameGraph#2-fold-stacks
|
|
|
|
import {Profile, FrameInfo} from '../profile'
|
|
|
|
interface BGSample {
|
|
stack: FrameInfo[]
|
|
duration: number
|
|
}
|
|
|
|
function parseBGFoldedStacks(contents: string): BGSample[] {
|
|
const samples: BGSample[] = []
|
|
contents.replace(/^(.*) (\d+)$/gm, (match: string, stack: string, n: string) => {
|
|
samples.push({
|
|
stack: stack.split(';').map(name => ({key: name, name: name})),
|
|
duration: parseInt(n, 10),
|
|
})
|
|
return match
|
|
})
|
|
return samples
|
|
}
|
|
|
|
export function importFromBGFlameGraph(contents: string): Profile {
|
|
const parsed = parseBGFoldedStacks(contents)
|
|
const duration = parsed.reduce((prev: number, cur: BGSample) => prev + cur.duration, 0)
|
|
const profile = new Profile(duration)
|
|
for (let sample of parsed) {
|
|
profile.appendSample(sample.stack, sample.duration)
|
|
}
|
|
return profile
|
|
}
|