interactive starts a shell to read pprof commands.
(p *profile.Profile, o *plugin.Options)
| 32 | |
| 33 | // interactive starts a shell to read pprof commands. |
| 34 | func 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 | } |
searching dependent graphs…