Debian Codegraph @

profile/merge.go

raw symbols SCIP
1 // Copyright 2014 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/
16
17 import (
18 "encoding/binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/"
19 "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/"
20 "slicesscip-go gomod github.com/golang/go/src go1.24.0 slices/"
21 "sortscip-go gomod github.com/golang/go/src go1.24.0 sort/"
22 "strconvscip-go gomod github.com/golang/go/src go1.24.0 strconv/"
23 "stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/"
24 )
25
26 // Compact performs garbage collection on a profile to remove any
27 // unreferenced fields. This is useful to reduce the size of a profile
28 // after samples or locations have been removed.
29 func (p *Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#) Compactscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Compact().() *Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile# {
30 p, _ = Mergescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Merge().([]*Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#{p})
31 return p
32 }
33
34 // Merge merges all the profiles in profs into a single Profile.
35 // Returns a new profile independent of the input profiles. The merged
36 // profile is compacted to eliminate unused samples, locations,
37 // functions and mappings. Profiles must have identical profile sample
38 // and period types or the merge will fail. profile.Period of the
39 // resulting profile will be the maximum of all profiles, and
40 // profile.TimeNanos will be the earliest nonzero one. Merges are
41 // associative with the caveat of the first profile having some
42 // specialization in how headers are combined. There may be other
43 // subtleties now or in the future regarding associativity.
44 func Mergescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Merge().(srcs []*Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#) (*Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#, error) {
45 if len(srcs) == 0 {
46 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("no profiles to merge")
47 }
48 p, err := combineHeadersscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/combineHeaders().(srcs)
49 if err != nil {
50 return nil, err
51 }
52
53 pm := &profileMergerscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#{
54 pscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#p.: p,
55 samplesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#samples.: make(map[sampleKeyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/sampleKey#]*Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#, len(srcs[0].Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample.)),
56 locationsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#locations.: make(map[locationKeyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationKey#]*Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#, len(srcs[0].Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location.)),
57 functionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#functions.: make(map[functionKeyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/functionKey#]*Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#, len(srcs[0].Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Function.)),
58 mappingsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#mappings.: make(map[mappingKeyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/mappingKey#]*Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#, len(srcs[0].Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping.)),
59 }
60
61 for _, src := range srcs {
62 // Clear the profile-specific hash tables
63 pm.locationsByIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#locationsByID. = makeLocationIDMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/makeLocationIDMap().(len(src.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location.))
64 pm.functionsByIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#functionsByID. = make(map[uint64]*Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#, len(src.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Function.))
65 pm.mappingsByIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#mappingsByID. = make(map[uint64]mapInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/mapInfo#, len(src.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping.))
66
67 if len(pm.mappingsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#mappings.) == 0 && len(src.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping.) > 0 {
68 // The Mapping list has the property that the first mapping
69 // represents the main binary. Take the first Mapping we see,
70 // otherwise the operations below will add mappings in an
71 // arbitrary order.
72 pm.mapMappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#mapMapping().(src.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping.[0])
73 }
74
75 for _, s := range src.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample. {
76 if !isZeroSamplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/isZeroSample().(s) {
77 pm.mapSamplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#mapSample().(s)
78 }
79 }
80 }
81
82 if slicesscip-go gomod github.com/golang/go/src go1.24.0 slices/.ContainsFuncscip-go gomod github.com/golang/go/src go1.24.0 slices/ContainsFunc().(p.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample., isZeroSamplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/isZeroSample().) {
83 // If there are any zero samples, re-merge the profile to GC
84 // them.
85 return Mergescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Merge().([]*Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#{p})
86 }
87
88 return p, nil
89 }
90
91 // Normalize normalizes the source profile by multiplying each value in profile by the
92 // ratio of the sum of the base profile's values of that sample type to the sum of the
93 // source profile's value of that sample type.
94 func (p *Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#) Normalizescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Normalize().(pb *Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#) error {
95
96 if err := p.compatiblescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#compatible().(pb); err != nil {
97 return err
98 }
99
100 baseVals := make([]int64, len(p.SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType.))
101 for _, s := range pb.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample. {
102 for i, v := range s.Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value. {
103 baseVals[i] += v
104 }
105 }
106
107 srcVals := make([]int64, len(p.SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType.))
108 for _, s := range p.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample. {
109 for i, v := range s.Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value. {
110 srcVals[i] += v
111 }
112 }
113
114 normScale := make([]float64, len(baseVals))
115 for i := range baseVals {
116 if srcVals[i] == 0 {
117 normScale[i] = 0.0
118 } else {
119 normScale[i] = float64(baseVals[i]) / float64(srcVals[i])
120 }
121 }
122 p.ScaleNscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#ScaleN().(normScale)
123 return nil
124 }
125
126 func isZeroSamplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/isZeroSample().(s *Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#) bool {
127 for _, v := range s.Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value. {
128 if v != 0 {
129 return false
130 }
131 }
132 return true
133 }
134
135 type profileMergerscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger# struct {
136 pscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#p. *Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#
137
138 // Memoization tables within a profile.
139 locationsByIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#locationsByID. locationIDMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationIDMap#
140 functionsByIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#functionsByID. map[uint64]*Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#
141 mappingsByIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#mappingsByID. map[uint64]mapInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/mapInfo#
142
143 // Memoization tables for profile entities.
144 samplesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#samples. map[sampleKeyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/sampleKey#]*Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#
145 locationsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#locations. map[locationKeyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationKey#]*Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#
146 functionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#functions. map[functionKeyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/functionKey#]*Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#
147 mappingsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#mappings. map[mappingKeyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/mappingKey#]*Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#
148 }
149
150 type mapInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/mapInfo# struct {
151 mscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/mapInfo#m. *Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#
152 offsetscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/mapInfo#offset. int64
153 }
154
155 func (pm *profileMergerscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#) mapSamplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#mapSample().(src *Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#) *Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample# {
156 // Check memoization table
157 k := pm.sampleKeyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#sampleKey().(src)
158 if ss, ok := pm.samplesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#samples.[k]; ok {
159 for i, v := range src.Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value. {
160 ss.Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value.[i] += v
161 }
162 return ss
163 }
164
165 // Make new sample.
166 s := &Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#{
167 Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location.: make([]*Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#, len(src.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location.)),
168 Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value.: make([]int64, len(src.Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value.)),
169 Labelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Label.: make(map[string][]string, len(src.Labelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Label.)),
170 NumLabelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#NumLabel.: make(map[string][]int64, len(src.NumLabelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#NumLabel.)),
171 NumUnitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#NumUnit.: make(map[string][]string, len(src.NumLabelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#NumLabel.)),
172 }
173 for i, l := range src.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location. {
174 s.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location.[i] = pm.mapLocationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#mapLocation().(l)
175 }
176 for k, v := range src.Labelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Label. {
177 vv := make([]string, len(v))
178 copy(vv, v)
179 s.Labelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Label.[k] = vv
180 }
181 for k, v := range src.NumLabelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#NumLabel. {
182 u := src.NumUnitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#NumUnit.[k]
183 vv := make([]int64, len(v))
184 uu := make([]string, len(u))
185 copy(vv, v)
186 copy(uu, u)
187 s.NumLabelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#NumLabel.[k] = vv
188 s.NumUnitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#NumUnit.[k] = uu
189 }
190 copy(s.Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value., src.Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value.)
191 pm.samplesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#samples.[k] = s
192 pm.pscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#p..Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample. = append(pm.pscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#p..Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample., s)
193 return s
194 }
195
196 func (pm *profileMergerscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#) sampleKeyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#sampleKey().(sample *Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#) sampleKeyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/sampleKey# {
197 // Accumulate contents into a string.
198 var buf stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Builderscip-go gomod github.com/golang/go/src go1.24.0 strings/Builder#
199 buf.Growscip-go gomod github.com/golang/go/src go1.24.0 strings/Builder#Grow().(64) // Heuristic to avoid extra allocs
200
201 // encode a number
202 putNumber := func(v uint64) {
203 var num [binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/.MaxVarintLen64scip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/MaxVarintLen64.]byte
204 n := binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/.PutUvarintscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/PutUvarint().(num[:], v)
205 buf.Writescip-go gomod github.com/golang/go/src go1.24.0 strings/Builder#Write().(num[:n])
206 }
207
208 // encode a string prefixed with its length.
209 putDelimitedString := func(s string) {
210 putNumber(uint64(len(s)))
211 buf.WriteStringscip-go gomod github.com/golang/go/src go1.24.0 strings/Builder#WriteString().(s)
212 }
213
214 for _, l := range sample.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location. {
215 // Get the location in the merged profile, which may have a different ID.
216 if loc := pm.mapLocationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#mapLocation().(l); loc != nil {
217 putNumber(loc.IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#ID.)
218 }
219 }
220 putNumber(0) // Delimiter
221
222 for _, l := range sortedKeys1scip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/sortedKeys1().(sample.Labelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Label.) {
223 putDelimitedString(l)
224 values := sample.Labelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Label.[l]
225 putNumber(uint64(len(values)))
226 for _, v := range values {
227 putDelimitedString(v)
228 }
229 }
230
231 for _, l := range sortedKeys2scip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/sortedKeys2().(sample.NumLabelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#NumLabel.) {
232 putDelimitedString(l)
233 values := sample.NumLabelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#NumLabel.[l]
234 putNumber(uint64(len(values)))
235 for _, v := range values {
236 putNumber(uint64(v))
237 }
238 units := sample.NumUnitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#NumUnit.[l]
239 putNumber(uint64(len(units)))
240 for _, v := range units {
241 putDelimitedString(v)
242 }
243 }
244
245 return sampleKeyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/sampleKey#(buf.Stringscip-go gomod github.com/golang/go/src go1.24.0 strings/Builder#String().())
246 }
247
248 type sampleKeyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/sampleKey# string
249
250 // sortedKeys1 returns the sorted keys found in a string->[]string map.
251 //
252 // Note: this is currently non-generic since github pprof runs golint,
253 // which does not support generics. When that issue is fixed, it can
254 // be merged with sortedKeys2 and made into a generic function.
255 func sortedKeys1scip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/sortedKeys1().(m map[string][]string) []string {
256 if len(m) == 0 {
257 return nil
258 }
259 keys := make([]string, 0, len(m))
260 for k := range m {
261 keys = append(keys, k)
262 }
263 sortscip-go gomod github.com/golang/go/src go1.24.0 sort/.Stringsscip-go gomod github.com/golang/go/src go1.24.0 sort/Strings().(keys)
264 return keys
265 }
266
267 // sortedKeys2 returns the sorted keys found in a string->[]int64 map.
268 //
269 // Note: this is currently non-generic since github pprof runs golint,
270 // which does not support generics. When that issue is fixed, it can
271 // be merged with sortedKeys1 and made into a generic function.
272 func sortedKeys2scip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/sortedKeys2().(m map[string][]int64) []string {
273 if len(m) == 0 {
274 return nil
275 }
276 keys := make([]string, 0, len(m))
277 for k := range m {
278 keys = append(keys, k)
279 }
280 sortscip-go gomod github.com/golang/go/src go1.24.0 sort/.Stringsscip-go gomod github.com/golang/go/src go1.24.0 sort/Strings().(keys)
281 return keys
282 }
283
284 func (pm *profileMergerscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#) mapLocationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#mapLocation().(src *Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#) *Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location# {
285 if src == nil {
286 return nil
287 }
288
289 if l := pm.locationsByIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#locationsByID..getscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationIDMap#get().(src.IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#ID.); l != nil {
290 return l
291 }
292
293 mi := pm.mapMappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#mapMapping().(src.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Mapping.)
294 l := &Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#{
295 IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#ID.: uint64(len(pm.pscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#p..Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location.) + 1),
296 Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Mapping.: mi.mscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/mapInfo#m.,
297 Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Address.: uint64(int64(src.Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Address.) + mi.offsetscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/mapInfo#offset.),
298 Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Line.: make([]Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#, len(src.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Line.)),
299 IsFoldedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#IsFolded.: src.IsFoldedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#IsFolded.,
300 }
301 for i, ln := range src.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Line. {
302 l.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Line.[i] = pm.mapLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#mapLine().(ln)
303 }
304 // Check memoization table. Must be done on the remapped location to
305 // account for the remapped mapping ID.
306 k := l.keyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#key().()
307 if ll, ok := pm.locationsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#locations.[k]; ok {
308 pm.locationsByIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#locationsByID..setscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationIDMap#set().(src.IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#ID., ll)
309 return ll
310 }
311 pm.locationsByIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#locationsByID..setscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationIDMap#set().(src.IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#ID., l)
312 pm.locationsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#locations.[k] = l
313 pm.pscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#p..Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location. = append(pm.pscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#p..Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location., l)
314 return l
315 }
316
317 // key generates locationKey to be used as a key for maps.
318 func (l *Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#) keyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#key().() locationKeyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationKey# {
319 key := locationKeyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationKey#{
320 addrscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationKey#addr.: l.Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Address.,
321 isFoldedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationKey#isFolded.: l.IsFoldedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#IsFolded.,
322 }
323 if l.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Mapping. != nil {
324 // Normalizes address to handle address space randomization.
325 key.addrscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationKey#addr. -= l.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Mapping..Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start.
326 key.mappingIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationKey#mappingID. = l.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Mapping..IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#ID.
327 }
328 lines := make([]string, len(l.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Line.)*3)
329 for i, line := range l.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Line. {
330 if line.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Function. != nil {
331 lines[i*2] = strconvscip-go gomod github.com/golang/go/src go1.24.0 strconv/.FormatUintscip-go gomod github.com/golang/go/src go1.24.0 strconv/FormatUint().(line.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Function..IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#ID., 16)
332 }
333 lines[i*2+1] = strconvscip-go gomod github.com/golang/go/src go1.24.0 strconv/.FormatIntscip-go gomod github.com/golang/go/src go1.24.0 strconv/FormatInt().(line.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Line., 16)
334 lines[i*2+2] = strconvscip-go gomod github.com/golang/go/src go1.24.0 strconv/.FormatIntscip-go gomod github.com/golang/go/src go1.24.0 strconv/FormatInt().(line.Columnscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Column., 16)
335 }
336 key.linesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationKey#lines. = stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.24.0 strings/Join().(lines, "|")
337 return key
338 }
339
340 type locationKeyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationKey# struct {
341 addrscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationKey#addr., mappingIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationKey#mappingID. uint64
342 linesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationKey#lines. string
343 isFoldedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationKey#isFolded. bool
344 }
345
346 func (pm *profileMergerscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#) mapMappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#mapMapping().(src *Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#) mapInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/mapInfo# {
347 if src == nil {
348 return mapInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/mapInfo#{}
349 }
350
351 if mi, ok := pm.mappingsByIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#mappingsByID.[src.IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#ID.]; ok {
352 return mi
353 }
354
355 // Check memoization tables.
356 mk := src.keyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#key().()
357 if m, ok := pm.mappingsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#mappings.[mk]; ok {
358 mi := mapInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/mapInfo#{m, int64(m.Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start.) - int64(src.Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start.)}
359 pm.mappingsByIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#mappingsByID.[src.IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#ID.] = mi
360 return mi
361 }
362 m := &Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#{
363 IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#ID.: uint64(len(pm.pscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#p..Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping.) + 1),
364 Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start.: src.Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start.,
365 Limitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Limit.: src.Limitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Limit.,
366 Offsetscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Offset.: src.Offsetscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Offset.,
367 Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File.: src.Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File.,
368 KernelRelocationSymbolscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#KernelRelocationSymbol.: src.KernelRelocationSymbolscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#KernelRelocationSymbol.,
369 BuildIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#BuildID.: src.BuildIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#BuildID.,
370 HasFunctionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#HasFunctions.: src.HasFunctionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#HasFunctions.,
371 HasFilenamesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#HasFilenames.: src.HasFilenamesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#HasFilenames.,
372 HasLineNumbersscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#HasLineNumbers.: src.HasLineNumbersscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#HasLineNumbers.,
373 HasInlineFramesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#HasInlineFrames.: src.HasInlineFramesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#HasInlineFrames.,
374 }
375 pm.pscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#p..Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping. = append(pm.pscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#p..Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping., m)
376
377 // Update memoization tables.
378 pm.mappingsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#mappings.[mk] = m
379 mi := mapInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/mapInfo#{m, 0}
380 pm.mappingsByIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#mappingsByID.[src.IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#ID.] = mi
381 return mi
382 }
383
384 // key generates encoded strings of Mapping to be used as a key for
385 // maps.
386 func (m *Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#) keyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#key().() mappingKeyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/mappingKey# {
387 // Normalize addresses to handle address space randomization.
388 // Round up to next 4K boundary to avoid minor discrepancies.
389 const mapsizeRounding = 0x1000
390
391 size := m.Limitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Limit. - m.Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start.
392 size = size + mapsizeRounding - 1
393 size = size - (size % mapsizeRounding)
394 key := mappingKeyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/mappingKey#{
395 sizescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/mappingKey#size.: size,
396 offsetscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/mappingKey#offset.: m.Offsetscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Offset.,
397 }
398
399 switch {
400 case m.BuildIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#BuildID. != "":
401 key.buildIDOrFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/mappingKey#buildIDOrFile. = m.BuildIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#BuildID.
402 case m.Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File. != "":
403 key.buildIDOrFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/mappingKey#buildIDOrFile. = m.Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File.
404 default:
405 // A mapping containing neither build ID nor file name is a fake mapping. A
406 // key with empty buildIDOrFile is used for fake mappings so that they are
407 // treated as the same mapping during merging.
408 }
409 return key
410 }
411
412 type mappingKeyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/mappingKey# struct {
413 sizescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/mappingKey#size., offsetscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/mappingKey#offset. uint64
414 buildIDOrFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/mappingKey#buildIDOrFile. string
415 }
416
417 func (pm *profileMergerscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#) mapLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#mapLine().(src Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#) Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line# {
418 ln := Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#{
419 Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Function.: pm.mapFunctionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#mapFunction().(src.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Function.),
420 Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Line.: src.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Line.,
421 Columnscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Column.: src.Columnscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Column.,
422 }
423 return ln
424 }
425
426 func (pm *profileMergerscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#) mapFunctionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#mapFunction().(src *Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#) *Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function# {
427 if src == nil {
428 return nil
429 }
430 if f, ok := pm.functionsByIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#functionsByID.[src.IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#ID.]; ok {
431 return f
432 }
433 k := src.keyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#key().()
434 if f, ok := pm.functionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#functions.[k]; ok {
435 pm.functionsByIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#functionsByID.[src.IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#ID.] = f
436 return f
437 }
438 f := &Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#{
439 IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#ID.: uint64(len(pm.pscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#p..Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Function.) + 1),
440 Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Name.: src.Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Name.,
441 SystemNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#SystemName.: src.SystemNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#SystemName.,
442 Filenamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Filename.: src.Filenamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Filename.,
443 StartLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#StartLine.: src.StartLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#StartLine.,
444 }
445 pm.functionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#functions.[k] = f
446 pm.functionsByIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#functionsByID.[src.IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#ID.] = f
447 pm.pscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#p..Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Function. = append(pm.pscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileMerger#p..Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Function., f)
448 return f
449 }
450
451 // key generates a struct to be used as a key for maps.
452 func (f *Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#) keyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#key().() functionKeyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/functionKey# {
453 return functionKeyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/functionKey#{
454 f.StartLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#StartLine.,
455 f.Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Name.,
456 f.SystemNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#SystemName.,
457 f.Filenamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Filename.,
458 }
459 }
460
461 type functionKeyscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/functionKey# struct {
462 startLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/functionKey#startLine. int64
463 namescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/functionKey#name., systemNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/functionKey#systemName., fileNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/functionKey#fileName. string
464 }
465
466 // combineHeaders checks that all profiles can be merged and returns
467 // their combined profile.
468 func combineHeadersscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/combineHeaders().(srcs []*Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#) (*Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#, error) {
469 for _, s := range srcs[1:] {
470 if err := srcs[0].compatiblescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#compatible().(s); err != nil {
471 return nil, err
472 }
473 }
474
475 var timeNanos, durationNanos, period int64
476 var comments []string
477 seenComments := map[string]bool{}
478 var docURL string
479 var defaultSampleType string
480 for _, s := range srcs {
481 if timeNanos == 0 || s.TimeNanosscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#TimeNanos. < timeNanos {
482 timeNanos = s.TimeNanosscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#TimeNanos.
483 }
484 durationNanos += s.DurationNanosscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#DurationNanos.
485 if period == 0 || period < s.Periodscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Period. {
486 period = s.Periodscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Period.
487 }
488 for _, c := range s.Commentsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Comments. {
489 if seen := seenComments[c]; !seen {
490 comments = append(comments, c)
491 seenComments[c] = true
492 }
493 }
494 if defaultSampleType == "" {
495 defaultSampleType = s.DefaultSampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#DefaultSampleType.
496 }
497 if docURL == "" {
498 docURL = s.DocURLscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#DocURL.
499 }
500 }
501
502 p := &Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#{
503 SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType.: make([]*ValueTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#, len(srcs[0].SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType.)),
504
505 DropFramesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#DropFrames.: srcs[0].DropFramesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#DropFrames.,
506 KeepFramesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#KeepFrames.: srcs[0].KeepFramesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#KeepFrames.,
507
508 TimeNanosscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#TimeNanos.: timeNanos,
509 DurationNanosscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#DurationNanos.: durationNanos,
510 PeriodTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#PeriodType.: srcs[0].PeriodTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#PeriodType.,
511 Periodscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Period.: period,
512
513 Commentsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Comments.: comments,
514 DefaultSampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#DefaultSampleType.: defaultSampleType,
515 DocURLscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#DocURL.: docURL,
516 }
517 copy(p.SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType., srcs[0].SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType.)
518 return p, nil
519 }
520
521 // compatible determines if two profiles can be compared/merged.
522 // returns nil if the profiles are compatible; otherwise an error with
523 // details on the incompatibility.
524 func (p *Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#) compatiblescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#compatible().(pb *Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#) error {
525 if !equalValueTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/equalValueType().(p.PeriodTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#PeriodType., pb.PeriodTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#PeriodType.) {
526 return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("incompatible period types %v and %v", p.PeriodTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#PeriodType., pb.PeriodTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#PeriodType.)
527 }
528
529 if len(p.SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType.) != len(pb.SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType.) {
530 return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("incompatible sample types %v and %v", p.SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType., pb.SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType.)
531 }
532
533 for i := range p.SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType. {
534 if !equalValueTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/equalValueType().(p.SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType.[i], pb.SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType.[i]) {
535 return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("incompatible sample types %v and %v", p.SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType., pb.SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType.)
536 }
537 }
538 return nil
539 }
540
541 // equalValueType returns true if the two value types are semantically
542 // equal. It ignores the internal fields used during encode/decode.
543 func equalValueTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/equalValueType().(st1, st2 *ValueTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#) bool {
544 return st1.Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type. == st2.Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type. && st1.Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Unit. == st2.Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Unit.
545 }
546
547 // locationIDMap is like a map[uint64]*Location, but provides efficiency for
548 // ids that are densely numbered, which is often the case.
549 type locationIDMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationIDMap# struct {
550 densescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationIDMap#dense. []*Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location# // indexed by id for id < len(dense)
551 sparsescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationIDMap#sparse. map[uint64]*Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location# // indexed by id for id >= len(dense)
552 }
553
554 func makeLocationIDMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/makeLocationIDMap().(n int) locationIDMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationIDMap# {
555 return locationIDMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationIDMap#{
556 densescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationIDMap#dense.: make([]*Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#, n),
557 sparsescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationIDMap#sparse.: map[uint64]*Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#{},
558 }
559 }
560
561 func (lm locationIDMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationIDMap#) getscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationIDMap#get().(id uint64) *Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location# {
562 if id < uint64(len(lm.densescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationIDMap#dense.)) {
563 return lm.densescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationIDMap#dense.[int(id)]
564 }
565 return lm.sparsescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationIDMap#sparse.[id]
566 }
567
568 func (lm locationIDMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationIDMap#) setscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationIDMap#set().(id uint64, loc *Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#) {
569 if id < uint64(len(lm.densescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationIDMap#dense.)) {
570 lm.densescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationIDMap#dense.[id] = loc
571 return
572 }
573 lm.sparsescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/locationIDMap#sparse.[id] = loc
574 }
575
576 // CompatibilizeSampleTypes makes profiles compatible to be compared/merged. It
577 // keeps sample types that appear in all profiles only and drops/reorders the
578 // sample types as necessary.
579 //
580 // In the case of sample types order is not the same for given profiles the
581 // order is derived from the first profile.
582 //
583 // Profiles are modified in-place.
584 //
585 // It returns an error if the sample type's intersection is empty.
586 func CompatibilizeSampleTypesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/CompatibilizeSampleTypes().(ps []*Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#) error {
587 sTypes := commonSampleTypesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/commonSampleTypes().(ps)
588 if len(sTypes) == 0 {
589 return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("profiles have empty common sample type list")
590 }
591 for _, p := range ps {
592 if err := compatibilizeSampleTypesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/compatibilizeSampleTypes().(p, sTypes); err != nil {
593 return err
594 }
595 }
596 return nil
597 }
598
599 // commonSampleTypes returns sample types that appear in all profiles in the
600 // order how they ordered in the first profile.
601 func commonSampleTypesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/commonSampleTypes().(ps []*Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#) []string {
602 if len(ps) == 0 {
603 return nil
604 }
605 sTypes := map[string]int{}
606 for _, p := range ps {
607 for _, st := range p.SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType. {
608 sTypes[st.Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type.]++
609 }
610 }
611 var res []string
612 for _, st := range ps[0].SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType. {
613 if sTypes[st.Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type.] == len(ps) {
614 res = append(res, st.Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type.)
615 }
616 }
617 return res
618 }
619
620 // compatibilizeSampleTypes drops sample types that are not present in sTypes
621 // list and reorder them if needed.
622 //
623 // It sets DefaultSampleType to sType[0] if it is not in sType list.
624 //
625 // It assumes that all sample types from the sTypes list are present in the
626 // given profile otherwise it returns an error.
627 func compatibilizeSampleTypesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/compatibilizeSampleTypes().(p *Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#, sTypes []string) error {
628 if len(sTypes) == 0 {
629 return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("sample type list is empty")
630 }
631 defaultSampleType := sTypes[0]
632 reMap, needToModify := make([]int, len(sTypes)), false
633 for i, st := range sTypes {
634 if st == p.DefaultSampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#DefaultSampleType. {
635 defaultSampleType = p.DefaultSampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#DefaultSampleType.
636 }
637 idx := searchValueTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/searchValueType().(p.SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType., st)
638 if idx < 0 {
639 return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("%q sample type is not found in profile", st)
640 }
641 reMap[i] = idx
642 if idx != i {
643 needToModify = true
644 }
645 }
646 if !needToModify && len(sTypes) == len(p.SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType.) {
647 return nil
648 }
649 p.DefaultSampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#DefaultSampleType. = defaultSampleType
650 oldSampleTypes := p.SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType.
651 p.SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType. = make([]*ValueTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#, len(sTypes))
652 for i, idx := range reMap {
653 p.SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType.[i] = oldSampleTypes[idx]
654 }
655 values := make([]int64, len(sTypes))
656 for _, s := range p.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample. {
657 for i, idx := range reMap {
658 values[i] = s.Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value.[idx]
659 }
660 s.Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value. = s.Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value.[:len(values)]
661 copy(s.Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value., values)
662 }
663 return nil
664 }
665
666 func searchValueTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/searchValueType().(vts []*ValueTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#, s string) int {
667 for i, vt := range vts {
668 if vt.Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type. == s {
669 return i
670 }
671 }
672 return -1
673 }