MCPcopy Create free account
hub / github.com/dispatchrun/wzprof / locationForCall

Function locationForCall

wzprof.go:239–299  ·  view source on GitHub ↗
(p *Profiling, fn experimental.InternalFunction, pc experimental.ProgramCounter, funcs map[string]*profile.Function)

Source from the content-addressed store, hash-verified

237}
238
239func locationForCall(p *Profiling, fn experimental.InternalFunction, pc experimental.ProgramCounter, funcs map[string]*profile.Function) *profile.Location {
240 // Cache miss. Get or create function and all the line
241 // locations associated with inlining.
242 var locations []location
243 var symbolFound bool
244 def := fn.Definition()
245
246 out := &profile.Location{}
247
248 if pc > 0 {
249 out.Address, locations = p.symbols.Locations(fn, pc)
250 symbolFound = len(locations) > 0
251 }
252 if len(locations) == 0 {
253 // If we don't have a source location, attach to a
254 // generic location within the function.
255 locations = []location{{}}
256 }
257 // Provide defaults in case we couldn't resolve DWARF information for
258 // the main function call's PC.
259 if locations[0].StableName == "" {
260 locations[0].StableName = def.Name()
261 }
262 if locations[0].HumanName == "" {
263 locations[0].HumanName = def.Name()
264 }
265
266 lines := make([]profile.Line, len(locations))
267
268 for i, loc := range locations {
269 pprofFn := funcs[loc.StableName]
270
271 if pprofFn == nil {
272 pprofFn = &profile.Function{
273 ID: uint64(len(funcs)) + 1, // 0 is reserved by pprof
274 Name: loc.HumanName,
275 SystemName: loc.StableName,
276 Filename: loc.File,
277 }
278 funcs[loc.StableName] = pprofFn
279 } else if symbolFound {
280 // Sometimes the function had to be created while the PC
281 // wasn't found by the symbol mapper. Attempt to correct
282 // it if we had a successful match this time.
283 pprofFn.Name = locations[i].HumanName
284 pprofFn.SystemName = locations[i].StableName
285 pprofFn.Filename = locations[i].File
286 }
287
288 // Pprof expects lines to start with the root of the inlined
289 // calls. DWARF encodes that information the other way around,
290 // so we fill lines backwards.
291 lines[len(locations)-(i+1)] = profile.Line{
292 Function: pprofFn,
293 Line: loc.Line,
294 }
295 }
296

Callers 1

buildProfileFunction · 0.85

Calls 3

LocationsMethod · 0.65
NameMethod · 0.65
DefinitionMethod · 0.45

Tested by

no test coverage detected