| 1 | // Copyright 2014 Google Inc. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/ |
| 16 | |
| 17 | // This file contains routines related to the generation of annotated |
| 18 | // source listings. |
| 19 | |
| 20 | import ( |
| 21 | "bufioscip-go gomod github.com/golang/go/src go1.24.0 bufio/" |
| 22 | "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 23 | "html/templatescip-go gomod github.com/golang/go/src go1.24.0 `html/template`/" |
| 24 | "ioscip-go gomod github.com/golang/go/src go1.24.0 io/" |
| 25 | "osscip-go gomod github.com/golang/go/src go1.24.0 os/" |
| 26 | "path/filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/" |
| 27 | "regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/" |
| 28 | "slicesscip-go gomod github.com/golang/go/src go1.24.0 slices/" |
| 29 | "sortscip-go gomod github.com/golang/go/src go1.24.0 sort/" |
| 30 | "strconvscip-go gomod github.com/golang/go/src go1.24.0 strconv/" |
| 31 | "stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/" |
| 32 | |
| 33 | "github.com/google/pprof/internal/graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/" |
| 34 | "github.com/google/pprof/internal/measurementscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/" |
| 35 | "github.com/google/pprof/internal/pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/" |
| 36 | "github.com/google/pprof/profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/" |
| 37 | ) |
| 38 | |
| 39 | // printSource prints an annotated source listing, include all |
| 40 | // functions with samples that match the regexp rpt.options.symbol. |
| 41 | // The sources are sorted by function name and then by filename to |
| 42 | // eliminate potential nondeterminism. |
| 43 | func printSourcescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/printSource().(w ioscip-go gomod github.com/golang/go/src go1.24.0 io/.Writerscip-go gomod github.com/golang/go/src go1.24.0 io/Writer#, rpt *Reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#) error { |
| 44 | o := rpt.optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#options. |
| 45 | g := rpt.newGraphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#newGraph().(nil) |
| 46 | |
| 47 | // Identify all the functions that match the regexp provided. |
| 48 | // Group nodes for each matching function. |
| 49 | var functions graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes# |
| 50 | functionNodes := make(map[string]graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#) |
| 51 | for _, n := range g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes. { |
| 52 | if !o.Symbolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#Symbol..MatchStringscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#MatchString().(n.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Name.) { |
| 53 | continue |
| 54 | } |
| 55 | if functionNodes[n.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Name.] == nil { |
| 56 | functions = append(functions, n) |
| 57 | } |
| 58 | functionNodes[n.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Name.] = append(functionNodes[n.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Name.], n) |
| 59 | } |
| 60 | functions.Sortscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#Sort().(graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/.NameOrderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NameOrder.) |
| 61 | |
| 62 | if len(functionNodes) == 0 { |
| 63 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("no matches found for regexp: %s", o.Symbolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#Symbol.) |
| 64 | } |
| 65 | |
| 66 | sourcePath := o.SourcePathscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#SourcePath. |
| 67 | if sourcePath == "" { |
| 68 | wd, err := osscip-go gomod github.com/golang/go/src go1.24.0 os/.Getwdscip-go gomod github.com/golang/go/src go1.24.0 os/Getwd().() |
| 69 | if err != nil { |
| 70 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("could not stat current dir: %v", err) |
| 71 | } |
| 72 | sourcePath = wd |
| 73 | } |
| 74 | reader := newSourceReaderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/newSourceReader().(sourcePath, o.TrimPathscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#TrimPath.) |
| 75 | |
| 76 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Fprintf().(w, "Total: %s\n", rpt.formatValuescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#formatValue.(rpt.totalscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#total.)) |
| 77 | for _, fn := range functions { |
| 78 | name := fn.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Name. |
| 79 | |
| 80 | // Identify all the source files associated to this function. |
| 81 | // Group nodes for each source file. |
| 82 | var sourceFiles graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes# |
| 83 | fileNodes := make(map[string]graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#) |
| 84 | for _, n := range functionNodes[name] { |
| 85 | if n.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#File. == "" { |
| 86 | continue |
| 87 | } |
| 88 | if fileNodes[n.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#File.] == nil { |
| 89 | sourceFiles = append(sourceFiles, n) |
| 90 | } |
| 91 | fileNodes[n.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#File.] = append(fileNodes[n.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#File.], n) |
| 92 | } |
| 93 | |
| 94 | if len(sourceFiles) == 0 { |
| 95 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Fprintf().(w, "No source information for %s\n", name) |
| 96 | continue |
| 97 | } |
| 98 | |
| 99 | sourceFiles.Sortscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#Sort().(graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/.FileOrderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/FileOrder.) |
| 100 | |
| 101 | // Print each file associated with this function. |
| 102 | for _, fl := range sourceFiles { |
| 103 | filename := fl.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#File. |
| 104 | fns := fileNodes[filename] |
| 105 | flatSum, cumSum := fns.Sumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#Sum().() |
| 106 | |
| 107 | fnodes, _, err := getSourceFromFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/getSourceFromFile().(filename, reader, fns, 0, 0) |
| 108 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Fprintf().(w, "ROUTINE ======================== %s in %s\n", name, filename) |
| 109 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Fprintf().(w, "%10s %10s (flat, cum) %s of Total\n", |
| 110 | rpt.formatValuescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#formatValue.(flatSum), rpt.formatValuescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#formatValue.(cumSum), |
| 111 | measurementscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/.Percentagescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/Percentage().(cumSum, rpt.totalscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#total.)) |
| 112 | |
| 113 | if err != nil { |
| 114 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Fprintf().(w, " Error: %v\n", err) |
| 115 | continue |
| 116 | } |
| 117 | |
| 118 | for _, fn := range fnodes { |
| 119 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Fprintf().(w, "%10s %10s %6d:%s\n", valueOrDotscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/valueOrDot().(fn.Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Flat., rpt), valueOrDotscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/valueOrDot().(fn.Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Cum., rpt), fn.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..Linenoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Lineno., fn.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Name.) |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | return nil |
| 124 | } |
| 125 | |
| 126 | // sourcePrinter holds state needed for generating source+asm HTML listing. |
| 127 | type sourcePrinterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter# struct { |
| 128 | readerscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#reader. *sourceReaderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceReader# |
| 129 | synthscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#synth. *synthCodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/synthCode# |
| 130 | objectToolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#objectTool. pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.ObjToolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/ObjTool# |
| 131 | objectsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#objects. map[string]pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.ObjFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/ObjFile# // Opened object files |
| 132 | symscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#sym. *regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/.Regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp# // May be nil |
| 133 | filesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#files. map[string]*sourceFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile# // Set of files to print. |
| 134 | instsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#insts. map[uint64]instructionInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo# // Instructions of interest (keyed by address). |
| 135 | |
| 136 | // Set of function names that we are interested in (because they had |
| 137 | // a sample and match sym). |
| 138 | interestscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#interest. map[string]bool |
| 139 | |
| 140 | // Mapping from system function names to printable names. |
| 141 | prettyNamesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#prettyNames. map[string]string |
| 142 | } |
| 143 | |
| 144 | // addrInfo holds information for an address we are interested in. |
| 145 | type addrInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addrInfo# struct { |
| 146 | locscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addrInfo#loc. *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location# // Always non-nil |
| 147 | objscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addrInfo#obj. pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.ObjFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/ObjFile# // May be nil |
| 148 | } |
| 149 | |
| 150 | // instructionInfo holds collected information for an instruction. |
| 151 | type instructionInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo# struct { |
| 152 | objAddrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#objAddr. uint64 // Address in object file (with base subtracted out) |
| 153 | lengthscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#length. int // Instruction length in bytes |
| 154 | disasmscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#disasm. string // Disassembly of instruction |
| 155 | filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#file. string // For top-level function in which instruction occurs |
| 156 | linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#line. int // For top-level function in which instruction occurs |
| 157 | flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#flat., cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#cum. int64 // Samples to report (divisor already applied) |
| 158 | } |
| 159 | |
| 160 | // sourceFile contains collected information for files we will print. |
| 161 | type sourceFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile# struct { |
| 162 | fnamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#fname. string |
| 163 | cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#cum. int64 |
| 164 | flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#flat. int64 |
| 165 | linesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#lines. map[int][]sourceInstscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceInst# // Instructions to show per line |
| 166 | funcNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#funcName. map[int]string // Function name per line |
| 167 | } |
| 168 | |
| 169 | // sourceInst holds information for an instruction to be displayed. |
| 170 | type sourceInstscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceInst# struct { |
| 171 | addrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceInst#addr. uint64 |
| 172 | stackscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceInst#stack. []callIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/callID# // Inlined call-stack |
| 173 | } |
| 174 | |
| 175 | // sourceFunction contains information for a contiguous range of lines per function we |
| 176 | // will print. |
| 177 | type sourceFunctionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction# struct { |
| 178 | namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#name. string |
| 179 | beginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#begin., endscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#end. int // Line numbers (end is not included in the range) |
| 180 | flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#flat., cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#cum. int64 |
| 181 | } |
| 182 | |
| 183 | // addressRange is a range of addresses plus the object file that contains it. |
| 184 | type addressRangescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addressRange# struct { |
| 185 | beginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addressRange#begin., endscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addressRange#end. uint64 |
| 186 | objscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addressRange#obj. pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.ObjFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/ObjFile# |
| 187 | mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addressRange#mapping. *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping# |
| 188 | scorescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addressRange#score. int64 // Used to order ranges for processing |
| 189 | } |
| 190 | |
| 191 | // WebListData holds the data needed to generate HTML source code listing. |
| 192 | type WebListDatascip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListData# struct { |
| 193 | Totalscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListData#Total. string |
| 194 | Filesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListData#Files. []WebListFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListFile# |
| 195 | } |
| 196 | |
| 197 | // WebListFile holds the per-file information for HTML source code listing. |
| 198 | type WebListFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListFile# struct { |
| 199 | Funcsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListFile#Funcs. []WebListFuncscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListFunc# |
| 200 | } |
| 201 | |
| 202 | // WebListFunc holds the per-function information for HTML source code listing. |
| 203 | type WebListFuncscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListFunc# struct { |
| 204 | Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListFunc#Name. string |
| 205 | Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListFunc#File. string |
| 206 | Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListFunc#Flat. string |
| 207 | Cumulativescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListFunc#Cumulative. string |
| 208 | Percentscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListFunc#Percent. string |
| 209 | Linesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListFunc#Lines. []WebListLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListLine# |
| 210 | } |
| 211 | |
| 212 | // WebListLine holds the per-source-line information for HTML source code listing. |
| 213 | type WebListLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListLine# struct { |
| 214 | SrcLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListLine#SrcLine. string |
| 215 | HTMLClassscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListLine#HTMLClass. string |
| 216 | Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListLine#Line. int |
| 217 | Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListLine#Flat. string |
| 218 | Cumulativescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListLine#Cumulative. string |
| 219 | Instructionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListLine#Instructions. []WebListInstructionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListInstruction# |
| 220 | } |
| 221 | |
| 222 | // WebListInstruction holds the per-instruction information for HTML source code listing. |
| 223 | type WebListInstructionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListInstruction# struct { |
| 224 | NewBlockscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListInstruction#NewBlock. bool // Insert marker that indicates separation from previous block |
| 225 | Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListInstruction#Flat. string |
| 226 | Cumulativescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListInstruction#Cumulative. string |
| 227 | Syntheticscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListInstruction#Synthetic. bool |
| 228 | Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListInstruction#Address. uint64 |
| 229 | Disasmscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListInstruction#Disasm. string |
| 230 | FileLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListInstruction#FileLine. string |
| 231 | InlinedCallsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListInstruction#InlinedCalls. []WebListCallscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListCall# |
| 232 | } |
| 233 | |
| 234 | // WebListCall holds the per-inlined-call information for HTML source code listing. |
| 235 | type WebListCallscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListCall# struct { |
| 236 | SrcLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListCall#SrcLine. string |
| 237 | FileBasescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListCall#FileBase. string |
| 238 | Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListCall#Line. int |
| 239 | } |
| 240 | |
| 241 | // MakeWebList returns an annotated source listing of rpt. |
| 242 | // rpt.prof should contain inlined call info. |
| 243 | func MakeWebListscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/MakeWebList().(rpt *Reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#, obj pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.ObjToolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/ObjTool#, maxFiles int) (WebListDatascip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListData#, error) { |
| 244 | sourcePath := rpt.optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#options..SourcePathscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#SourcePath. |
| 245 | if sourcePath == "" { |
| 246 | wd, err := osscip-go gomod github.com/golang/go/src go1.24.0 os/.Getwdscip-go gomod github.com/golang/go/src go1.24.0 os/Getwd().() |
| 247 | if err != nil { |
| 248 | return WebListDatascip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListData#{}, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("could not stat current dir: %v", err) |
| 249 | } |
| 250 | sourcePath = wd |
| 251 | } |
| 252 | sp := newSourcePrinterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/newSourcePrinter().(rpt, obj, sourcePath) |
| 253 | if len(sp.interestscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#interest.) == 0 { |
| 254 | return WebListDatascip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListData#{}, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("no matches found for regexp: %s", rpt.optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#options..Symbolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#Symbol.) |
| 255 | } |
| 256 | defer sp.closescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#close().() |
| 257 | return sp.generatescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#generate().(maxFiles, rpt), nil |
| 258 | } |
| 259 | |
| 260 | func newSourcePrinterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/newSourcePrinter().(rpt *Reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#, obj pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.ObjToolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/ObjTool#, sourcePath string) *sourcePrinterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter# { |
| 261 | sp := &sourcePrinterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#{ |
| 262 | readerscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#reader.: newSourceReaderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/newSourceReader().(sourcePath, rpt.optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#options..TrimPathscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#TrimPath.), |
| 263 | synthscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#synth.: newSynthCodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/newSynthCode().(rpt.profscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#prof..Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping.), |
| 264 | objectToolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#objectTool.: obj, |
| 265 | objectsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#objects.: map[string]pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.ObjFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/ObjFile#{}, |
| 266 | symscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#sym.: rpt.optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#options..Symbolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#Symbol., |
| 267 | filesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#files.: map[string]*sourceFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#{}, |
| 268 | instsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#insts.: map[uint64]instructionInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#{}, |
| 269 | prettyNamesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#prettyNames.: map[string]string{}, |
| 270 | interestscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#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.symscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#sym. != nil { |
| 277 | if hex, err := strconvscip-go gomod github.com/golang/go/src go1.24.0 strconv/.ParseUintscip-go gomod github.com/golang/go/src go1.24.0 strconv/ParseUint().(sp.symscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#sym..Stringscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#String().(), 0, 64); err == nil { |
| 278 | address = &hex |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | addrs := map[uint64]addrInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/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 *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#, index int) { |
| 288 | fn := loc.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Line.[index] |
| 289 | if fn.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Function. == nil { |
| 290 | return |
| 291 | } |
| 292 | sp.interestscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#interest.[fn.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Function..Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Name.] = true |
| 293 | sp.interestscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#interest.[fn.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Function..SystemNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#SystemName.] = true |
| 294 | if _, ok := addrs[addr]; !ok { |
| 295 | addrs[addr] = addrInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addrInfo#{loc, sp.objectFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#objectFile().(loc.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Mapping.)} |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | // See if sp.sym matches line. |
| 300 | matches := func(line profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#) bool { |
| 301 | if line.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Function. == nil { |
| 302 | return false |
| 303 | } |
| 304 | return sp.symscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#sym..MatchStringscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#MatchString().(line.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Function..Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Name.) || |
| 305 | sp.symscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#sym..MatchStringscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#MatchString().(line.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Function..SystemNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#SystemName.) || |
| 306 | sp.symscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#sym..MatchStringscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#MatchString().(line.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Function..Filenamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Filename.) |
| 307 | } |
| 308 | |
| 309 | // Extract sample counts and compute set of interesting functions. |
| 310 | for _, sample := range rpt.profscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#prof..Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample. { |
| 311 | value := rpt.optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#options..SampleValuescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#SampleValue.(sample.Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value.) |
| 312 | if rpt.optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#options..SampleMeanDivisorscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#SampleMeanDivisor. != nil { |
| 313 | div := rpt.optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#options..SampleMeanDivisorscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#SampleMeanDivisor.(sample.Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value.) |
| 314 | if div != 0 { |
| 315 | value /= div |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | // Find call-sites matching sym. |
| 320 | for i := len(sample.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location.) - 1; i >= 0; i-- { |
| 321 | loc := sample.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location.[i] |
| 322 | for _, line := range loc.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Line. { |
| 323 | if line.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Function. == nil { |
| 324 | continue |
| 325 | } |
| 326 | sp.prettyNamesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#prettyNames.[line.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Function..SystemNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#SystemName.] = line.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Function..Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Name. |
| 327 | } |
| 328 | |
| 329 | addr := loc.Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Address. |
| 330 | if addr == 0 { |
| 331 | // Some profiles are missing valid addresses. |
| 332 | addr = sp.synthscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#synth..addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/synthCode#address().(loc) |
| 333 | } |
| 334 | |
| 335 | cum[addr] += value |
| 336 | if i == 0 { |
| 337 | flat[addr] += value |
| 338 | } |
| 339 | |
| 340 | if sp.symscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#sym. == nil || (address != nil && addr == *address) { |
| 341 | // Interested in top-level entry of stack. |
| 342 | if len(loc.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Line.) > 0 { |
| 343 | markInterest(addr, loc, len(loc.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Line.)-1) |
| 344 | } |
| 345 | continue |
| 346 | } |
| 347 | |
| 348 | // Search in inlined stack for a match. |
| 349 | matchFile := (loc.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Mapping. != nil && sp.symscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#sym..MatchStringscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#MatchString().(loc.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Mapping..Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File.)) |
| 350 | for j, line := range loc.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Line. { |
| 351 | if (j == 0 && matchFile) || matches(line) { |
| 352 | markInterest(addr, loc, j) |
| 353 | } |
| 354 | } |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | sp.expandAddressesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#expandAddresses().(rpt, addrs, flat) |
| 359 | sp.initSamplesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#initSamples().(flat, cum) |
| 360 | return sp |
| 361 | } |
| 362 | |
| 363 | func (sp *sourcePrinterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#) closescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#close().() { |
| 364 | for _, objFile := range sp.objectsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#objects. { |
| 365 | if objFile != nil { |
| 366 | objFile.Closescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/ObjFile#Close.() |
| 367 | } |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | func (sp *sourcePrinterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#) expandAddressesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#expandAddresses().(rpt *Reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#, addrs map[uint64]addrInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addrInfo#, flat map[uint64]int64) { |
| 372 | // We found interesting addresses (ones with non-zero samples) above. |
| 373 | // Get covering address ranges and disassemble the ranges. |
| 374 | ranges, unprocessed := sp.splitIntoRangesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#splitIntoRanges().(rpt.profscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#prof., addrs, flat) |
| 375 | sp.handleUnprocessedscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#handleUnprocessed().(addrs, unprocessed) |
| 376 | |
| 377 | // Trim ranges if there are too many. |
| 378 | const maxRanges = 25 |
| 379 | sortscip-go gomod github.com/golang/go/src go1.24.0 sort/.Slicescip-go gomod github.com/golang/go/src go1.24.0 sort/Slice().(ranges, func(i, j int) bool { |
| 380 | return ranges[i].scorescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addressRange#score. > ranges[j].scorescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addressRange#score. |
| 381 | }) |
| 382 | if len(ranges) > maxRanges { |
| 383 | ranges = ranges[:maxRanges] |
| 384 | } |
| 385 | |
| 386 | for _, r := range ranges { |
| 387 | objBegin, err := r.objscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addressRange#obj..ObjAddrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/ObjFile#ObjAddr.(r.beginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addressRange#begin.) |
| 388 | if err != nil { |
| 389 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Fprintf().(osscip-go gomod github.com/golang/go/src go1.24.0 os/.Stderrscip-go gomod github.com/golang/go/src go1.24.0 os/Stderr., "Failed to compute objdump address for range start %x: %v\n", r.beginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addressRange#begin., err) |
| 390 | continue |
| 391 | } |
| 392 | objEnd, err := r.objscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addressRange#obj..ObjAddrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/ObjFile#ObjAddr.(r.endscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addressRange#end.) |
| 393 | if err != nil { |
| 394 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Fprintf().(osscip-go gomod github.com/golang/go/src go1.24.0 os/.Stderrscip-go gomod github.com/golang/go/src go1.24.0 os/Stderr., "Failed to compute objdump address for range end %x: %v\n", r.endscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addressRange#end., err) |
| 395 | continue |
| 396 | } |
| 397 | base := r.beginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addressRange#begin. - objBegin |
| 398 | insts, err := sp.objectToolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#objectTool..Disasmscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/ObjTool#Disasm.(r.mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addressRange#mapping..Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File., objBegin, objEnd, rpt.optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#options..IntelSyntaxscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#IntelSyntax.) |
| 399 | if err != nil { |
| 400 | // TODO(sanjay): Report that the covered addresses are missing. |
| 401 | continue |
| 402 | } |
| 403 | |
| 404 | var lastFrames []pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.Framescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame# |
| 405 | var lastAddr, maxAddr uint64 |
| 406 | for i, inst := range insts { |
| 407 | addr := inst.Addrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Inst#Addr. + base |
| 408 | |
| 409 | // Guard against duplicate output from Disasm. |
| 410 | if addr <= maxAddr { |
| 411 | continue |
| 412 | } |
| 413 | maxAddr = addr |
| 414 | |
| 415 | length := 1 |
| 416 | if i+1 < len(insts) && insts[i+1].Addrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Inst#Addr. > inst.Addrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Inst#Addr. { |
| 417 | // Extend to next instruction. |
| 418 | length = int(insts[i+1].Addrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Inst#Addr. - inst.Addrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Inst#Addr.) |
| 419 | } |
| 420 | |
| 421 | // Get inlined-call-stack for address. |
| 422 | frames, err := r.objscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addressRange#obj..SourceLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/ObjFile#SourceLine.(addr) |
| 423 | if err != nil { |
| 424 | // Construct a frame from disassembler output. |
| 425 | frames = []pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.Framescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#{{Funcscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#Func.: inst.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Inst#Function., Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#File.: inst.Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Inst#File., Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#Line.: inst.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Inst#Line.}} |
| 426 | } |
| 427 | |
| 428 | x := instructionInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#{objAddrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#objAddr.: inst.Addrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Inst#Addr., lengthscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#length.: length, disasmscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#disasm.: inst.Textscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Inst#Text.} |
| 429 | if len(frames) > 0 { |
| 430 | // We could consider using the outer-most caller's source |
| 431 | // location so we give the some hint as to where the |
| 432 | // inlining happened that led to this instruction. So for |
| 433 | // example, suppose we have the following (inlined) call |
| 434 | // chains for this instruction: |
| 435 | // F1->G->H |
| 436 | // F2->G->H |
| 437 | // We could tag the instructions from the first call with |
| 438 | // F1 and instructions from the second call with F2. But |
| 439 | // that leads to a somewhat confusing display. So for now, |
| 440 | // we stick with just the inner-most location (i.e., H). |
| 441 | // In the future we will consider changing the display to |
| 442 | // make caller info more visible. |
| 443 | index := 0 // Inner-most frame |
| 444 | x.filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#file. = frames[index].Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#File. |
| 445 | x.linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#line. = frames[index].Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#Line. |
| 446 | } |
| 447 | sp.instsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#insts.[addr] = x |
| 448 | |
| 449 | // We sometimes get instructions with a zero reported line number. |
| 450 | // Make such instructions have the same line info as the preceding |
| 451 | // instruction, if an earlier instruction is found close enough. |
| 452 | const neighborhood = 32 |
| 453 | if len(frames) > 0 && frames[0].Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#Line. != 0 { |
| 454 | lastFrames = frames |
| 455 | lastAddr = addr |
| 456 | } else if (addr-lastAddr <= neighborhood) && lastFrames != nil { |
| 457 | frames = lastFrames |
| 458 | } |
| 459 | |
| 460 | sp.addStackscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#addStack().(addr, frames) |
| 461 | } |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | func (sp *sourcePrinterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#) addStackscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#addStack().(addr uint64, frames []pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.Framescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#) { |
| 466 | // See if the stack contains a function we are interested in. |
| 467 | for i, f := range frames { |
| 468 | if !sp.interestscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#interest.[f.Funcscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#Func.] { |
| 469 | continue |
| 470 | } |
| 471 | |
| 472 | // Record sub-stack under frame's file/line. |
| 473 | fname := canonicalizeFileNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/canonicalizeFileName().(f.Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#File.) |
| 474 | file := sp.filesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#files.[fname] |
| 475 | if file == nil { |
| 476 | file = &sourceFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#{ |
| 477 | fnamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#fname.: fname, |
| 478 | linesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#lines.: map[int][]sourceInstscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceInst#{}, |
| 479 | funcNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#funcName.: map[int]string{}, |
| 480 | } |
| 481 | sp.filesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#files.[fname] = file |
| 482 | } |
| 483 | callees := frames[:i] |
| 484 | stack := make([]callIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/callID#, 0, len(callees)) |
| 485 | for j := len(callees) - 1; j >= 0; j-- { // Reverse so caller is first |
| 486 | stack = append(stack, callIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/callID#{ |
| 487 | filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/callID#file.: callees[j].Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#File., |
| 488 | linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/callID#line.: callees[j].Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#Line., |
| 489 | }) |
| 490 | } |
| 491 | file.linesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#lines.[f.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#Line.] = append(file.linesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#lines.[f.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#Line.], sourceInstscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceInst#{addr, stack}) |
| 492 | |
| 493 | // Remember the first function name encountered per source line |
| 494 | // and assume that line belongs to that function. |
| 495 | if _, ok := file.funcNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#funcName.[f.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#Line.]; !ok { |
| 496 | file.funcNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#funcName.[f.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#Line.] = f.Funcscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#Func. |
| 497 | } |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | // synthAsm is the special disassembler value used for instructions without an object file. |
| 502 | const synthAsmscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/synthAsm. = "" |
| 503 | |
| 504 | // handleUnprocessed handles addresses that were skipped by splitIntoRanges because they |
| 505 | // did not belong to a known object file. |
| 506 | func (sp *sourcePrinterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#) handleUnprocessedscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#handleUnprocessed().(addrs map[uint64]addrInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addrInfo#, unprocessed []uint64) { |
| 507 | // makeFrames synthesizes a []plugin.Frame list for the specified address. |
| 508 | // The result will typically have length 1, but may be longer if address corresponds |
| 509 | // to inlined calls. |
| 510 | makeFrames := func(addr uint64) []pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.Framescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame# { |
| 511 | loc := addrs[addr].locscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addrInfo#loc. |
| 512 | stack := make([]pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.Framescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#, 0, len(loc.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Line.)) |
| 513 | for _, line := range loc.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Line. { |
| 514 | fn := line.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Function. |
| 515 | if fn == nil { |
| 516 | continue |
| 517 | } |
| 518 | stack = append(stack, pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.Framescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#{ |
| 519 | Funcscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#Func.: fn.Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Name., |
| 520 | Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#File.: fn.Filenamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Filename., |
| 521 | Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#Line.: int(line.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Line.), |
| 522 | }) |
| 523 | } |
| 524 | return stack |
| 525 | } |
| 526 | |
| 527 | for _, addr := range unprocessed { |
| 528 | frames := makeFrames(addr) |
| 529 | x := instructionInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#{ |
| 530 | objAddrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#objAddr.: addr, |
| 531 | lengthscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#length.: 1, |
| 532 | disasmscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#disasm.: synthAsmscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/synthAsm., |
| 533 | } |
| 534 | if len(frames) > 0 { |
| 535 | x.filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#file. = frames[0].Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#File. |
| 536 | x.linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#line. = frames[0].Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#Line. |
| 537 | } |
| 538 | sp.instsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#insts.[addr] = x |
| 539 | |
| 540 | sp.addStackscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#addStack().(addr, frames) |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | // splitIntoRanges converts the set of addresses we are interested in into a set of address |
| 545 | // ranges to disassemble. It also returns the set of addresses found that did not have an |
| 546 | // associated object file and were therefore not added to an address range. |
| 547 | func (sp *sourcePrinterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#) splitIntoRangesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#splitIntoRanges().(prof *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#, addrMap map[uint64]addrInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addrInfo#, flat map[uint64]int64) ([]addressRangescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addressRange#, []uint64) { |
| 548 | // Partition addresses into two sets: ones with a known object file, and ones without. |
| 549 | var addrs, unprocessed []uint64 |
| 550 | for addr, info := range addrMap { |
| 551 | if info.objscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addrInfo#obj. != nil { |
| 552 | addrs = append(addrs, addr) |
| 553 | } else { |
| 554 | unprocessed = append(unprocessed, addr) |
| 555 | } |
| 556 | } |
| 557 | slicesscip-go gomod github.com/golang/go/src go1.24.0 slices/.Sortscip-go gomod github.com/golang/go/src go1.24.0 slices/Sort().(addrs) |
| 558 | |
| 559 | const expand = 500 // How much to expand range to pick up nearby addresses. |
| 560 | var result []addressRangescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addressRange# |
| 561 | for i, n := 0, len(addrs); i < n; { |
| 562 | begin, end := addrs[i], addrs[i] |
| 563 | sum := flat[begin] |
| 564 | i++ |
| 565 | |
| 566 | info := addrMap[begin] |
| 567 | m := info.locscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addrInfo#loc..Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Mapping. |
| 568 | obj := info.objscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addrInfo#obj. // Non-nil because of the partitioning done above. |
| 569 | |
| 570 | // Find following addresses that are close enough to addrs[i]. |
| 571 | for i < n && addrs[i] <= end+2*expand && addrs[i] < m.Limitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Limit. { |
| 572 | // When we expand ranges by "expand" on either side, the ranges |
| 573 | // for addrs[i] and addrs[i-1] will merge. |
| 574 | end = addrs[i] |
| 575 | sum += flat[end] |
| 576 | i++ |
| 577 | } |
| 578 | if m.Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start.-begin >= expand { |
| 579 | begin -= expand |
| 580 | } else { |
| 581 | begin = m.Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start. |
| 582 | } |
| 583 | if m.Limitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Limit.-end >= expand { |
| 584 | end += expand |
| 585 | } else { |
| 586 | end = m.Limitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Limit. |
| 587 | } |
| 588 | |
| 589 | result = append(result, addressRangescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/addressRange#{begin, end, obj, m, sum}) |
| 590 | } |
| 591 | return result, unprocessed |
| 592 | } |
| 593 | |
| 594 | func (sp *sourcePrinterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#) initSamplesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#initSamples().(flat, cum map[uint64]int64) { |
| 595 | for addr, inst := range sp.instsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#insts. { |
| 596 | // Move all samples that were assigned to the middle of an instruction to the |
| 597 | // beginning of that instruction. This takes care of samples that were recorded |
| 598 | // against pc+1. |
| 599 | instEnd := addr + uint64(inst.lengthscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#length.) |
| 600 | for p := addr; p < instEnd; p++ { |
| 601 | inst.flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#flat. += flat[p] |
| 602 | inst.cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#cum. += cum[p] |
| 603 | } |
| 604 | sp.instsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#insts.[addr] = inst |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | func (sp *sourcePrinterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#) generatescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#generate().(maxFiles int, rpt *Reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#) WebListDatascip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListData# { |
| 609 | // Finalize per-file counts. |
| 610 | for _, file := range sp.filesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#files. { |
| 611 | seen := map[uint64]bool{} |
| 612 | for _, line := range file.linesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#lines. { |
| 613 | for _, x := range line { |
| 614 | if seen[x.addrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceInst#addr.] { |
| 615 | // Same address can be displayed multiple times in a file |
| 616 | // (e.g., if we show multiple inlined functions). |
| 617 | // Avoid double-counting samples in this case. |
| 618 | continue |
| 619 | } |
| 620 | seen[x.addrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceInst#addr.] = true |
| 621 | inst := sp.instsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#insts.[x.addrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceInst#addr.] |
| 622 | file.cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#cum. += inst.cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#cum. |
| 623 | file.flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#flat. += inst.flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#flat. |
| 624 | } |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | // Get sorted list of files to print. |
| 629 | var files []*sourceFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile# |
| 630 | for _, f := range sp.filesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#files. { |
| 631 | files = append(files, f) |
| 632 | } |
| 633 | order := func(i, j int) bool { return files[i].flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#flat. > files[j].flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#flat. } |
| 634 | if maxFiles < 0 { |
| 635 | // Order by name for compatibility with old code. |
| 636 | order = func(i, j int) bool { return files[i].fnamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#fname. < files[j].fnamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#fname. } |
| 637 | maxFiles = len(files) |
| 638 | } |
| 639 | sortscip-go gomod github.com/golang/go/src go1.24.0 sort/.Slicescip-go gomod github.com/golang/go/src go1.24.0 sort/Slice().(files, order) |
| 640 | result := WebListDatascip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListData#{ |
| 641 | Totalscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListData#Total.: rpt.formatValuescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#formatValue.(rpt.totalscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#total.), |
| 642 | } |
| 643 | for i, f := range files { |
| 644 | if i < maxFiles { |
| 645 | result.Filesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListData#Files. = append(result.Filesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListData#Files., sp.generateFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#generateFile().(f, rpt)) |
| 646 | } |
| 647 | } |
| 648 | return result |
| 649 | } |
| 650 | |
| 651 | func (sp *sourcePrinterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#) generateFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#generateFile().(f *sourceFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#, rpt *Reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#) WebListFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListFile# { |
| 652 | var result WebListFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListFile# |
| 653 | for _, fn := range sp.functionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#functions().(f) { |
| 654 | if fn.cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#cum. == 0 { |
| 655 | continue |
| 656 | } |
| 657 | |
| 658 | listfn := WebListFuncscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListFunc#{ |
| 659 | Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListFunc#Name.: fn.namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#name., |
| 660 | Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListFunc#File.: f.fnamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#fname., |
| 661 | Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListFunc#Flat.: rpt.formatValuescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#formatValue.(fn.flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#flat.), |
| 662 | Cumulativescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListFunc#Cumulative.: rpt.formatValuescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#formatValue.(fn.cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#cum.), |
| 663 | Percentscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListFunc#Percent.: measurementscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/.Percentagescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/Percentage().(fn.cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#cum., rpt.totalscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#total.), |
| 664 | } |
| 665 | var asm []assemblyInstructionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/assemblyInstruction# |
| 666 | for l := fn.beginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#begin.; l < fn.endscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#end.; l++ { |
| 667 | lineContents, ok := sp.readerscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#reader..linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceReader#line().(f.fnamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#fname., l) |
| 668 | if !ok { |
| 669 | if len(f.linesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#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.linesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#lines.[l] { |
| 687 | addr := inst.addrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceInst#addr. |
| 688 | x := sp.instsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#insts.[addr] |
| 689 | flatSum += x.flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#flat. |
| 690 | cumSum += x.cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#cum. |
| 691 | startsBlock := (addr != lastAddr+uint64(sp.instsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#insts.[lastAddr].lengthscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#length.)) |
| 692 | lastAddr = addr |
| 693 | |
| 694 | // divisors already applied, so leave flatDiv,cumDiv as 0 |
| 695 | asm = append(asm, assemblyInstructionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/assemblyInstruction#{ |
| 696 | addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/assemblyInstruction#address.: x.objAddrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#objAddr., |
| 697 | instructionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/assemblyInstruction#instruction.: x.disasmscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#disasm., |
| 698 | functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/assemblyInstruction#function.: fn.namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#name., |
| 699 | filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/assemblyInstruction#file.: x.filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#file., |
| 700 | linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/assemblyInstruction#line.: x.linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#line., |
| 701 | flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/assemblyInstruction#flat.: x.flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#flat., |
| 702 | cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/assemblyInstruction#cum.: x.cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#cum., |
| 703 | startsBlockscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/assemblyInstruction#startsBlock.: startsBlock, |
| 704 | inlineCallsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/assemblyInstruction#inlineCalls.: inst.stackscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceInst#stack., |
| 705 | }) |
| 706 | } |
| 707 | |
| 708 | listfn.Linesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListFunc#Lines. = append(listfn.Linesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListFunc#Lines., makeWebListLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/makeWebListLine().(l, flatSum, cumSum, lineContents, asm, sp.readerscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#reader., rpt)) |
| 709 | } |
| 710 | |
| 711 | result.Funcsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListFile#Funcs. = append(result.Funcsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListFile#Funcs., listfn) |
| 712 | } |
| 713 | return result |
| 714 | } |
| 715 | |
| 716 | // functions splits apart the lines to show in a file into a list of per-function ranges. |
| 717 | func (sp *sourcePrinterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#) functionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#functions().(f *sourceFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#) []sourceFunctionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction# { |
| 718 | var funcs []sourceFunctionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction# |
| 719 | |
| 720 | // Get interesting lines in sorted order. |
| 721 | lines := make([]int, 0, len(f.linesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#lines.)) |
| 722 | for l := range f.linesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#lines. { |
| 723 | lines = append(lines, l) |
| 724 | } |
| 725 | sortscip-go gomod github.com/golang/go/src go1.24.0 sort/.Intsscip-go gomod github.com/golang/go/src go1.24.0 sort/Ints().(lines) |
| 726 | |
| 727 | // Merge adjacent lines that are in same function and not too far apart. |
| 728 | const mergeLimit = 20 |
| 729 | for _, l := range lines { |
| 730 | name := f.funcNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#funcName.[l] |
| 731 | if pretty, ok := sp.prettyNamesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#prettyNames.[name]; ok { |
| 732 | // Use demangled name if available. |
| 733 | name = pretty |
| 734 | } |
| 735 | |
| 736 | fn := sourceFunctionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#{namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#name.: name, beginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#begin.: l, endscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#end.: l + 1} |
| 737 | for _, x := range f.linesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFile#lines.[l] { |
| 738 | inst := sp.instsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#insts.[x.addrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceInst#addr.] |
| 739 | fn.flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#flat. += inst.flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#flat. |
| 740 | fn.cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#cum. += inst.cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/instructionInfo#cum. |
| 741 | } |
| 742 | |
| 743 | // See if we should merge into preceding function. |
| 744 | if len(funcs) > 0 { |
| 745 | last := funcs[len(funcs)-1] |
| 746 | if l-last.endscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#end. < mergeLimit && last.namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#name. == name { |
| 747 | last.endscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#end. = l + 1 |
| 748 | last.flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#flat. += fn.flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#flat. |
| 749 | last.cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#cum. += fn.cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#cum. |
| 750 | funcs[len(funcs)-1] = last |
| 751 | continue |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | // Add new function. |
| 756 | funcs = append(funcs, fn) |
| 757 | } |
| 758 | |
| 759 | // Expand function boundaries to show neighborhood. |
| 760 | const expand = 5 |
| 761 | for i, f := range funcs { |
| 762 | if i == 0 { |
| 763 | // Extend backwards, stopping at line number 1, but do not disturb 0 |
| 764 | // since that is a special line number that can show up when addr2line |
| 765 | // cannot determine the real line number. |
| 766 | if f.beginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#begin. > expand { |
| 767 | f.beginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#begin. -= expand |
| 768 | } else if f.beginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#begin. > 1 { |
| 769 | f.beginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#begin. = 1 |
| 770 | } |
| 771 | } else { |
| 772 | // Find gap from predecessor and divide between predecessor and f. |
| 773 | halfGap := min((f.beginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#begin.-funcs[i-1].endscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#end.)/2, expand) |
| 774 | funcs[i-1].endscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#end. += halfGap |
| 775 | f.beginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#begin. -= halfGap |
| 776 | } |
| 777 | funcs[i] = f |
| 778 | } |
| 779 | |
| 780 | // Also extend the ending point of the last function. |
| 781 | if len(funcs) > 0 { |
| 782 | funcs[len(funcs)-1].endscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceFunction#end. += expand |
| 783 | } |
| 784 | |
| 785 | return funcs |
| 786 | } |
| 787 | |
| 788 | // objectFile return the object for the specified mapping, opening it if necessary. |
| 789 | // It returns nil on error. |
| 790 | func (sp *sourcePrinterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#) objectFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#objectFile().(m *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#) pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.ObjFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/ObjFile# { |
| 791 | if m == nil { |
| 792 | return nil |
| 793 | } |
| 794 | if object, ok := sp.objectsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#objects.[m.Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File.]; ok { |
| 795 | return object // May be nil if we detected an error earlier. |
| 796 | } |
| 797 | object, err := sp.objectToolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#objectTool..Openscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/ObjTool#Open.(m.Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File., m.Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start., m.Limitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Limit., m.Offsetscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Offset., m.KernelRelocationSymbolscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#KernelRelocationSymbol.) |
| 798 | if err != nil { |
| 799 | object = nil |
| 800 | } |
| 801 | sp.objectsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourcePrinter#objects.[m.Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File.] = object // Cache even on error. |
| 802 | return object |
| 803 | } |
| 804 | |
| 805 | // makeWebListLine returns the contents of a single line in a web listing. This includes |
| 806 | // the source line and the corresponding assembly. |
| 807 | func makeWebListLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/makeWebListLine().(lineNo int, flat, cum int64, lineContents string, |
| 808 | assembly []assemblyInstructionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/assemblyInstruction#, reader *sourceReaderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceReader#, rpt *Reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#) WebListLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListLine# { |
| 809 | line := WebListLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListLine#{ |
| 810 | SrcLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListLine#SrcLine.: lineContents, |
| 811 | Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListLine#Line.: lineNo, |
| 812 | Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListLine#Flat.: valueOrDotscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/valueOrDot().(flat, rpt), |
| 813 | Cumulativescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListLine#Cumulative.: valueOrDotscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/valueOrDot().(cum, rpt), |
| 814 | } |
| 815 | |
| 816 | if len(assembly) == 0 { |
| 817 | line.HTMLClassscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListLine#HTMLClass. = "nop" |
| 818 | return line |
| 819 | } |
| 820 | |
| 821 | nestedInfo := false |
| 822 | line.HTMLClassscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListLine#HTMLClass. = "deadsrc" |
| 823 | for _, an := range assembly { |
| 824 | if len(an.inlineCallsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/assemblyInstruction#inlineCalls.) > 0 || an.instructionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/assemblyInstruction#instruction. != synthAsmscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/synthAsm. { |
| 825 | nestedInfo = true |
| 826 | line.HTMLClassscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListLine#HTMLClass. = "livesrc" |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | if nestedInfo { |
| 831 | srcIndent := indentationscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/indentation().(lineContents) |
| 832 | line.Instructionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListLine#Instructions. = makeWebListInstructionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/makeWebListInstructions().(srcIndent, assembly, reader, rpt) |
| 833 | } |
| 834 | return line |
| 835 | } |
| 836 | |
| 837 | func makeWebListInstructionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/makeWebListInstructions().(srcIndent int, assembly []assemblyInstructionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/assemblyInstruction#, reader *sourceReaderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceReader#, rpt *Reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#) []WebListInstructionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListInstruction# { |
| 838 | var result []WebListInstructionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListInstruction# |
| 839 | var curCalls []callIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/callID# |
| 840 | for i, an := range assembly { |
| 841 | var fileline string |
| 842 | if an.filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/assemblyInstruction#file. != "" { |
| 843 | fileline = fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprintf().("%s:%d", templatescip-go gomod github.com/golang/go/src go1.24.0 `html/template`/.HTMLEscapeStringscip-go gomod github.com/golang/go/src go1.24.0 `html/template`/HTMLEscapeString().(filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Basescip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Base().(an.filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/assemblyInstruction#file.)), an.linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/assemblyInstruction#line.) |
| 844 | } |
| 845 | text := stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Repeatscip-go gomod github.com/golang/go/src go1.24.0 strings/Repeat().(" ", srcIndent+4+4*len(an.inlineCallsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/assemblyInstruction#inlineCalls.)) + an.instructionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/assemblyInstruction#instruction. |
| 846 | inst := WebListInstructionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListInstruction#{ |
| 847 | NewBlockscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListInstruction#NewBlock.: (an.startsBlockscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/assemblyInstruction#startsBlock. && i != 0), |
| 848 | Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListInstruction#Flat.: valueOrDotscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/valueOrDot().(an.flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/assemblyInstruction#flat., rpt), |
| 849 | Cumulativescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListInstruction#Cumulative.: valueOrDotscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/valueOrDot().(an.cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/assemblyInstruction#cum., rpt), |
| 850 | Syntheticscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListInstruction#Synthetic.: (an.instructionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/assemblyInstruction#instruction. == synthAsmscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/synthAsm.), |
| 851 | Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListInstruction#Address.: an.addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/assemblyInstruction#address., |
| 852 | Disasmscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListInstruction#Disasm.: rightPadscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/rightPad().(text, 80), |
| 853 | FileLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListInstruction#FileLine.: fileline, |
| 854 | } |
| 855 | |
| 856 | // Add inlined call context. |
| 857 | for j, c := range an.inlineCallsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/assemblyInstruction#inlineCalls. { |
| 858 | if j < len(curCalls) && curCalls[j] == c { |
| 859 | // Skip if same as previous instruction. |
| 860 | continue |
| 861 | } |
| 862 | curCalls = nil |
| 863 | fline, ok := reader.linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceReader#line().(c.filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/callID#file., c.linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/callID#line.) |
| 864 | if !ok { |
| 865 | fline = "" |
| 866 | } |
| 867 | srcCode := stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Repeatscip-go gomod github.com/golang/go/src go1.24.0 strings/Repeat().(" ", srcIndent+4+4*j) + stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.24.0 strings/TrimSpace().(fline) |
| 868 | inst.InlinedCallsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListInstruction#InlinedCalls. = append(inst.InlinedCallsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListInstruction#InlinedCalls., WebListCallscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListCall#{ |
| 869 | SrcLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListCall#SrcLine.: rightPadscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/rightPad().(srcCode, 80), |
| 870 | FileBasescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListCall#FileBase.: filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Basescip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Base().(c.filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/callID#file.), |
| 871 | Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListCall#Line.: c.linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/callID#line., |
| 872 | }) |
| 873 | } |
| 874 | curCalls = an.inlineCallsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/assemblyInstruction#inlineCalls. |
| 875 | |
| 876 | result = append(result, inst) |
| 877 | } |
| 878 | return result |
| 879 | } |
| 880 | |
| 881 | // getSourceFromFile collects the sources of a function from a source |
| 882 | // file and annotates it with the samples in fns. Returns the sources |
| 883 | // as nodes, using the info.name field to hold the source code. |
| 884 | func getSourceFromFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/getSourceFromFile().(file string, reader *sourceReaderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceReader#, fns graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#, start, end int) (graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#, string, error) { |
| 885 | lineNodes := make(map[int]graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#) |
| 886 | |
| 887 | // Collect source coordinates from profile. |
| 888 | const margin = 5 // Lines before first/after last sample. |
| 889 | if start == 0 { |
| 890 | if fns[0].Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..StartLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#StartLine. != 0 { |
| 891 | start = fns[0].Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..StartLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#StartLine. |
| 892 | } else { |
| 893 | start = fns[0].Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..Linenoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Lineno. - margin |
| 894 | } |
| 895 | } else { |
| 896 | start -= margin |
| 897 | } |
| 898 | if end == 0 { |
| 899 | end = fns[0].Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..Linenoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Lineno. |
| 900 | } |
| 901 | end += margin |
| 902 | for _, n := range fns { |
| 903 | lineno := n.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..Linenoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Lineno. |
| 904 | nodeStart := n.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..StartLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#StartLine. |
| 905 | if nodeStart == 0 { |
| 906 | nodeStart = lineno - margin |
| 907 | } |
| 908 | nodeEnd := lineno + margin |
| 909 | if nodeStart < start { |
| 910 | start = nodeStart |
| 911 | } else if nodeEnd > end { |
| 912 | end = nodeEnd |
| 913 | } |
| 914 | lineNodes[lineno] = append(lineNodes[lineno], n) |
| 915 | } |
| 916 | if start < 1 { |
| 917 | start = 1 |
| 918 | } |
| 919 | |
| 920 | var src graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes# |
| 921 | for lineno := start; lineno <= end; lineno++ { |
| 922 | line, ok := reader.linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceReader#line().(file, lineno) |
| 923 | if !ok { |
| 924 | break |
| 925 | } |
| 926 | flat, cum := lineNodes[lineno].Sumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#Sum().() |
| 927 | src = append(src, &graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/.Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#{ |
| 928 | Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info.: graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/.NodeInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#{ |
| 929 | Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Name.: stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.TrimRightscip-go gomod github.com/golang/go/src go1.24.0 strings/TrimRight().(line, "\n"), |
| 930 | Linenoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Lineno.: lineno, |
| 931 | }, |
| 932 | Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Flat.: flat, |
| 933 | Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Cum.: cum, |
| 934 | }) |
| 935 | } |
| 936 | if err := reader.fileErrorscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceReader#fileError().(file); err != nil { |
| 937 | return nil, file, err |
| 938 | } |
| 939 | return src, file, nil |
| 940 | } |
| 941 | |
| 942 | // sourceReader provides access to source code with caching of file contents. |
| 943 | type sourceReaderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceReader# struct { |
| 944 | // searchPath is a filepath.ListSeparator-separated list of directories where |
| 945 | // source files should be searched. |
| 946 | searchPathscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceReader#searchPath. string |
| 947 | |
| 948 | // trimPath is a filepath.ListSeparator-separated list of paths to trim. |
| 949 | trimPathscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceReader#trimPath. string |
| 950 | |
| 951 | // files maps from path name to a list of lines. |
| 952 | // files[*][0] is unused since line numbering starts at 1. |
| 953 | filesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceReader#files. map[string][]string |
| 954 | |
| 955 | // errors collects errors encountered per file. These errors are |
| 956 | // consulted before returning out of these module. |
| 957 | errorsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceReader#errors. map[string]error |
| 958 | } |
| 959 | |
| 960 | func newSourceReaderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/newSourceReader().(searchPath, trimPath string) *sourceReaderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceReader# { |
| 961 | return &sourceReaderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceReader#{ |
| 962 | searchPath, |
| 963 | trimPath, |
| 964 | make(map[string][]string), |
| 965 | make(map[string]error), |
| 966 | } |
| 967 | } |
| 968 | |
| 969 | func (reader *sourceReaderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceReader#) fileErrorscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceReader#fileError().(path string) error { |
| 970 | return reader.errorsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceReader#errors.[path] |
| 971 | } |
| 972 | |
| 973 | // line returns the line numbered "lineno" in path, or _,false if lineno is out of range. |
| 974 | func (reader *sourceReaderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceReader#) linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceReader#line().(path string, lineno int) (string, bool) { |
| 975 | lines, ok := reader.filesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceReader#files.[path] |
| 976 | if !ok { |
| 977 | // Read and cache file contents. |
| 978 | lines = []string{""} // Skip 0th line |
| 979 | f, err := openSourceFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/openSourceFile().(path, reader.searchPathscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceReader#searchPath., reader.trimPathscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceReader#trimPath.) |
| 980 | if err != nil { |
| 981 | reader.errorsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceReader#errors.[path] = err |
| 982 | } else { |
| 983 | s := bufioscip-go gomod github.com/golang/go/src go1.24.0 bufio/.NewScannerscip-go gomod github.com/golang/go/src go1.24.0 bufio/NewScanner().(f) |
| 984 | for s.Scanscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Scan().() { |
| 985 | lines = append(lines, s.Textscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Text().()) |
| 986 | } |
| 987 | f.Closescip-go gomod github.com/golang/go/src go1.24.0 os/File#Close().() |
| 988 | if s.Errscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Err().() != nil { |
| 989 | reader.errorsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceReader#errors.[path] = err |
| 990 | } |
| 991 | } |
| 992 | reader.filesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/sourceReader#files.[path] = lines |
| 993 | } |
| 994 | if lineno <= 0 || lineno >= len(lines) { |
| 995 | return "", false |
| 996 | } |
| 997 | return lines[lineno], true |
| 998 | } |
| 999 | |
| 1000 | // openSourceFile opens a source file from a name encoded in a profile. File |
| 1001 | // names in a profile after can be relative paths, so search them in each of |
| 1002 | // the paths in searchPath and their parents. In case the profile contains |
| 1003 | // absolute paths, additional paths may be configured to trim from the source |
| 1004 | // paths in the profile. This effectively turns the path into a relative path |
| 1005 | // searching it using searchPath as usual). |
| 1006 | func openSourceFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/openSourceFile().(path, searchPath, trim string) (*osscip-go gomod github.com/golang/go/src go1.24.0 os/.Filescip-go gomod github.com/golang/go/src go1.24.0 os/File#, error) { |
| 1007 | path = trimPathscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/trimPath().(path, trim, searchPath) |
| 1008 | // If file is still absolute, require file to exist. |
| 1009 | if filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.IsAbsscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/IsAbs().(path) { |
| 1010 | f, err := osscip-go gomod github.com/golang/go/src go1.24.0 os/.Openscip-go gomod github.com/golang/go/src go1.24.0 os/Open().(path) |
| 1011 | return f, err |
| 1012 | } |
| 1013 | // Scan each component of the path. |
| 1014 | for _, dir := range filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.SplitListscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/SplitList().(searchPath) { |
| 1015 | // Search up for every parent of each possible path. |
| 1016 | for { |
| 1017 | filename := filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Join().(dir, path) |
| 1018 | if f, err := osscip-go gomod github.com/golang/go/src go1.24.0 os/.Openscip-go gomod github.com/golang/go/src go1.24.0 os/Open().(filename); err == nil { |
| 1019 | return f, nil |
| 1020 | } |
| 1021 | parent := filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Dirscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Dir().(dir) |
| 1022 | if parent == dir { |
| 1023 | break |
| 1024 | } |
| 1025 | dir = parent |
| 1026 | } |
| 1027 | } |
| 1028 | |
| 1029 | return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("could not find file %s on path %s", path, searchPath) |
| 1030 | } |
| 1031 | |
| 1032 | // trimPath cleans up a path by removing prefixes that are commonly |
| 1033 | // found on profiles plus configured prefixes. |
| 1034 | // TODO(aalexand): Consider optimizing out the redundant work done in this |
| 1035 | // function if it proves to matter. |
| 1036 | func trimPathscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/trimPath().(path, trimPath, searchPath string) string { |
| 1037 | // Keep path variable intact as it's used below to form the return value. |
| 1038 | sPath, searchPath := filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.ToSlashscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/ToSlash().(path), filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.ToSlashscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/ToSlash().(searchPath) |
| 1039 | if trimPath == "" { |
| 1040 | // If the trim path is not configured, try to guess it heuristically: |
| 1041 | // search for basename of each search path in the original path and, if |
| 1042 | // found, strip everything up to and including the basename. So, for |
| 1043 | // example, given original path "/some/remote/path/my-project/foo/bar.c" |
| 1044 | // and search path "/my/local/path/my-project" the heuristic will return |
| 1045 | // "/my/local/path/my-project/foo/bar.c". |
| 1046 | for _, dir := range filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.SplitListscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/SplitList().(searchPath) { |
| 1047 | want := "/" + filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Basescip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Base().(dir) + "/" |
| 1048 | if found := stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Indexscip-go gomod github.com/golang/go/src go1.24.0 strings/Index().(sPath, want); found != -1 { |
| 1049 | return path[found+len(want):] |
| 1050 | } |
| 1051 | } |
| 1052 | } |
| 1053 | // Trim configured trim prefixes. |
| 1054 | trimPaths := append(filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.SplitListscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/SplitList().(filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.ToSlashscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/ToSlash().(trimPath)), "/proc/self/cwd/./", "/proc/self/cwd/") |
| 1055 | for _, trimPath := range trimPaths { |
| 1056 | if !stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.HasSuffixscip-go gomod github.com/golang/go/src go1.24.0 strings/HasSuffix().(trimPath, "/") { |
| 1057 | trimPath += "/" |
| 1058 | } |
| 1059 | if stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.24.0 strings/HasPrefix().(sPath, trimPath) { |
| 1060 | return path[len(trimPath):] |
| 1061 | } |
| 1062 | } |
| 1063 | return path |
| 1064 | } |
| 1065 | |
| 1066 | func indentationscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/indentation().(line string) int { |
| 1067 | column := 0 |
| 1068 | for _, c := range line { |
| 1069 | switch c { |
| 1070 | case ' ': |
| 1071 | column++ |
| 1072 | case '\t': |
| 1073 | column++ |
| 1074 | for column%8 != 0 { |
| 1075 | column++ |
| 1076 | } |
| 1077 | default: |
| 1078 | return column |
| 1079 | } |
| 1080 | } |
| 1081 | return column |
| 1082 | } |
| 1083 | |
| 1084 | // rightPad pads the input with spaces on the right-hand-side to make it have |
| 1085 | // at least width n. It treats tabs as enough spaces that lead to the next |
| 1086 | // 8-aligned tab-stop. |
| 1087 | func rightPadscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/rightPad().(s string, n int) string { |
| 1088 | var str stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Builderscip-go gomod github.com/golang/go/src go1.24.0 strings/Builder# |
| 1089 | |
| 1090 | // Convert tabs to spaces as we go so padding works regardless of what prefix |
| 1091 | // is placed before the result. |
| 1092 | column := 0 |
| 1093 | for _, c := range s { |
| 1094 | column++ |
| 1095 | if c == '\t' { |
| 1096 | str.WriteRunescip-go gomod github.com/golang/go/src go1.24.0 strings/Builder#WriteRune().(' ') |
| 1097 | for column%8 != 0 { |
| 1098 | column++ |
| 1099 | str.WriteRunescip-go gomod github.com/golang/go/src go1.24.0 strings/Builder#WriteRune().(' ') |
| 1100 | } |
| 1101 | } else { |
| 1102 | str.WriteRunescip-go gomod github.com/golang/go/src go1.24.0 strings/Builder#WriteRune().(c) |
| 1103 | } |
| 1104 | } |
| 1105 | for column < n { |
| 1106 | column++ |
| 1107 | str.WriteRunescip-go gomod github.com/golang/go/src go1.24.0 strings/Builder#WriteRune().(' ') |
| 1108 | } |
| 1109 | return str.Stringscip-go gomod github.com/golang/go/src go1.24.0 strings/Builder#String().() |
| 1110 | } |
| 1111 | |
| 1112 | func canonicalizeFileNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/canonicalizeFileName().(fname string) string { |
| 1113 | fname = stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.TrimPrefixscip-go gomod github.com/golang/go/src go1.24.0 strings/TrimPrefix().(fname, "/proc/self/cwd/") |
| 1114 | fname = stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.TrimPrefixscip-go gomod github.com/golang/go/src go1.24.0 strings/TrimPrefix().(fname, "./") |
| 1115 | return filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Cleanscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Clean().(fname) |
| 1116 | } |