| 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 driver implements the core pprof functionality. It can be |
| 16 | // parameterized with a flag implementation, fetch and symbolize |
| 17 | // mechanisms. |
| 18 | package driverscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/ |
| 19 | |
| 20 | import ( |
| 21 | "bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/" |
| 22 | "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 23 | "ioscip-go gomod github.com/golang/go/src go1.24.0 io/" |
| 24 | "osscip-go gomod github.com/golang/go/src go1.24.0 os/" |
| 25 | "path/filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/" |
| 26 | "regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/" |
| 27 | "stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/" |
| 28 | |
| 29 | "github.com/google/pprof/internal/pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/" |
| 30 | "github.com/google/pprof/internal/reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/" |
| 31 | "github.com/google/pprof/profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/" |
| 32 | ) |
| 33 | |
| 34 | // PProf acquires a profile, and symbolizes it using a profile |
| 35 | // manager. Then it generates a report formatted according to the |
| 36 | // options selected through the flags package. |
| 37 | func PProfscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/PProf().(eo *pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.Optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#) error { |
| 38 | // Remove any temporary files created during pprof processing. |
| 39 | defer cleanupTempFilesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/cleanupTempFiles().() |
| 40 | |
| 41 | o := setDefaultsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/setDefaults().(eo) |
| 42 | |
| 43 | src, cmd, err := parseFlagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/parseFlags().(o) |
| 44 | if err != nil { |
| 45 | return err |
| 46 | } |
| 47 | |
| 48 | p, err := fetchProfilesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fetchProfiles().(src, o) |
| 49 | if err != nil { |
| 50 | return err |
| 51 | } |
| 52 | |
| 53 | if cmd != nil { |
| 54 | return generateReportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/generateReport().(p, cmd, currentConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/currentConfig().(), o) |
| 55 | } |
| 56 | |
| 57 | if src.HTTPHostportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#HTTPHostport. != "" { |
| 58 | return serveWebInterfacescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/serveWebInterface().(src.HTTPHostportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#HTTPHostport., p, o, src.HTTPDisableBrowserscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#HTTPDisableBrowser.) |
| 59 | } |
| 60 | return interactivescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/interactive().(p, o) |
| 61 | } |
| 62 | |
| 63 | // generateRawReport is allowed to modify p. |
| 64 | func generateRawReportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/generateRawReport().(p *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#, cmd []string, cfg configscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#, o *pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.Optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#) (*commandscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/command#, *reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/.Reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#, error) { |
| 65 | // Identify units of numeric tags in profile. |
| 66 | numLabelUnits := identifyNumLabelUnitsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/identifyNumLabelUnits().(p, o.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI.) |
| 67 | |
| 68 | // Get report output format |
| 69 | c := pprofCommandsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/pprofCommands.[cmd[0]] |
| 70 | if c == nil { |
| 71 | panic("unexpected nil command") |
| 72 | } |
| 73 | |
| 74 | cfg = applyCommandOverridesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/applyCommandOverrides().(cmd[0], c.formatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/command#format., cfg) |
| 75 | |
| 76 | // Create label pseudo nodes before filtering, in case the filters use |
| 77 | // the generated nodes. |
| 78 | generateTagRootsLeavesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/generateTagRootsLeaves().(p, cfg, o.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI.) |
| 79 | |
| 80 | // Delay focus after configuring report to get percentages on all samples. |
| 81 | relative := cfg.RelativePercentagesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#RelativePercentages. |
| 82 | if relative { |
| 83 | if err := applyFocusscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/applyFocus().(p, numLabelUnits, cfg, o.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI.); err != nil { |
| 84 | return nil, nil, err |
| 85 | } |
| 86 | } |
| 87 | ropt, err := reportOptionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/reportOptions().(p, numLabelUnits, cfg) |
| 88 | if err != nil { |
| 89 | return nil, nil, err |
| 90 | } |
| 91 | ropt.OutputFormatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#OutputFormat. = c.formatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/command#format. |
| 92 | if len(cmd) == 2 { |
| 93 | s, err := regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/.Compilescip-go gomod github.com/golang/go/src go1.24.0 regexp/Compile().(cmd[1]) |
| 94 | if err != nil { |
| 95 | return nil, 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().("parsing argument regexp %s: %v", cmd[1], err) |
| 96 | } |
| 97 | ropt.Symbolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#Symbol. = s |
| 98 | } |
| 99 | |
| 100 | rpt := reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/.Newscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/New().(p, ropt) |
| 101 | if !relative { |
| 102 | if err := applyFocusscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/applyFocus().(p, numLabelUnits, cfg, o.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI.); err != nil { |
| 103 | return nil, nil, err |
| 104 | } |
| 105 | } |
| 106 | if err := aggregatescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/aggregate().(p, cfg); err != nil { |
| 107 | return nil, nil, err |
| 108 | } |
| 109 | |
| 110 | return c, rpt, nil |
| 111 | } |
| 112 | |
| 113 | // generateReport is allowed to modify p. |
| 114 | func generateReportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/generateReport().(p *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#, cmd []string, cfg configscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#, o *pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.Optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#) error { |
| 115 | c, rpt, err := generateRawReportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/generateRawReport().(p, cmd, cfg, o) |
| 116 | if err != nil { |
| 117 | return err |
| 118 | } |
| 119 | |
| 120 | // Generate the report. |
| 121 | dst := new(bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#) |
| 122 | switch rpt.OutputFormatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#OutputFormat().() { |
| 123 | case reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/.WebListscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebList.: |
| 124 | // We need template expansion, so generate here instead of in report. |
| 125 | err = printWebListscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/printWebList().(dst, rpt, o.Objscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#Obj.) |
| 126 | default: |
| 127 | err = reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/.Generatescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Generate().(dst, rpt, o.Objscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#Obj.) |
| 128 | } |
| 129 | if err != nil { |
| 130 | return err |
| 131 | } |
| 132 | src := dst |
| 133 | |
| 134 | // If necessary, perform any data post-processing. |
| 135 | if c.postProcessscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/command#postProcess. != nil { |
| 136 | dst = new(bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#) |
| 137 | if err := c.postProcessscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/command#postProcess.(src, dst, o.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI.); err != nil { |
| 138 | return err |
| 139 | } |
| 140 | src = dst |
| 141 | } |
| 142 | |
| 143 | // If no output is specified, use default visualizer. |
| 144 | output := cfg.Outputscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Output. |
| 145 | if output == "" { |
| 146 | if c.visualizerscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/command#visualizer. != nil { |
| 147 | return c.visualizerscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/command#visualizer.(src, osscip-go gomod github.com/golang/go/src go1.24.0 os/.Stdoutscip-go gomod github.com/golang/go/src go1.24.0 os/Stdout., o.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI.) |
| 148 | } |
| 149 | _, err := src.WriteToscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#WriteTo().(osscip-go gomod github.com/golang/go/src go1.24.0 os/.Stdoutscip-go gomod github.com/golang/go/src go1.24.0 os/Stdout.) |
| 150 | return err |
| 151 | } |
| 152 | |
| 153 | // Output to specified file. |
| 154 | o.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI..PrintErrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#PrintErr.("Generating report in ", output) |
| 155 | out, err := o.Writerscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#Writer..Openscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Writer#Open.(output) |
| 156 | if err != nil { |
| 157 | return err |
| 158 | } |
| 159 | if _, err := src.WriteToscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#WriteTo().(out); err != nil { |
| 160 | out.Closescip-go gomod github.com/golang/go/src go1.24.0 io/Closer#Close().() |
| 161 | return err |
| 162 | } |
| 163 | return out.Closescip-go gomod github.com/golang/go/src go1.24.0 io/Closer#Close().() |
| 164 | } |
| 165 | |
| 166 | func printWebListscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/printWebList().(dst 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`/.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#) error { |
| 167 | listing, err := reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/.MakeWebListscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/MakeWebList().(rpt, obj, -1) |
| 168 | if err != nil { |
| 169 | return err |
| 170 | } |
| 171 | legend := reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/.ProfileLabelsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/ProfileLabels().(rpt) |
| 172 | return renderHTMLscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/renderHTML().(dst, "sourcelisting", rpt, nil, legend, webArgsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#{ |
| 173 | Standalonescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#Standalone.: true, |
| 174 | Listingscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#Listing.: listing, |
| 175 | }) |
| 176 | } |
| 177 | |
| 178 | func applyCommandOverridesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/applyCommandOverrides().(cmd string, outputFormat int, cfg configscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#) configscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config# { |
| 179 | // Some report types override the trim flag to false below. This is to make |
| 180 | // sure the default heuristics of excluding insignificant nodes and edges |
| 181 | // from the call graph do not apply. One example where it is important is |
| 182 | // annotated source or disassembly listing. Those reports run on a specific |
| 183 | // function (or functions), but the trimming is applied before the function |
| 184 | // data is selected. So, with trimming enabled, the report could end up |
| 185 | // showing no data if the specified function is "uninteresting" as far as the |
| 186 | // trimming is concerned. |
| 187 | trim := cfg.Trimscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Trim. |
| 188 | |
| 189 | switch cmd { |
| 190 | case "disasm": |
| 191 | trim = false |
| 192 | cfg.Granularityscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Granularity. = "addresses" |
| 193 | // Force the 'noinlines' mode so that source locations for a given address |
| 194 | // collapse and there is only one for the given address. Without this |
| 195 | // cumulative metrics would be double-counted when annotating the assembly. |
| 196 | // This is because the merge is done by address and in case of an inlined |
| 197 | // stack each of the inlined entries is a separate callgraph node. |
| 198 | cfg.NoInlinesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#NoInlines. = true |
| 199 | case "weblist": |
| 200 | trim = false |
| 201 | cfg.Granularityscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Granularity. = "addresses" |
| 202 | cfg.NoInlinesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#NoInlines. = false // Need inline info to support call expansion |
| 203 | case "peek": |
| 204 | trim = false |
| 205 | case "list": |
| 206 | trim = false |
| 207 | cfg.Granularityscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Granularity. = "lines" |
| 208 | // Do not force 'noinlines' to be false so that specifying |
| 209 | // "-list foo -noinlines" is supported and works as expected. |
| 210 | case "text", "top", "topproto": |
| 211 | if cfg.NodeCountscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#NodeCount. == -1 { |
| 212 | cfg.NodeCountscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#NodeCount. = 0 |
| 213 | } |
| 214 | default: |
| 215 | if cfg.NodeCountscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#NodeCount. == -1 { |
| 216 | cfg.NodeCountscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#NodeCount. = 80 |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | switch outputFormat { |
| 221 | case reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/.Protoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Proto., reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/.Rawscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Raw., reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/.Callgrindscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Callgrind.: |
| 222 | trim = false |
| 223 | cfg.Granularityscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Granularity. = "addresses" |
| 224 | } |
| 225 | |
| 226 | if !trim { |
| 227 | cfg.NodeCountscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#NodeCount. = 0 |
| 228 | cfg.NodeFractionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#NodeFraction. = 0 |
| 229 | cfg.EdgeFractionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#EdgeFraction. = 0 |
| 230 | } |
| 231 | return cfg |
| 232 | } |
| 233 | |
| 234 | // generateTagRootsLeaves generates extra nodes from the tagroot and tagleaf options. |
| 235 | func generateTagRootsLeavesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/generateTagRootsLeaves().(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#, cfg configscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#, ui pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#) { |
| 236 | tagRootLabelKeys := dropEmptyStringsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/dropEmptyStrings().(stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Splitscip-go gomod github.com/golang/go/src go1.24.0 strings/Split().(cfg.TagRootscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#TagRoot., ",")) |
| 237 | tagLeafLabelKeys := dropEmptyStringsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/dropEmptyStrings().(stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Splitscip-go gomod github.com/golang/go/src go1.24.0 strings/Split().(cfg.TagLeafscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#TagLeaf., ",")) |
| 238 | rootm, leafm := addLabelNodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/addLabelNodes().(prof, tagRootLabelKeys, tagLeafLabelKeys, cfg.Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Unit.) |
| 239 | warnNoMatchesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/warnNoMatches().(cfg.TagRootscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#TagRoot. == "" || rootm, "TagRoot", ui) |
| 240 | warnNoMatchesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/warnNoMatches().(cfg.TagLeafscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#TagLeaf. == "" || leafm, "TagLeaf", ui) |
| 241 | } |
| 242 | |
| 243 | // dropEmptyStrings filters a slice to only non-empty strings |
| 244 | func dropEmptyStringsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/dropEmptyStrings().(in []string) (out []string) { |
| 245 | for _, s := range in { |
| 246 | if s != "" { |
| 247 | out = append(out, s) |
| 248 | } |
| 249 | } |
| 250 | return |
| 251 | } |
| 252 | |
| 253 | func aggregatescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/aggregate().(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#, cfg configscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#) error { |
| 254 | var function, filename, linenumber, address bool |
| 255 | inlines := !cfg.NoInlinesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#NoInlines. |
| 256 | switch cfg.Granularityscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Granularity. { |
| 257 | case "": |
| 258 | function = true // Default granularity is "functions" |
| 259 | case "addresses": |
| 260 | if inlines { |
| 261 | return nil |
| 262 | } |
| 263 | function = true |
| 264 | filename = true |
| 265 | linenumber = true |
| 266 | address = true |
| 267 | case "lines": |
| 268 | function = true |
| 269 | filename = true |
| 270 | linenumber = true |
| 271 | case "files": |
| 272 | filename = true |
| 273 | case "functions": |
| 274 | function = true |
| 275 | case "filefunctions": |
| 276 | function = true |
| 277 | filename = true |
| 278 | default: |
| 279 | 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().("unexpected granularity") |
| 280 | } |
| 281 | return prof.Aggregatescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Aggregate().(inlines, function, filename, linenumber, cfg.ShowColumnsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#ShowColumns., address) |
| 282 | } |
| 283 | |
| 284 | func reportOptionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/reportOptions().(p *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#, numLabelUnits map[string]string, cfg configscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#) (*reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/.Optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#, error) { |
| 285 | si, mean := cfg.SampleIndexscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#SampleIndex., cfg.Meanscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Mean. |
| 286 | value, meanDiv, sample, err := sampleFormatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/sampleFormat().(p, si, mean) |
| 287 | if err != nil { |
| 288 | return nil, err |
| 289 | } |
| 290 | |
| 291 | stype := sample.Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type. |
| 292 | if mean { |
| 293 | stype = "mean_" + stype |
| 294 | } |
| 295 | |
| 296 | if cfg.DivideByscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#DivideBy. == 0 { |
| 297 | 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().("zero divisor specified") |
| 298 | } |
| 299 | |
| 300 | var filters []string |
| 301 | addFilter := func(k string, v string) { |
| 302 | if v != "" { |
| 303 | filters = append(filters, k+"="+v) |
| 304 | } |
| 305 | } |
| 306 | addFilter("focus", cfg.Focusscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Focus.) |
| 307 | addFilter("ignore", cfg.Ignorescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Ignore.) |
| 308 | addFilter("hide", cfg.Hidescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Hide.) |
| 309 | addFilter("show", cfg.Showscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Show.) |
| 310 | addFilter("show_from", cfg.ShowFromscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#ShowFrom.) |
| 311 | addFilter("tagfocus", cfg.TagFocusscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#TagFocus.) |
| 312 | addFilter("tagignore", cfg.TagIgnorescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#TagIgnore.) |
| 313 | addFilter("tagshow", cfg.TagShowscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#TagShow.) |
| 314 | addFilter("taghide", cfg.TagHidescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#TagHide.) |
| 315 | |
| 316 | ropt := &reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/.Optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#{ |
| 317 | CumSortscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#CumSort.: cfg.Sortscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Sort. == "cum", |
| 318 | CallTreescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#CallTree.: cfg.CallTreescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#CallTree., |
| 319 | DropNegativescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#DropNegative.: cfg.DropNegativescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#DropNegative., |
| 320 | |
| 321 | CompactLabelsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#CompactLabels.: cfg.CompactLabelsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#CompactLabels., |
| 322 | Ratioscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#Ratio.: 1 / cfg.DivideByscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#DivideBy., |
| 323 | |
| 324 | NodeCountscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#NodeCount.: cfg.NodeCountscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#NodeCount., |
| 325 | NodeFractionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#NodeFraction.: cfg.NodeFractionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#NodeFraction., |
| 326 | EdgeFractionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#EdgeFraction.: cfg.EdgeFractionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#EdgeFraction., |
| 327 | |
| 328 | ActiveFiltersscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#ActiveFilters.: filters, |
| 329 | NumLabelUnitsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#NumLabelUnits.: numLabelUnits, |
| 330 | |
| 331 | SampleValuescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#SampleValue.: value, |
| 332 | SampleMeanDivisorscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#SampleMeanDivisor.: meanDiv, |
| 333 | SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#SampleType.: stype, |
| 334 | SampleUnitscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#SampleUnit.: sample.Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Unit., |
| 335 | |
| 336 | OutputUnitscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#OutputUnit.: cfg.Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Unit., |
| 337 | |
| 338 | SourcePathscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#SourcePath.: cfg.SourcePathscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#SourcePath., |
| 339 | TrimPathscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#TrimPath.: cfg.TrimPathscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#TrimPath., |
| 340 | |
| 341 | IntelSyntaxscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#IntelSyntax.: cfg.IntelSyntaxscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#IntelSyntax., |
| 342 | } |
| 343 | |
| 344 | if len(p.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping.) > 0 && p.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping.[0].Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File. != "" { |
| 345 | ropt.Titlescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#Title. = 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().(p.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping.[0].Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File.) |
| 346 | } |
| 347 | |
| 348 | return ropt, nil |
| 349 | } |
| 350 | |
| 351 | // identifyNumLabelUnits returns a map of numeric label keys to the units |
| 352 | // associated with those keys. |
| 353 | func identifyNumLabelUnitsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/identifyNumLabelUnits().(p *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#, ui pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#) map[string]string { |
| 354 | numLabelUnits, ignoredUnits := p.NumLabelUnitsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#NumLabelUnits().() |
| 355 | |
| 356 | // Print errors for tags with multiple units associated with |
| 357 | // a single key. |
| 358 | for k, units := range ignoredUnits { |
| 359 | ui.PrintErrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#PrintErr.(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().("For tag %s used unit %s, also encountered unit(s) %s", k, numLabelUnits[k], stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.24.0 strings/Join().(units, ", "))) |
| 360 | } |
| 361 | return numLabelUnits |
| 362 | } |
| 363 | |
| 364 | type sampleValueFuncscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/sampleValueFunc# func([]int64) int64 |
| 365 | |
| 366 | // sampleFormat returns a function to extract values out of a profile.Sample, |
| 367 | // and the type/units of those values. |
| 368 | func sampleFormatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/sampleFormat().(p *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#, sampleIndex string, mean bool) (value, meanDiv sampleValueFuncscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/sampleValueFunc#, v *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.ValueTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#, err error) { |
| 369 | if len(p.SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType.) == 0 { |
| 370 | return nil, nil, 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().("profile has no samples") |
| 371 | } |
| 372 | index, err := p.SampleIndexByNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleIndexByName().(sampleIndex) |
| 373 | if err != nil { |
| 374 | return nil, nil, nil, err |
| 375 | } |
| 376 | value = valueExtractorscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/valueExtractor().(index) |
| 377 | if mean { |
| 378 | meanDiv = valueExtractorscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/valueExtractor().(0) |
| 379 | } |
| 380 | v = p.SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType.[index] |
| 381 | return |
| 382 | } |
| 383 | |
| 384 | func valueExtractorscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/valueExtractor().(ix int) sampleValueFuncscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/sampleValueFunc# { |
| 385 | return func(v []int64) int64 { |
| 386 | return v[ix] |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | // profileCopier can be used to obtain a fresh copy of a profile. |
| 391 | // It is useful since reporting code may mutate the profile handed to it. |
| 392 | type profileCopierscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/profileCopier# []byte |
| 393 | |
| 394 | func makeProfileCopierscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/makeProfileCopier().(src *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#) profileCopierscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/profileCopier# { |
| 395 | // Pre-serialize the profile. We will deserialize every time a fresh copy is needed. |
| 396 | var buf bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer# |
| 397 | src.WriteUncompressedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#WriteUncompressed().(&buf) |
| 398 | return profileCopierscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/profileCopier#(buf.Bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#Bytes().()) |
| 399 | } |
| 400 | |
| 401 | // newCopy returns a new copy of the profile. |
| 402 | func (c profileCopierscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/profileCopier#) newCopyscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/profileCopier#newCopy().() *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# { |
| 403 | p, err := profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.ParseUncompressedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ParseUncompressed().([]byte(c)) |
| 404 | if err != nil { |
| 405 | panic(err) |
| 406 | } |
| 407 | return p |
| 408 | } |