(rpt *Report, obj plugin.ObjTool, sourcePath string)
| 258 | } |
| 259 | |
| 260 | func 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 | } |
no test coverage detected
searching dependent graphs…