summaryrefslogtreecommitdiff
path: root/internal/flamegraph/trie_insert.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/flamegraph/trie_insert.go')
-rw-r--r--internal/flamegraph/trie_insert.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/internal/flamegraph/trie_insert.go b/internal/flamegraph/trie_insert.go
new file mode 100644
index 0000000..7748b4a
--- /dev/null
+++ b/internal/flamegraph/trie_insert.go
@@ -0,0 +1,22 @@
+package flamegraph
+
+// insertTriePath follows or creates nodes for frames and adds value at the leaf.
+func insertTriePath(root *trieNode, frames []string, value uint64) {
+ node := root
+ for _, frame := range frames {
+ if node.childMap == nil {
+ node.childMap = make(map[string]*trieNode)
+ }
+ child, ok := node.childMap[frame]
+ if !ok {
+ child = &trieNode{
+ name: frame,
+ childMap: make(map[string]*trieNode),
+ }
+ node.children = append(node.children, child)
+ node.childMap[frame] = child
+ }
+ node = child
+ }
+ node.value += value
+}