Skip to content

Commit fada901

Browse files
committed
adds comments to flamebearer
1 parent d9c6724 commit fada901

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

pkg/storage/tree/flamebearer.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,14 @@ func (t *Tree) FlamebearerStruct(maxNodes int) *Flamebearer {
5454
if level == len(res.Levels) {
5555
res.Levels = append(res.Levels, []int{})
5656
}
57-
// * barIndex, delta encoded
58-
// * numBarTicks
59-
// * link to name
60-
// barIndex := xOffset
61-
// if len(res.Levels[level]) > 0 { // delta encoding
62-
// prevX := res.Levels[level][len(res.Levels[level])-3]
63-
// prevW := res.Levels[level][len(res.Levels[level])-2]
64-
// barIndex -= prevX + prevW
65-
// }
6657
if res.MaxSelf < int(tn.Self) {
6758
res.MaxSelf = int(tn.Self)
6859
}
60+
61+
// i+0 = x offset
62+
// i+1 = total
63+
// i+2 = self
64+
// i+3 = index in names array
6965
res.Levels[level] = append([]int{xOffset, int(tn.Total), int(tn.Self), i}, res.Levels[level]...)
7066

7167
xOffset += int(tn.Self)
@@ -93,13 +89,16 @@ func (t *Tree) FlamebearerStruct(maxNodes int) *Flamebearer {
9389
}
9490
}
9591
}
92+
93+
// delta encoding
9694
for _, l := range res.Levels {
9795
prev := 0
9896
for i := 0; i < len(l); i += 4 {
9997
l[i] -= prev
10098
prev += l[i] + l[i+1]
10199
}
102100
}
101+
103102
// TODO: we used to drop the first level, because it's always an empty node
104103
// but that didn't work because flamebearer doesn't work with more
105104
// than one root element. Long term we should fix it on flamebearer side

pkg/storage/tree/flamebearer_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@ var _ = Describe("FlamebearerStruct", func() {
1717

1818
f := tree.FlamebearerStruct(1024)
1919
Expect(f.Names).To(ConsistOf("total", "a", "b", "c"))
20-
Expect(f.Levels).To(HaveLen(3))
20+
Expect(f.Levels).To(Equal([][]int{
21+
// i+0 = x offset (delta encoded)
22+
// i+1 = total
23+
// i+2 = self
24+
// i+3 = index in names array
25+
{0, 3, 0, 0},
26+
{0, 3, 0, 1},
27+
{0, 1, 1, 3, 0, 2, 2, 2},
28+
}))
2129
Expect(f.NumTicks).To(Equal(3))
2230
Expect(f.MaxSelf).To(Equal(2))
2331
})

0 commit comments

Comments
 (0)