Source file src/cmd/vendor/github.com/google/pprof/internal/report/synth.go

     1  package report
     2  
     3  import (
     4  	"github.com/google/pprof/profile"
     5  )
     6  
     7  // synthCode assigns addresses to locations without an address.
     8  type synthCode struct {
     9  	next uint64
    10  	addr map[*profile.Location]uint64 // Synthesized address assigned to a location
    11  }
    12  
    13  func newSynthCode(mappings []*profile.Mapping) *synthCode {
    14  	// Find a larger address than any mapping.
    15  	s := &synthCode{next: 1}
    16  	for _, m := range mappings {
    17  		if s.next < m.Limit {
    18  			s.next = m.Limit
    19  		}
    20  	}
    21  	return s
    22  }
    23  
    24  // address returns the synthetic address for loc, creating one if needed.
    25  func (s *synthCode) address(loc *profile.Location) uint64 {
    26  	if loc.Address != 0 {
    27  		panic("can only synthesize addresses for locations without an address")
    28  	}
    29  	if addr, ok := s.addr[loc]; ok {
    30  		return addr
    31  	}
    32  	if s.addr == nil {
    33  		s.addr = map[*profile.Location]uint64{}
    34  	}
    35  	addr := s.next
    36  	s.next++
    37  	s.addr[loc] = addr
    38  	return addr
    39  }
    40  

View as plain text