File: synth.go

package info (click to toggle)
golang-github-google-pprof 0.0~git20211008.947d60d-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-backports, forky, sid, trixie
  • size: 5,036 kB
  • sloc: sh: 70; ansic: 11; makefile: 4
file content (39 lines) | stat: -rw-r--r-- 883 bytes parent folder | download | duplicates (21)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package report

import (
	"github.com/google/pprof/profile"
)

// synthCode assigns addresses to locations without an address.
type synthCode struct {
	next uint64
	addr map[*profile.Location]uint64 // Synthesized address assigned to a location
}

func newSynthCode(mappings []*profile.Mapping) *synthCode {
	// Find a larger address than any mapping.
	s := &synthCode{next: 1}
	for _, m := range mappings {
		if s.next < m.Limit {
			s.next = m.Limit
		}
	}
	return s
}

// address returns the synthetic address for loc, creating one if needed.
func (s *synthCode) address(loc *profile.Location) uint64 {
	if loc.Address != 0 {
		panic("can only synthesize addresses for locations without an address")
	}
	if addr, ok := s.addr[loc]; ok {
		return addr
	}
	if s.addr == nil {
		s.addr = map[*profile.Location]uint64{}
	}
	addr := s.next
	s.next++
	s.addr[loc] = addr
	return addr
}