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

Function annotateAssembly

internal/report/report.go:638–685  ·  view source on GitHub ↗

annotateAssembly annotates a set of assembly instructions with a set of samples. It returns a set of nodes to display. base is an offset to adjust the sample addresses.

(insts []plugin.Inst, samples graph.Nodes, file plugin.ObjFile)

Source from the content-addressed store, hash-verified

636// set of samples. It returns a set of nodes to display. base is an
637// offset to adjust the sample addresses.
638func annotateAssembly(insts []plugin.Inst, samples graph.Nodes, file plugin.ObjFile) []assemblyInstruction {
639 // Add end marker to simplify printing loop.
640 insts = append(insts, plugin.Inst{
641 Addr: ^uint64(0),
642 })
643
644 // Ensure samples are sorted by address.
645 samples.Sort(graph.AddressOrder)
646
647 s := 0
648 asm := make([]assemblyInstruction, 0, len(insts))
649 for ix, in := range insts[:len(insts)-1] {
650 n := assemblyInstruction{
651 address: in.Addr,
652 instruction: in.Text,
653 function: in.Function,
654 line: in.Line,
655 }
656 if in.File != "" {
657 n.file = filepath.Base(in.File)
658 }
659
660 // Sum all the samples until the next instruction (to account
661 // for samples attributed to the middle of an instruction).
662 for next := insts[ix+1].Addr; s < len(samples); s++ {
663 if addr, err := file.ObjAddr(samples[s].Info.Address); err != nil || addr >= next {
664 break
665 }
666 sample := samples[s]
667 n.flatDiv += sample.FlatDiv
668 n.flat += sample.Flat
669 n.cumDiv += sample.CumDiv
670 n.cum += sample.Cum
671 if f := sample.Info.File; f != "" && n.file == "" {
672 n.file = filepath.Base(f)
673 }
674 if ln := sample.Info.Lineno; ln != 0 && n.line == 0 {
675 n.line = ln
676 }
677 if f := sample.Info.Name; f != "" && n.function == "" {
678 n.function = f
679 }
680 }
681 asm = append(asm, n)
682 }
683
684 return asm
685}
686
687// valueOrDot formats a value according to a report, intercepting zero
688// values.

Callers 1

PrintAssemblyFunction · 0.85

Calls 2

ObjAddrMethod · 0.65
SortMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…