Skip to content

Commit

Permalink
Merge pull request #369 from parca-dev/storage-cumulative-flamegraph
Browse files Browse the repository at this point in the history
pkg/storage: Improve flame graph stack iterating
  • Loading branch information
brancz committed Oct 25, 2021
2 parents a6867a7 + aa289da commit 37f8225
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions pkg/storage/flamegraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,15 @@ func GenerateFlamegraph(
outerMost, innerMost := locationToTreeNodes(l, 0, 0)

flamegraphStack.Peek().node.Children = append(flamegraphStack.Peek().node.Children, outerMost)
flamegraphStack.Push(&TreeStackEntry{
node: innerMost,
})
if int32(len(flamegraphStack)) > flamegraph.Height {
flamegraph.Height = int32(len(flamegraphStack))

steppedInto := it.StepInto()
if steppedInto {
flamegraphStack.Push(&TreeStackEntry{
node: innerMost,
})
if int32(len(flamegraphStack)) > flamegraph.Height {
flamegraph.Height = int32(len(flamegraphStack))
}
}

for _, n := range child.FlatValues() {
Expand All @@ -191,7 +195,6 @@ func GenerateFlamegraph(
}
}

it.StepInto()
continue
}

Expand Down Expand Up @@ -301,6 +304,8 @@ func mergeChildren(node *pb.FlamegraphNode, compare, equals func(a, b *pb.Flameg
return compare(node.Children[i], node.Children[j])
})

var cumulative int64

i, j := 0, 1
for i < len(node.Children)-1 {
current, next := node.Children[i], node.Children[j]
Expand All @@ -311,6 +316,7 @@ func mergeChildren(node *pb.FlamegraphNode, compare, equals func(a, b *pb.Flameg
current.Meta.Mapping = &pb.Mapping{}
}

cumulative += next.Cumulative
current.Cumulative += next.Cumulative
current.Diff += next.Diff
current.Children = append(current.Children, next.Children...)
Expand All @@ -320,6 +326,11 @@ func mergeChildren(node *pb.FlamegraphNode, compare, equals func(a, b *pb.Flameg
}
i, j = i+1, j+1
}

// TODO: This is just a safeguard and should be properly fixed before this function.
if node.Cumulative < cumulative {
node.Cumulative = cumulative
}
}

func compareByName(a, b *pb.FlamegraphNode) bool {
Expand Down

0 comments on commit 37f8225

Please sign in to comment.