diff --git a/pkg/storage/tree/flamebearer.go b/pkg/storage/tree/flamebearer.go index 049a876f19..180264103c 100644 --- a/pkg/storage/tree/flamebearer.go +++ b/pkg/storage/tree/flamebearer.go @@ -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) @@ -93,6 +89,8 @@ func (t *Tree) FlamebearerStruct(maxNodes int) *Flamebearer { } } } + + // delta encoding for _, l := range res.Levels { prev := 0 for i := 0; i < len(l); i += 4 { @@ -100,6 +98,7 @@ func (t *Tree) FlamebearerStruct(maxNodes int) *Flamebearer { 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 diff --git a/pkg/storage/tree/flamebearer_test.go b/pkg/storage/tree/flamebearer_test.go index c3bfde3463..b16b11605a 100644 --- a/pkg/storage/tree/flamebearer_test.go +++ b/pkg/storage/tree/flamebearer_test.go @@ -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)) })