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

Method generateFile

internal/report/source.go:651–714  ·  view source on GitHub ↗
(f *sourceFile, rpt *Report)

Source from the content-addressed store, hash-verified

649}
650
651func (sp *sourcePrinter) generateFile(f *sourceFile, rpt *Report) WebListFile {
652 var result WebListFile
653 for _, fn := range sp.functions(f) {
654 if fn.cum == 0 {
655 continue
656 }
657
658 listfn := WebListFunc{
659 Name: fn.name,
660 File: f.fname,
661 Flat: rpt.formatValue(fn.flat),
662 Cumulative: rpt.formatValue(fn.cum),
663 Percent: measurement.Percentage(fn.cum, rpt.total),
664 }
665 var asm []assemblyInstruction
666 for l := fn.begin; l < fn.end; l++ {
667 lineContents, ok := sp.reader.line(f.fname, l)
668 if !ok {
669 if len(f.lines[l]) == 0 {
670 // Outside of range of valid lines and nothing to print.
671 continue
672 }
673 if l == 0 {
674 // Line number 0 shows up if line number is not known.
675 lineContents = "<instructions with unknown line numbers>"
676 } else {
677 // Past end of file, but have data to print.
678 lineContents = "???"
679 }
680 }
681
682 // Make list of assembly instructions.
683 asm = asm[:0]
684 var flatSum, cumSum int64
685 var lastAddr uint64
686 for _, inst := range f.lines[l] {
687 addr := inst.addr
688 x := sp.insts[addr]
689 flatSum += x.flat
690 cumSum += x.cum
691 startsBlock := (addr != lastAddr+uint64(sp.insts[lastAddr].length))
692 lastAddr = addr
693
694 // divisors already applied, so leave flatDiv,cumDiv as 0
695 asm = append(asm, assemblyInstruction{
696 address: x.objAddr,
697 instruction: x.disasm,
698 function: fn.name,
699 file: x.file,
700 line: x.line,
701 flat: x.flat,
702 cum: x.cum,
703 startsBlock: startsBlock,
704 inlineCalls: inst.stack,
705 })
706 }
707
708 listfn.Lines = append(listfn.Lines, makeWebListLine(l, flatSum, cumSum, lineContents, asm, sp.reader, rpt))

Callers 1

generateMethod · 0.95

Calls 4

functionsMethod · 0.95
PercentageFunction · 0.92
makeWebListLineFunction · 0.85
lineMethod · 0.80

Tested by

no test coverage detected