github.com/GuanceCloud/cliutils@v1.1.21/pprofparser/domain/tracing/tracing.go (about)

     1  package tracing
     2  
     3  var (
     4  	AllTraceSpanSet = NewSpanIDSet()
     5  )
     6  
     7  type SpanIDSet struct {
     8  	Set map[string]struct{}
     9  }
    10  
    11  func NewSpanIDSet() *SpanIDSet {
    12  	return &SpanIDSet{
    13  		Set: make(map[string]struct{}),
    14  	}
    15  }
    16  
    17  func (ss *SpanIDSet) Put(id string) {
    18  	ss.Set[id] = struct{}{}
    19  }
    20  
    21  func (ss *SpanIDSet) Contains(id string) bool {
    22  	// avoid nil pointer
    23  	if ss.Set == nil {
    24  		return false
    25  	}
    26  	_, ok := ss.Set[id]
    27  	return ok
    28  }
    29  
    30  // getSpanParentID 查询 spanID 的顶级父级ID, 并进行路径压缩
    31  func getSpanParentID(spanIDMaps map[string]string, topID string, spanID string) string {
    32  	for {
    33  		pid, ok := spanIDMaps[spanID]
    34  		if !ok {
    35  			return ""
    36  		}
    37  		if pid != "0" && pid != topID {
    38  			spanIDMaps[spanID] = getSpanParentID(spanIDMaps, topID, pid)
    39  		}
    40  		return spanIDMaps[spanID]
    41  	}
    42  }