Skip to content

Commit

Permalink
fix(bg-flamegraph): ignore comment lines
Browse files Browse the repository at this point in the history
This fix ignores any lines starting with a hash character in folded
stack file formats. This allows the raw output generated by Austin
3 to be imported directly without any of the extra metadata lines
littering the flame graph visualisation.
  • Loading branch information
P403n1x87 committed Oct 22, 2021
1 parent e37f6fa commit ff0b44d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions sample/profiles/stackcollapse/simple-with-invalids.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ a;b;d 4
a;b;c 3
a;b 5
invalid line

# duration: 1000
6 changes: 3 additions & 3 deletions src/import/bg-flamegraph.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// https://github.com/brendangregg/FlameGraph#2-fold-stacks

import {Profile, FrameInfo, StackListProfileBuilder} from '../lib/profile'
import { Profile, FrameInfo, StackListProfileBuilder } from '../lib/profile'

interface BGSample {
stack: FrameInfo[]
Expand All @@ -9,9 +9,9 @@ interface BGSample {

function parseBGFoldedStacks(contents: string): BGSample[] {
const samples: BGSample[] = []
contents.replace(/^(.*) (\d+)$/gm, (match: string, stack: string, n: string) => {
contents.replace(/(^[^#\n].*) (\d+)$/gm, (match: string, stack: string, n: string) => {
samples.push({
stack: stack.split(';').map(name => ({key: name, name: name})),
stack: stack.split(';').map(name => ({ key: name, name: name })),
duration: parseInt(n, 10),
})
return match
Expand Down

0 comments on commit ff0b44d

Please sign in to comment.