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

Function parseCommandLine

internal/driver/interactive.go:223–307  ·  view source on GitHub ↗

parseCommandLine parses a command and returns the pprof command to execute and the configuration to use for the report.

(input []string)

Source from the content-addressed store, hash-verified

221// parseCommandLine parses a command and returns the pprof command to
222// execute and the configuration to use for the report.
223func parseCommandLine(input []string) ([]string, config, error) {
224 cmd, args := input[:1], input[1:]
225 name := cmd[0]
226
227 c := pprofCommands[name]
228 if c == nil {
229 // Attempt splitting digits on abbreviated commands (eg top10)
230 if d := tailDigitsRE.FindString(name); d != "" && d != name {
231 name = name[:len(name)-len(d)]
232 cmd[0], args = name, append([]string{d}, args...)
233 c = pprofCommands[name]
234 }
235 }
236 if c == nil {
237 if _, ok := configHelp[name]; ok {
238 value := "<val>"
239 if len(args) > 0 {
240 value = args[0]
241 }
242 return nil, config{}, fmt.Errorf("did you mean: %s=%s", name, value)
243 }
244 return nil, config{}, fmt.Errorf("unrecognized command: %q", name)
245 }
246
247 if c.hasParam {
248 if len(args) == 0 {
249 return nil, config{}, fmt.Errorf("command %s requires an argument", name)
250 }
251 cmd = append(cmd, args[0])
252 args = args[1:]
253 }
254
255 // Copy config since options set in the command line should not persist.
256 vcopy := currentConfig()
257
258 var focus, ignore string
259 for i := 0; i < len(args); i++ {
260 t := args[i]
261 if n, err := strconv.ParseInt(t, 10, 32); err == nil {
262 vcopy.NodeCount = int(n)
263 continue
264 }
265 switch t[0] {
266 case '>':
267 outputFile := t[1:]
268 if outputFile == "" {
269 i++
270 if i >= len(args) {
271 return nil, config{}, fmt.Errorf("unexpected end of line after >")
272 }
273 outputFile = args[i]
274 }
275 vcopy.Output = outputFile
276 case '-':
277 if t == "--cum" || t == "-cum" {
278 vcopy.Sort = "cum"
279 continue
280 }

Callers 2

TestInteractiveCommandsFunction · 0.85
interactiveFunction · 0.85

Calls 2

currentConfigFunction · 0.85
catRegexFunction · 0.85

Tested by 1

TestInteractiveCommandsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…