Skip to content

Commit

Permalink
adds comments to flamebearer
Browse files Browse the repository at this point in the history
  • Loading branch information
petethepig committed Jul 12, 2021
1 parent d9c6724 commit fada901
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
17 changes: 8 additions & 9 deletions pkg/storage/tree/flamebearer.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,14 @@ func (t *Tree) FlamebearerStruct(maxNodes int) *Flamebearer {
if level == len(res.Levels) {
res.Levels = append(res.Levels, []int{})
}
// * barIndex, delta encoded
// * numBarTicks
// * link to name
// barIndex := xOffset
// if len(res.Levels[level]) > 0 { // delta encoding
// prevX := res.Levels[level][len(res.Levels[level])-3]
// prevW := res.Levels[level][len(res.Levels[level])-2]
// barIndex -= prevX + prevW
// }
if res.MaxSelf < int(tn.Self) {
res.MaxSelf = int(tn.Self)
}

// i+0 = x offset
// i+1 = total
// i+2 = self
// i+3 = index in names array
res.Levels[level] = append([]int{xOffset, int(tn.Total), int(tn.Self), i}, res.Levels[level]...)

xOffset += int(tn.Self)
Expand Down Expand Up @@ -93,13 +89,16 @@ func (t *Tree) FlamebearerStruct(maxNodes int) *Flamebearer {
}
}
}

// delta encoding
for _, l := range res.Levels {
prev := 0
for i := 0; i < len(l); i += 4 {
l[i] -= prev
prev += l[i] + l[i+1]
}
}

// TODO: we used to drop the first level, because it's always an empty node
// but that didn't work because flamebearer doesn't work with more
// than one root element. Long term we should fix it on flamebearer side
Expand Down
10 changes: 9 additions & 1 deletion pkg/storage/tree/flamebearer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ var _ = Describe("FlamebearerStruct", func() {

f := tree.FlamebearerStruct(1024)
Expect(f.Names).To(ConsistOf("total", "a", "b", "c"))
Expect(f.Levels).To(HaveLen(3))
Expect(f.Levels).To(Equal([][]int{
// i+0 = x offset (delta encoded)
// i+1 = total
// i+2 = self
// i+3 = index in names array
{0, 3, 0, 0},
{0, 3, 0, 1},
{0, 1, 1, 3, 0, 2, 2, 2},
}))
Expect(f.NumTicks).To(Equal(3))
Expect(f.MaxSelf).To(Equal(2))
})
Expand Down

0 comments on commit fada901

Please sign in to comment.