github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/storage/tree/collapsed.go (about)

     1  package tree
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  )
     7  
     8  func (t *Tree) Collapsed() string {
     9  	t.RLock()
    10  	defer t.RUnlock()
    11  
    12  	var res strings.Builder
    13  
    14  	t.IterateStacks(func(_ string, self uint64, stack []string) {
    15  		for i, j := 0, len(stack)-1; i < j; i, j = i+1, j-1 {
    16  			stack[i], stack[j] = stack[j], stack[i]
    17  		}
    18  		v2 := fmt.Sprintf("%s %d\n", strings.Join(stack, ";"), self)
    19  		res.WriteString(v2)
    20  	})
    21  
    22  	return res.String()
    23  }