MCPcopy Create free account
hub / github.com/google/pprof / newSourcePrinter

Function newSourcePrinter

internal/report/source.go:260–361  ·  view source on GitHub ↗
(rpt *Report, obj plugin.ObjTool, sourcePath string)

Source from the content-addressed store, hash-verified

258}
259
260func newSourcePrinter(rpt *Report, obj plugin.ObjTool, sourcePath string) *sourcePrinter {
261 sp := &sourcePrinter{
262 reader: newSourceReader(sourcePath, rpt.options.TrimPath),
263 synth: newSynthCode(rpt.prof.Mapping),
264 objectTool: obj,
265 objects: map[string]plugin.ObjFile{},
266 sym: rpt.options.Symbol,
267 files: map[string]*sourceFile{},
268 insts: map[uint64]instructionInfo{},
269 prettyNames: map[string]string{},
270 interest: map[string]bool{},
271 }
272
273 // If the regexp source can be parsed as an address, also match
274 // functions that land on that address.
275 var address *uint64
276 if sp.sym != nil {
277 if hex, err := strconv.ParseUint(sp.sym.String(), 0, 64); err == nil {
278 address = &hex
279 }
280 }
281
282 addrs := map[uint64]addrInfo{}
283 flat := map[uint64]int64{}
284 cum := map[uint64]int64{}
285
286 // Record an interest in the function corresponding to lines[index].
287 markInterest := func(addr uint64, loc *profile.Location, index int) {
288 fn := loc.Line[index]
289 if fn.Function == nil {
290 return
291 }
292 sp.interest[fn.Function.Name] = true
293 sp.interest[fn.Function.SystemName] = true
294 if _, ok := addrs[addr]; !ok {
295 addrs[addr] = addrInfo{loc, sp.objectFile(loc.Mapping)}
296 }
297 }
298
299 // See if sp.sym matches line.
300 matches := func(line profile.Line) bool {
301 if line.Function == nil {
302 return false
303 }
304 return sp.sym.MatchString(line.Function.Name) ||
305 sp.sym.MatchString(line.Function.SystemName) ||
306 sp.sym.MatchString(line.Function.Filename)
307 }
308
309 // Extract sample counts and compute set of interesting functions.
310 for _, sample := range rpt.prof.Sample {
311 value := rpt.options.SampleValue(sample.Value)
312 if rpt.options.SampleMeanDivisor != nil {
313 div := rpt.options.SampleMeanDivisor(sample.Value)
314 if div != 0 {
315 value /= div
316 }
317 }

Callers 1

MakeWebListFunction · 0.85

Calls 7

objectFileMethod · 0.95
expandAddressesMethod · 0.95
initSamplesMethod · 0.95
newSourceReaderFunction · 0.85
newSynthCodeFunction · 0.85
addressMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…