| 1 | package driverscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/ |
| 2 | |
| 3 | import ( |
| 4 | "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 5 | "net/urlscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/" |
| 6 | "reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/" |
| 7 | "slicesscip-go gomod github.com/golang/go/src go1.24.0 slices/" |
| 8 | "strconvscip-go gomod github.com/golang/go/src go1.24.0 strconv/" |
| 9 | "stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/" |
| 10 | "syncscip-go gomod github.com/golang/go/src go1.24.0 sync/" |
| 11 | ) |
| 12 | |
| 13 | // config holds settings for a single named config. |
| 14 | // The JSON tag name for a field is used both for JSON encoding and as |
| 15 | // a named variable. |
| 16 | type configscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config# struct { |
| 17 | // Filename for file-based output formats, stdout by default. |
| 18 | Outputscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Output. string `json:"-"` |
| 19 | |
| 20 | // Display options. |
| 21 | CallTreescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#CallTree. bool `json:"call_tree,omitempty"` |
| 22 | RelativePercentagesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#RelativePercentages. bool `json:"relative_percentages,omitempty"` |
| 23 | Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Unit. string `json:"unit,omitempty"` |
| 24 | CompactLabelsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#CompactLabels. bool `json:"compact_labels,omitempty"` |
| 25 | SourcePathscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#SourcePath. string `json:"-"` |
| 26 | TrimPathscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#TrimPath. string `json:"-"` |
| 27 | IntelSyntaxscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#IntelSyntax. bool `json:"intel_syntax,omitempty"` |
| 28 | Meanscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Mean. bool `json:"mean,omitempty"` |
| 29 | SampleIndexscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#SampleIndex. string `json:"-"` |
| 30 | DivideByscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#DivideBy. float64 `json:"-"` |
| 31 | Normalizescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Normalize. bool `json:"normalize,omitempty"` |
| 32 | Sortscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Sort. string `json:"sort,omitempty"` |
| 33 | |
| 34 | // Label pseudo stack frame generation options |
| 35 | TagRootscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#TagRoot. string `json:"tagroot,omitempty"` |
| 36 | TagLeafscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#TagLeaf. string `json:"tagleaf,omitempty"` |
| 37 | |
| 38 | // Filtering options |
| 39 | DropNegativescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#DropNegative. bool `json:"drop_negative,omitempty"` |
| 40 | NodeCountscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#NodeCount. int `json:"nodecount,omitempty"` |
| 41 | NodeFractionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#NodeFraction. float64 `json:"nodefraction,omitempty"` |
| 42 | EdgeFractionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#EdgeFraction. float64 `json:"edgefraction,omitempty"` |
| 43 | Trimscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Trim. bool `json:"trim,omitempty"` |
| 44 | Focusscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Focus. string `json:"focus,omitempty"` |
| 45 | Ignorescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Ignore. string `json:"ignore,omitempty"` |
| 46 | PruneFromscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#PruneFrom. string `json:"prune_from,omitempty"` |
| 47 | Hidescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Hide. string `json:"hide,omitempty"` |
| 48 | Showscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Show. string `json:"show,omitempty"` |
| 49 | ShowFromscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#ShowFrom. string `json:"show_from,omitempty"` |
| 50 | TagFocusscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#TagFocus. string `json:"tagfocus,omitempty"` |
| 51 | TagIgnorescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#TagIgnore. string `json:"tagignore,omitempty"` |
| 52 | TagShowscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#TagShow. string `json:"tagshow,omitempty"` |
| 53 | TagHidescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#TagHide. string `json:"taghide,omitempty"` |
| 54 | NoInlinesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#NoInlines. bool `json:"noinlines,omitempty"` |
| 55 | ShowColumnsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#ShowColumns. bool `json:"showcolumns,omitempty"` |
| 56 | |
| 57 | // Output granularity |
| 58 | Granularityscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Granularity. string `json:"granularity,omitempty"` |
| 59 | } |
| 60 | |
| 61 | // defaultConfig returns the default configuration values; it is unaffected by |
| 62 | // flags and interactive assignments. |
| 63 | func defaultConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/defaultConfig().() configscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config# { |
| 64 | return configscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#{ |
| 65 | Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Unit.: "minimum", |
| 66 | NodeCountscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#NodeCount.: -1, |
| 67 | NodeFractionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#NodeFraction.: 0.005, |
| 68 | EdgeFractionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#EdgeFraction.: 0.001, |
| 69 | Trimscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Trim.: true, |
| 70 | DivideByscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#DivideBy.: 1.0, |
| 71 | Sortscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Sort.: "flat", |
| 72 | Granularityscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Granularity.: "", // Default depends on the display format |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | // currentConfig holds the current configuration values; it is affected by |
| 77 | // flags and interactive assignments. |
| 78 | var currentCfgscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/currentCfg. = defaultConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/defaultConfig().() |
| 79 | var currentMuscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/currentMu. syncscip-go gomod github.com/golang/go/src go1.24.0 sync/.Mutexscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex# |
| 80 | |
| 81 | func currentConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/currentConfig().() configscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config# { |
| 82 | currentMuscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/currentMu..Lockscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex#Lock().() |
| 83 | defer currentMuscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/currentMu..Unlockscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex#Unlock().() |
| 84 | return currentCfgscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/currentCfg. |
| 85 | } |
| 86 | |
| 87 | func setCurrentConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/setCurrentConfig().(cfg configscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#) { |
| 88 | currentMuscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/currentMu..Lockscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex#Lock().() |
| 89 | defer currentMuscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/currentMu..Unlockscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex#Unlock().() |
| 90 | currentCfgscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/currentCfg. = cfg |
| 91 | } |
| 92 | |
| 93 | // configField contains metadata for a single configuration field. |
| 94 | type configFieldscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField# struct { |
| 95 | namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#name. string // JSON field name/key in variables |
| 96 | urlparamscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#urlparam. string // URL parameter name |
| 97 | savedscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#saved. bool // Is field saved in settings? |
| 98 | fieldscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#field. reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/.StructFieldscip-go gomod github.com/golang/go/src go1.24.0 reflect/StructField# // Field in config |
| 99 | choicesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#choices. []string // Name Of variables in group |
| 100 | defaultValuescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#defaultValue. string // Default value for this field. |
| 101 | } |
| 102 | |
| 103 | var ( |
| 104 | configFieldsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configFields. []configFieldscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField# // Precomputed metadata per config field |
| 105 | |
| 106 | // configFieldMap holds an entry for every config field as well as an |
| 107 | // entry for every valid choice for a multi-choice field. |
| 108 | configFieldMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configFieldMap. map[string]configFieldscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField# |
| 109 | ) |
| 110 | |
| 111 | func initscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/init().() { |
| 112 | // Config names for fields that are not saved in settings and therefore |
| 113 | // do not have a JSON name. |
| 114 | notSaved := map[string]string{ |
| 115 | // Not saved in settings, but present in URLs. |
| 116 | "SampleIndex": "sample_index", |
| 117 | |
| 118 | // Following fields are also not placed in URLs. |
| 119 | "Output": "output", |
| 120 | "SourcePath": "source_path", |
| 121 | "TrimPath": "trim_path", |
| 122 | "DivideBy": "divide_by", |
| 123 | } |
| 124 | |
| 125 | // choices holds the list of allowed values for config fields that can |
| 126 | // take on one of a bounded set of values. |
| 127 | choices := map[string][]string{ |
| 128 | "sort": {"cum", "flat"}, |
| 129 | "granularity": {"functions", "filefunctions", "files", "lines", "addresses"}, |
| 130 | } |
| 131 | |
| 132 | // urlparam holds the mapping from a config field name to the URL |
| 133 | // parameter used to hold that config field. If no entry is present for |
| 134 | // a name, the corresponding field is not saved in URLs. |
| 135 | urlparam := map[string]string{ |
| 136 | "drop_negative": "dropneg", |
| 137 | "call_tree": "calltree", |
| 138 | "relative_percentages": "rel", |
| 139 | "unit": "unit", |
| 140 | "compact_labels": "compact", |
| 141 | "intel_syntax": "intel", |
| 142 | "nodecount": "n", |
| 143 | "nodefraction": "nf", |
| 144 | "edgefraction": "ef", |
| 145 | "trim": "trim", |
| 146 | "focus": "f", |
| 147 | "ignore": "i", |
| 148 | "prune_from": "prunefrom", |
| 149 | "hide": "h", |
| 150 | "show": "s", |
| 151 | "show_from": "sf", |
| 152 | "tagfocus": "tf", |
| 153 | "tagignore": "ti", |
| 154 | "tagshow": "ts", |
| 155 | "taghide": "th", |
| 156 | "mean": "mean", |
| 157 | "sample_index": "si", |
| 158 | "normalize": "norm", |
| 159 | "sort": "sort", |
| 160 | "granularity": "g", |
| 161 | "noinlines": "noinlines", |
| 162 | "showcolumns": "showcolumns", |
| 163 | } |
| 164 | |
| 165 | def := defaultConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/defaultConfig().() |
| 166 | configFieldMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configFieldMap. = map[string]configFieldscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#{} |
| 167 | t := reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/.TypeForscip-go gomod github.com/golang/go/src go1.24.0 reflect/TypeFor().[configscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#]() |
| 168 | for i, n := 0, t.NumFieldscip-go gomod github.com/golang/go/src go1.24.0 reflect/Type#NumField().(); i < n; i++ { |
| 169 | field := t.Fieldscip-go gomod github.com/golang/go/src go1.24.0 reflect/Type#Field().(i) |
| 170 | js := 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().(field.Tagscip-go gomod github.com/golang/go/src go1.24.0 reflect/StructField#Tag..Getscip-go gomod github.com/golang/go/src go1.24.0 reflect/StructTag#Get().("json"), ",") |
| 171 | if len(js) == 0 { |
| 172 | continue |
| 173 | } |
| 174 | // Get the configuration name for this field. |
| 175 | name := js[0] |
| 176 | if name == "-" { |
| 177 | name = notSaved[field.Namescip-go gomod github.com/golang/go/src go1.24.0 reflect/StructField#Name.] |
| 178 | if name == "" { |
| 179 | // Not a configurable field. |
| 180 | continue |
| 181 | } |
| 182 | } |
| 183 | f := configFieldscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#{ |
| 184 | namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#name.: name, |
| 185 | urlparamscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#urlparam.: urlparam[name], |
| 186 | savedscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#saved.: (name == js[0]), |
| 187 | fieldscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#field.: field, |
| 188 | choicesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#choices.: choices[name], |
| 189 | } |
| 190 | f.defaultValuescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#defaultValue. = def.getscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#get().(f) |
| 191 | configFieldsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configFields. = append(configFieldsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configFields., f) |
| 192 | configFieldMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configFieldMap.[f.namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#name.] = f |
| 193 | for _, choice := range f.choicesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#choices. { |
| 194 | configFieldMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configFieldMap.[choice] = f |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | // fieldPtr returns a pointer to the field identified by f in *cfg. |
| 200 | func (cfg *configscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#) fieldPtrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#fieldPtr().(f configFieldscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#) interface{} { |
| 201 | // reflect.ValueOf: converts to reflect.Value |
| 202 | // Elem: dereferences cfg to make *cfg |
| 203 | // FieldByIndex: fetches the field |
| 204 | // Addr: takes address of field |
| 205 | // Interface: converts back from reflect.Value to a regular value |
| 206 | return reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.24.0 reflect/ValueOf().(cfg).Elemscip-go gomod github.com/golang/go/src go1.24.0 reflect/Value#Elem().().FieldByIndexscip-go gomod github.com/golang/go/src go1.24.0 reflect/Value#FieldByIndex().(f.fieldscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#field..Indexscip-go gomod github.com/golang/go/src go1.24.0 reflect/StructField#Index.).Addrscip-go gomod github.com/golang/go/src go1.24.0 reflect/Value#Addr().().Interfacescip-go gomod github.com/golang/go/src go1.24.0 reflect/Value#Interface().() |
| 207 | } |
| 208 | |
| 209 | // get returns the value of field f in cfg. |
| 210 | func (cfg *configscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#) getscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#get().(f configFieldscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#) string { |
| 211 | switch ptr := cfg.fieldPtrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#fieldPtr().(f).(type) { |
| 212 | case *string: |
| 213 | return *ptr |
| 214 | case *int: |
| 215 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprint().(*ptr) |
| 216 | case *float64: |
| 217 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprint().(*ptr) |
| 218 | case *bool: |
| 219 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprint().(*ptr) |
| 220 | } |
| 221 | panic(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().("unsupported config field type %v", f.fieldscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#field..Typescip-go gomod github.com/golang/go/src go1.24.0 reflect/StructField#Type.)) |
| 222 | } |
| 223 | |
| 224 | // set sets the value of field f in cfg to value. |
| 225 | func (cfg *configscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#) setscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#set().(f configFieldscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#, value string) error { |
| 226 | switch ptr := cfg.fieldPtrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#fieldPtr().(f).(type) { |
| 227 | case *string: |
| 228 | if len(f.choicesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#choices.) > 0 { |
| 229 | // Verify that value is one of the allowed choices. |
| 230 | if slicesscip-go gomod github.com/golang/go/src go1.24.0 slices/.Containsscip-go gomod github.com/golang/go/src go1.24.0 slices/Contains().(f.choicesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#choices., value) { |
| 231 | *ptr = value |
| 232 | return nil |
| 233 | } |
| 234 | 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().("invalid %q value %q", f.namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#name., value) |
| 235 | } |
| 236 | *ptr = value |
| 237 | case *int: |
| 238 | v, err := strconvscip-go gomod github.com/golang/go/src go1.24.0 strconv/.Atoiscip-go gomod github.com/golang/go/src go1.24.0 strconv/Atoi().(value) |
| 239 | if err != nil { |
| 240 | return err |
| 241 | } |
| 242 | *ptr = v |
| 243 | case *float64: |
| 244 | v, err := strconvscip-go gomod github.com/golang/go/src go1.24.0 strconv/.ParseFloatscip-go gomod github.com/golang/go/src go1.24.0 strconv/ParseFloat().(value, 64) |
| 245 | if err != nil { |
| 246 | return err |
| 247 | } |
| 248 | *ptr = v |
| 249 | case *bool: |
| 250 | v, err := stringToBoolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/stringToBool().(value) |
| 251 | if err != nil { |
| 252 | return err |
| 253 | } |
| 254 | *ptr = v |
| 255 | default: |
| 256 | panic(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().("unsupported config field type %v", f.fieldscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#field..Typescip-go gomod github.com/golang/go/src go1.24.0 reflect/StructField#Type.)) |
| 257 | } |
| 258 | return nil |
| 259 | } |
| 260 | |
| 261 | // isConfigurable returns true if name is either the name of a config field, or |
| 262 | // a valid value for a multi-choice config field. |
| 263 | func isConfigurablescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/isConfigurable().(name string) bool { |
| 264 | _, ok := configFieldMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configFieldMap.[name] |
| 265 | return ok |
| 266 | } |
| 267 | |
| 268 | // isBoolConfig returns true if name is either name of a boolean config field, |
| 269 | // or a valid value for a multi-choice config field. |
| 270 | func isBoolConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/isBoolConfig().(name string) bool { |
| 271 | f, ok := configFieldMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configFieldMap.[name] |
| 272 | if !ok { |
| 273 | return false |
| 274 | } |
| 275 | if name != f.namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#name. { |
| 276 | return true // name must be one possible value for the field |
| 277 | } |
| 278 | var cfg configscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config# |
| 279 | _, ok = cfg.fieldPtrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#fieldPtr().(f).(*bool) |
| 280 | return ok |
| 281 | } |
| 282 | |
| 283 | // completeConfig returns the list of configurable names starting with prefix. |
| 284 | func completeConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/completeConfig().(prefix string) []string { |
| 285 | var result []string |
| 286 | for v := range configFieldMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configFieldMap. { |
| 287 | 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().(v, prefix) { |
| 288 | result = append(result, v) |
| 289 | } |
| 290 | } |
| 291 | return result |
| 292 | } |
| 293 | |
| 294 | // configure stores the name=value mapping into the current config, correctly |
| 295 | // handling the case when name identifies a particular choice in a field. |
| 296 | func configurescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configure().(name, value string) error { |
| 297 | currentMuscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/currentMu..Lockscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex#Lock().() |
| 298 | defer currentMuscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/currentMu..Unlockscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex#Unlock().() |
| 299 | f, ok := configFieldMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configFieldMap.[name] |
| 300 | if !ok { |
| 301 | 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().("unknown config field %q", name) |
| 302 | } |
| 303 | if f.namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#name. == name { |
| 304 | return currentCfgscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/currentCfg..setscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#set().(f, value) |
| 305 | } |
| 306 | // name must be one of the choices. If value is true, set field-value |
| 307 | // to name. |
| 308 | if v, err := strconvscip-go gomod github.com/golang/go/src go1.24.0 strconv/.ParseBoolscip-go gomod github.com/golang/go/src go1.24.0 strconv/ParseBool().(value); v && err == nil { |
| 309 | return currentCfgscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/currentCfg..setscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#set().(f, name) |
| 310 | } |
| 311 | 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().("unknown config field %q", name) |
| 312 | } |
| 313 | |
| 314 | // resetTransient sets all transient fields in *cfg to their currently |
| 315 | // configured values. |
| 316 | func (cfg *configscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#) resetTransientscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#resetTransient().() { |
| 317 | current := currentConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/currentConfig().() |
| 318 | cfg.Outputscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Output. = current.Outputscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Output. |
| 319 | cfg.SourcePathscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#SourcePath. = current.SourcePathscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#SourcePath. |
| 320 | cfg.TrimPathscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#TrimPath. = current.TrimPathscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#TrimPath. |
| 321 | cfg.DivideByscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#DivideBy. = current.DivideByscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#DivideBy. |
| 322 | cfg.SampleIndexscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#SampleIndex. = current.SampleIndexscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#SampleIndex. |
| 323 | } |
| 324 | |
| 325 | // applyURL updates *cfg based on params. |
| 326 | func (cfg *configscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#) applyURLscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#applyURL().(params urlscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/.Valuesscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/Values#) error { |
| 327 | for _, f := range configFieldsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configFields. { |
| 328 | var value string |
| 329 | if f.urlparamscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#urlparam. != "" { |
| 330 | value = params.Getscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/Values#Get().(f.urlparamscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#urlparam.) |
| 331 | } |
| 332 | if value == "" { |
| 333 | continue |
| 334 | } |
| 335 | if err := cfg.setscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#set().(f, value); err != nil { |
| 336 | 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().("error setting config field %s: %v", f.namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#name., err) |
| 337 | } |
| 338 | } |
| 339 | return nil |
| 340 | } |
| 341 | |
| 342 | // makeURL returns a URL based on initialURL that contains the config contents |
| 343 | // as parameters. The second result is true iff a parameter value was changed. |
| 344 | func (cfg *configscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#) makeURLscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#makeURL().(initialURL urlscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/.URLscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/URL#) (urlscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/.URLscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/URL#, bool) { |
| 345 | q := initialURL.Queryscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/URL#Query().() |
| 346 | changed := false |
| 347 | for _, f := range configFieldsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configFields. { |
| 348 | if f.urlparamscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#urlparam. == "" || !f.savedscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#saved. { |
| 349 | continue |
| 350 | } |
| 351 | v := cfg.getscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#get().(f) |
| 352 | if v == f.defaultValuescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#defaultValue. { |
| 353 | v = "" // URL for of default value is the empty string. |
| 354 | } else if f.fieldscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#field..Typescip-go gomod github.com/golang/go/src go1.24.0 reflect/StructField#Type..Kindscip-go gomod github.com/golang/go/src go1.24.0 reflect/Type#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/.Boolscip-go gomod github.com/golang/go/src go1.24.0 reflect/Bool. { |
| 355 | // Shorten bool values to "f" or "t" |
| 356 | v = v[:1] |
| 357 | } |
| 358 | if q.Getscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/Values#Get().(f.urlparamscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#urlparam.) == v { |
| 359 | continue |
| 360 | } |
| 361 | changed = true |
| 362 | if v == "" { |
| 363 | q.Delscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/Values#Del().(f.urlparamscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#urlparam.) |
| 364 | } else { |
| 365 | q.Setscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/Values#Set().(f.urlparamscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configField#urlparam., v) |
| 366 | } |
| 367 | } |
| 368 | if changed { |
| 369 | initialURL.RawQueryscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/URL#RawQuery. = q.Encodescip-go gomod github.com/golang/go/src go1.24.0 `net/url`/Values#Encode().() |
| 370 | } |
| 371 | return initialURL, changed |
| 372 | } |