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

Function interactive

internal/driver/interactive.go:34–122  ·  view source on GitHub ↗

interactive starts a shell to read pprof commands.

(p *profile.Profile, o *plugin.Options)

Source from the content-addressed store, hash-verified

32
33// interactive starts a shell to read pprof commands.
34func interactive(p *profile.Profile, o *plugin.Options) error {
35 // Enter command processing loop.
36 o.UI.SetAutoComplete(newCompleter(functionNames(p)))
37 configure("compact_labels", "true")
38 configHelp["sample_index"] += fmt.Sprintf("Or use sample_index=name, with name in %v.\n", sampleTypes(p))
39
40 // Do not wait for the visualizer to complete, to allow multiple
41 // graphs to be visualized simultaneously.
42 interactiveMode = true
43 shortcuts := profileShortcuts(p)
44
45 copier := makeProfileCopier(p)
46 greetings(p, o.UI)
47 for {
48 input, err := o.UI.ReadLine("(pprof) ")
49 if err != nil {
50 if err != io.EOF {
51 return err
52 }
53 if input == "" {
54 return nil
55 }
56 }
57
58 for _, input := range shortcuts.expand(input) {
59 // Process assignments of the form variable=value
60 if s := strings.SplitN(input, "=", 2); len(s) > 0 {
61 name := strings.TrimSpace(s[0])
62 var value string
63 if len(s) == 2 {
64 value = s[1]
65 if comment := strings.LastIndex(value, commentStart); comment != -1 {
66 value = value[:comment]
67 }
68 value = strings.TrimSpace(value)
69 }
70 if isConfigurable(name) {
71 // All non-bool options require inputs
72 if len(s) == 1 && !isBoolConfig(name) {
73 o.UI.PrintErr(fmt.Errorf("please specify a value, e.g. %s=<val>", name))
74 continue
75 }
76 if name == "sample_index" {
77 // Error check sample_index=xxx to ensure xxx is a valid sample type.
78 index, err := p.SampleIndexByName(value)
79 if err != nil {
80 o.UI.PrintErr(err)
81 continue
82 }
83 if index < 0 || index >= len(p.SampleType) {
84 o.UI.PrintErr(fmt.Errorf("invalid sample_index %q", value))
85 continue
86 }
87 value = p.SampleType[index].Type
88 }
89 if err := configure(name, value); err != nil {
90 o.UI.PrintErr(err)
91 }

Callers 2

TestShellFunction · 0.85
PProfFunction · 0.85

Calls 15

newCompleterFunction · 0.85
functionNamesFunction · 0.85
configureFunction · 0.85
profileShortcutsFunction · 0.85
makeProfileCopierFunction · 0.85
greetingsFunction · 0.85
isConfigurableFunction · 0.85
isBoolConfigFunction · 0.85
printCurrentOptionsFunction · 0.85
commandHelpFunction · 0.85
parseCommandLineFunction · 0.85
expandMethod · 0.80

Tested by 1

TestShellFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…