| 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 driverscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/ |
| 16 | |
| 17 | import ( |
| 18 | "errorsscip-go gomod github.com/golang/go/src go1.24.0 errors/" |
| 19 | "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 20 | "osscip-go gomod github.com/golang/go/src go1.24.0 os/" |
| 21 | |
| 22 | "github.com/google/pprof/internal/binutilsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/binutils`/" |
| 23 | "github.com/google/pprof/internal/pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/" |
| 24 | ) |
| 25 | |
| 26 | type sourcescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source# struct { |
| 27 | Sourcesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#Sources. []string |
| 28 | ExecNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#ExecName. string |
| 29 | BuildIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#BuildID. string |
| 30 | Basescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#Base. []string |
| 31 | DiffBasescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#DiffBase. bool |
| 32 | Normalizescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#Normalize. bool |
| 33 | |
| 34 | Secondsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#Seconds. int |
| 35 | Timeoutscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#Timeout. int |
| 36 | Symbolizescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#Symbolize. string |
| 37 | HTTPHostportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#HTTPHostport. string |
| 38 | HTTPDisableBrowserscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#HTTPDisableBrowser. bool |
| 39 | Commentscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#Comment. string |
| 40 | AllFramesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#AllFrames. bool |
| 41 | } |
| 42 | |
| 43 | // parseFlags parses the command lines through the specified flags package |
| 44 | // and returns the source of the profile and optionally the command |
| 45 | // for the kind of report to generate (nil for interactive use). |
| 46 | func parseFlagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/parseFlags().(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#) (*sourcescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#, []string, error) { |
| 47 | flag := o.Flagsetscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#Flagset. |
| 48 | // Comparisons. |
| 49 | flagDiffBase := flag.StringListscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#StringList.("diff_base", "", "Source of base profile for comparison") |
| 50 | flagBase := flag.StringListscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#StringList.("base", "", "Source of base profile for profile subtraction") |
| 51 | // Source options. |
| 52 | flagSymbolize := flag.Stringscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#String.("symbolize", "", "Options for profile symbolization") |
| 53 | flagBuildID := flag.Stringscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#String.("buildid", "", "Override build id for first mapping") |
| 54 | flagTimeout := flag.Intscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#Int.("timeout", -1, "Timeout in seconds for fetching a profile") |
| 55 | flagAddComment := flag.Stringscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#String.("add_comment", "", "Free-form annotation to add to the profile") |
| 56 | flagAllFrames := flag.Boolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#Bool.("all_frames", false, "Ignore drop_frames and keep_frames regexps") |
| 57 | // CPU profile options |
| 58 | flagSeconds := flag.Intscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#Int.("seconds", -1, "Length of time for dynamic profiles") |
| 59 | // Heap profile options |
| 60 | flagInUseSpace := flag.Boolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#Bool.("inuse_space", false, "Display in-use memory size") |
| 61 | flagInUseObjects := flag.Boolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#Bool.("inuse_objects", false, "Display in-use object counts") |
| 62 | flagAllocSpace := flag.Boolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#Bool.("alloc_space", false, "Display allocated memory size") |
| 63 | flagAllocObjects := flag.Boolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#Bool.("alloc_objects", false, "Display allocated object counts") |
| 64 | // Contention profile options |
| 65 | flagTotalDelay := flag.Boolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#Bool.("total_delay", false, "Display total delay at each region") |
| 66 | flagContentions := flag.Boolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#Bool.("contentions", false, "Display number of delays at each region") |
| 67 | flagMeanDelay := flag.Boolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#Bool.("mean_delay", false, "Display mean delay at each region") |
| 68 | flagTools := flag.Stringscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#String.("tools", osscip-go gomod github.com/golang/go/src go1.24.0 os/.Getenvscip-go gomod github.com/golang/go/src go1.24.0 os/Getenv().("PPROF_TOOLS"), "Path for object tool pathnames") |
| 69 | |
| 70 | flagHTTP := flag.Stringscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#String.("http", "", "Present interactive web UI at the specified http host:port") |
| 71 | flagNoBrowser := flag.Boolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#Bool.("no_browser", false, "Skip opening a browser for the interactive web UI") |
| 72 | |
| 73 | // Flags that set configuration properties. |
| 74 | cfg := currentConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/currentConfig().() |
| 75 | configFlagSetter := installConfigFlagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/installConfigFlags().(flag, &cfg) |
| 76 | |
| 77 | flagCommands := make(map[string]*bool) |
| 78 | flagParamCommands := make(map[string]*string) |
| 79 | for name, cmd := range pprofCommandsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/pprofCommands. { |
| 80 | if cmd.hasParamscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/command#hasParam. { |
| 81 | flagParamCommands[name] = flag.Stringscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#String.(name, "", "Generate a report in "+name+" format, matching regexp") |
| 82 | } else { |
| 83 | flagCommands[name] = flag.Boolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#Bool.(name, false, "Generate a report in "+name+" format") |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | args := flag.Parsescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#Parse.(func() { |
| 88 | o.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI..Printscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#Print.(usageMsgHdrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/usageMsgHdr. + |
| 89 | usagescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/usage().(true) + |
| 90 | usageMsgSrcscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/usageMsgSrc. + |
| 91 | flag.ExtraUsagescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#ExtraUsage.() + |
| 92 | usageMsgVarsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/usageMsgVars.) |
| 93 | }) |
| 94 | if len(args) == 0 { |
| 95 | return nil, nil, errorsscip-go gomod github.com/golang/go/src go1.24.0 errors/.Newscip-go gomod github.com/golang/go/src go1.24.0 errors/New().("no profile source specified") |
| 96 | } |
| 97 | |
| 98 | var execName string |
| 99 | // Recognize first argument as an executable or buildid override. |
| 100 | if len(args) > 1 { |
| 101 | arg0 := args[0] |
| 102 | if file, err := o.Objscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#Obj..Openscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/ObjTool#Open.(arg0, 0, ^uint64(0), 0, ""); err == nil { |
| 103 | file.Closescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/ObjFile#Close.() |
| 104 | execName = arg0 |
| 105 | args = args[1:] |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | // Apply any specified flags to cfg. |
| 110 | if err := configFlagSetter(); err != nil { |
| 111 | return nil, nil, err |
| 112 | } |
| 113 | |
| 114 | cmd, err := outputFormatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/outputFormat().(flagCommands, flagParamCommands) |
| 115 | if err != nil { |
| 116 | return nil, nil, err |
| 117 | } |
| 118 | if cmd != nil && *flagHTTP != "" { |
| 119 | return nil, nil, errorsscip-go gomod github.com/golang/go/src go1.24.0 errors/.Newscip-go gomod github.com/golang/go/src go1.24.0 errors/New().("-http is not compatible with an output format on the command line") |
| 120 | } |
| 121 | |
| 122 | if *flagNoBrowser && *flagHTTP == "" { |
| 123 | return nil, nil, errorsscip-go gomod github.com/golang/go/src go1.24.0 errors/.Newscip-go gomod github.com/golang/go/src go1.24.0 errors/New().("-no_browser only makes sense with -http") |
| 124 | } |
| 125 | |
| 126 | si := cfg.SampleIndexscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#SampleIndex. |
| 127 | si = sampleIndexscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/sampleIndex().(flagTotalDelay, si, "delay", "-total_delay", o.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI.) |
| 128 | si = sampleIndexscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/sampleIndex().(flagMeanDelay, si, "delay", "-mean_delay", o.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI.) |
| 129 | si = sampleIndexscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/sampleIndex().(flagContentions, si, "contentions", "-contentions", o.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI.) |
| 130 | si = sampleIndexscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/sampleIndex().(flagInUseSpace, si, "inuse_space", "-inuse_space", o.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI.) |
| 131 | si = sampleIndexscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/sampleIndex().(flagInUseObjects, si, "inuse_objects", "-inuse_objects", o.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI.) |
| 132 | si = sampleIndexscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/sampleIndex().(flagAllocSpace, si, "alloc_space", "-alloc_space", o.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI.) |
| 133 | si = sampleIndexscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/sampleIndex().(flagAllocObjects, si, "alloc_objects", "-alloc_objects", o.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI.) |
| 134 | cfg.SampleIndexscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#SampleIndex. = si |
| 135 | |
| 136 | if *flagMeanDelay { |
| 137 | cfg.Meanscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Mean. = true |
| 138 | } |
| 139 | |
| 140 | source := &sourcescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#{ |
| 141 | Sourcesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#Sources.: args, |
| 142 | ExecNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#ExecName.: execName, |
| 143 | BuildIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#BuildID.: *flagBuildID, |
| 144 | Secondsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#Seconds.: *flagSeconds, |
| 145 | Timeoutscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#Timeout.: *flagTimeout, |
| 146 | Symbolizescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#Symbolize.: *flagSymbolize, |
| 147 | HTTPHostportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#HTTPHostport.: *flagHTTP, |
| 148 | HTTPDisableBrowserscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#HTTPDisableBrowser.: *flagNoBrowser, |
| 149 | Commentscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#Comment.: *flagAddComment, |
| 150 | AllFramesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#AllFrames.: *flagAllFrames, |
| 151 | } |
| 152 | |
| 153 | if err := source.addBaseProfilesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#addBaseProfiles().(*flagBase, *flagDiffBase); err != nil { |
| 154 | return nil, nil, err |
| 155 | } |
| 156 | |
| 157 | normalize := cfg.Normalizescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Normalize. |
| 158 | if normalize && len(source.Basescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#Base.) == 0 { |
| 159 | return nil, nil, errorsscip-go gomod github.com/golang/go/src go1.24.0 errors/.Newscip-go gomod github.com/golang/go/src go1.24.0 errors/New().("must have base profile to normalize by") |
| 160 | } |
| 161 | source.Normalizescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#Normalize. = normalize |
| 162 | |
| 163 | if bu, ok := o.Objscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#Obj..(*binutilsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/binutils`/.Binutilsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/binutils`/Binutils#); ok { |
| 164 | bu.SetToolsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/binutils`/Binutils#SetTools().(*flagTools) |
| 165 | } |
| 166 | |
| 167 | setCurrentConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/setCurrentConfig().(cfg) |
| 168 | return source, cmd, nil |
| 169 | } |
| 170 | |
| 171 | // addBaseProfiles adds the list of base profiles or diff base profiles to |
| 172 | // the source. This function will return an error if both base and diff base |
| 173 | // profiles are specified. |
| 174 | func (source *sourcescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#) addBaseProfilesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#addBaseProfiles().(flagBase, flagDiffBase []*string) error { |
| 175 | base, diffBase := dropEmptyscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/dropEmpty().(flagBase), dropEmptyscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/dropEmpty().(flagDiffBase) |
| 176 | if len(base) > 0 && len(diffBase) > 0 { |
| 177 | return errorsscip-go gomod github.com/golang/go/src go1.24.0 errors/.Newscip-go gomod github.com/golang/go/src go1.24.0 errors/New().("-base and -diff_base flags cannot both be specified") |
| 178 | } |
| 179 | |
| 180 | source.Basescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#Base. = base |
| 181 | if len(diffBase) > 0 { |
| 182 | source.Basescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#Base., source.DiffBasescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/source#DiffBase. = diffBase, true |
| 183 | } |
| 184 | return nil |
| 185 | } |
| 186 | |
| 187 | // dropEmpty list takes a slice of string pointers, and outputs a slice of |
| 188 | // non-empty strings associated with the flag. |
| 189 | func dropEmptyscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/dropEmpty().(list []*string) []string { |
| 190 | var l []string |
| 191 | for _, s := range list { |
| 192 | if *s != "" { |
| 193 | l = append(l, *s) |
| 194 | } |
| 195 | } |
| 196 | return l |
| 197 | } |
| 198 | |
| 199 | // installConfigFlags creates command line flags for configuration |
| 200 | // fields and returns a function which can be called after flags have |
| 201 | // been parsed to copy any flags specified on the command line to |
| 202 | // *cfg. |
| 203 | func installConfigFlagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/installConfigFlags().(flag pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.FlagSetscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#, cfg *configscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#) func() error { |
| 204 | // List of functions for setting the different parts of a config. |
| 205 | var setters []func() |
| 206 | var err error // Holds any errors encountered while running setters. |
| 207 | |
| 208 | for _, field := range configFieldsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configFields. { |
| 209 | n := field.namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#name. |
| 210 | help := configHelpscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configHelp.[n] |
| 211 | var setter func() |
| 212 | switch ptr := cfg.fieldPtrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#fieldPtr().(field).(type) { |
| 213 | case *bool: |
| 214 | f := flag.Boolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#Bool.(n, *ptr, help) |
| 215 | setter = func() { *ptr = *f } |
| 216 | case *int: |
| 217 | f := flag.Intscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#Int.(n, *ptr, help) |
| 218 | setter = func() { *ptr = *f } |
| 219 | case *float64: |
| 220 | f := flag.Float64scip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#Float64.(n, *ptr, help) |
| 221 | setter = func() { *ptr = *f } |
| 222 | case *string: |
| 223 | if len(field.choicesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#choices.) == 0 { |
| 224 | f := flag.Stringscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#String.(n, *ptr, help) |
| 225 | setter = func() { *ptr = *f } |
| 226 | } else { |
| 227 | // Make a separate flag per possible choice. |
| 228 | // Set all flags to initially false so we can |
| 229 | // identify conflicts. |
| 230 | bools := make(map[string]*bool) |
| 231 | for _, choice := range field.choicesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#choices. { |
| 232 | bools[choice] = flag.Boolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/FlagSet#Bool.(choice, false, configHelpscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configHelp.[choice]) |
| 233 | } |
| 234 | setter = func() { |
| 235 | var set []string |
| 236 | for k, v := range bools { |
| 237 | if *v { |
| 238 | set = append(set, k) |
| 239 | } |
| 240 | } |
| 241 | switch len(set) { |
| 242 | case 0: |
| 243 | // Leave as default value. |
| 244 | case 1: |
| 245 | *ptr = set[0] |
| 246 | default: |
| 247 | err = 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().("conflicting options set: %v", set) |
| 248 | } |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | setters = append(setters, setter) |
| 253 | } |
| 254 | |
| 255 | return func() error { |
| 256 | // Apply the setter for every flag. |
| 257 | for _, setter := range setters { |
| 258 | setter() |
| 259 | if err != nil { |
| 260 | return err |
| 261 | } |
| 262 | } |
| 263 | return nil |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | func sampleIndexscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/sampleIndex().(flag *bool, si string, sampleType, option string, 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#) string { |
| 268 | if *flag { |
| 269 | if si == "" { |
| 270 | return sampleType |
| 271 | } |
| 272 | ui.PrintErrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#PrintErr.("Multiple value selections, ignoring ", option) |
| 273 | } |
| 274 | return si |
| 275 | } |
| 276 | |
| 277 | func outputFormatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/outputFormat().(bcmd map[string]*bool, acmd map[string]*string) (cmd []string, err error) { |
| 278 | for n, b := range bcmd { |
| 279 | if *b { |
| 280 | if cmd != nil { |
| 281 | return nil, errorsscip-go gomod github.com/golang/go/src go1.24.0 errors/.Newscip-go gomod github.com/golang/go/src go1.24.0 errors/New().("must set at most one output format") |
| 282 | } |
| 283 | cmd = []string{n} |
| 284 | } |
| 285 | } |
| 286 | for n, s := range acmd { |
| 287 | if *s != "" { |
| 288 | if cmd != nil { |
| 289 | return nil, errorsscip-go gomod github.com/golang/go/src go1.24.0 errors/.Newscip-go gomod github.com/golang/go/src go1.24.0 errors/New().("must set at most one output format") |
| 290 | } |
| 291 | cmd = []string{n, *s} |
| 292 | } |
| 293 | } |
| 294 | return cmd, nil |
| 295 | } |
| 296 | |
| 297 | var usageMsgHdrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/usageMsgHdr. = `usage: |
| 298 | |
| 299 | Produce output in the specified format. |
| 300 | |
| 301 | pprof <format> [options] [binary] <source> ... |
| 302 | |
| 303 | Omit the format to get an interactive shell whose commands can be used |
| 304 | to generate various views of a profile |
| 305 | |
| 306 | pprof [options] [binary] <source> ... |
| 307 | |
| 308 | Omit the format and provide the "-http" flag to get an interactive web |
| 309 | interface at the specified host:port that can be used to navigate through |
| 310 | various views of a profile. |
| 311 | |
| 312 | pprof -http [host]:[port] [options] [binary] <source> ... |
| 313 | |
| 314 | Details: |
| 315 | ` |
| 316 | |
| 317 | var usageMsgSrcscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/usageMsgSrc. = "\n\n" + |
| 318 | " Source options:\n" + |
| 319 | " -seconds Duration for time-based profile collection\n" + |
| 320 | " -timeout Timeout in seconds for profile collection\n" + |
| 321 | " -buildid Override build id for main binary\n" + |
| 322 | " -add_comment Free-form annotation to add to the profile\n" + |
| 323 | " Displayed on some reports or with pprof -comments\n" + |
| 324 | " -diff_base source Source of base profile for comparison\n" + |
| 325 | " -base source Source of base profile for profile subtraction\n" + |
| 326 | " profile.pb.gz Profile in compressed protobuf format\n" + |
| 327 | " legacy_profile Profile in legacy pprof format\n" + |
| 328 | " http://host/profile URL for profile handler to retrieve\n" + |
| 329 | " -symbolize= Controls source of symbol information\n" + |
| 330 | " none Do not attempt symbolization\n" + |
| 331 | " local Examine only local binaries\n" + |
| 332 | " fastlocal Only get function names from local binaries\n" + |
| 333 | " remote Do not examine local binaries\n" + |
| 334 | " force Force re-symbolization\n" + |
| 335 | " Binary Local path or build id of binary for symbolization\n" |
| 336 | |
| 337 | var usageMsgVarsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/usageMsgVars. = "\n\n" + |
| 338 | " Misc options:\n" + |
| 339 | " -http Provide web interface at host:port.\n" + |
| 340 | " Host is optional and 'localhost' by default.\n" + |
| 341 | " Port is optional and a randomly available port by default.\n" + |
| 342 | " -no_browser Skip opening a browser for the interactive web UI.\n" + |
| 343 | " -tools Search path for object tools\n" + |
| 344 | " -all_frames Ignore drop_frames and keep_frames regexps in the profile\n" + |
| 345 | " Rarely needed, mainly used for debugging pprof itself\n" + |
| 346 | "\n" + |
| 347 | " Legacy convenience options:\n" + |
| 348 | " -inuse_space Same as -sample_index=inuse_space\n" + |
| 349 | " -inuse_objects Same as -sample_index=inuse_objects\n" + |
| 350 | " -alloc_space Same as -sample_index=alloc_space\n" + |
| 351 | " -alloc_objects Same as -sample_index=alloc_objects\n" + |
| 352 | " -total_delay Same as -sample_index=delay\n" + |
| 353 | " -contentions Same as -sample_index=contentions\n" + |
| 354 | " -mean_delay Same as -mean -sample_index=delay\n" + |
| 355 | "\n" + |
| 356 | " Environment Variables:\n" + |
| 357 | " PPROF_TMPDIR Location for saved profiles (default $HOME/pprof)\n" + |
| 358 | " PPROF_TOOLS Search path for object-level tools\n" + |
| 359 | " PPROF_BINARY_PATH Search path for local binary files\n" + |
| 360 | " default: $HOME/pprof/binaries\n" + |
| 361 | " searches $buildid/$name, $buildid/*, $path/$buildid,\n" + |
| 362 | " ${buildid:0:2}/${buildid:2}.debug, $name, $path,\n" + |
| 363 | " ${name}.debug, $dir/.debug/${name}.debug,\n" + |
| 364 | " usr/lib/debug/$dir/${name}.debug\n" + |
| 365 | " * On Windows, %USERPROFILE% is used instead of $HOME" |