| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | package driver |
| |
|
| | import ( |
| | "bufio" |
| | "fmt" |
| | "io" |
| | "os" |
| | "strings" |
| |
|
| | "github.com/google/pprof/internal/binutils" |
| | "github.com/google/pprof/internal/plugin" |
| | "github.com/google/pprof/internal/symbolizer" |
| | "github.com/google/pprof/internal/transport" |
| | ) |
| |
|
| | |
| | |
| | func setDefaults(o *plugin.Options) *plugin.Options { |
| | d := &plugin.Options{} |
| | if o != nil { |
| | *d = *o |
| | } |
| | if d.Writer == nil { |
| | d.Writer = oswriter{} |
| | } |
| | if d.Flagset == nil { |
| | d.Flagset = &GoFlags{} |
| | } |
| | if d.Obj == nil { |
| | d.Obj = &binutils.Binutils{} |
| | } |
| | if d.UI == nil { |
| | d.UI = &stdUI{r: bufio.NewReader(os.Stdin)} |
| | } |
| | if d.HTTPTransport == nil { |
| | d.HTTPTransport = transport.New(d.Flagset) |
| | } |
| | if d.Sym == nil { |
| | d.Sym = &symbolizer.Symbolizer{Obj: d.Obj, UI: d.UI, Transport: d.HTTPTransport} |
| | } |
| | return d |
| | } |
| |
|
| | type stdUI struct { |
| | r *bufio.Reader |
| | } |
| |
|
| | func (ui *stdUI) ReadLine(prompt string) (string, error) { |
| | os.Stdout.WriteString(prompt) |
| | return ui.r.ReadString('\n') |
| | } |
| |
|
| | func (ui *stdUI) Print(args ...interface{}) { |
| | ui.fprint(os.Stderr, args) |
| | } |
| |
|
| | func (ui *stdUI) PrintErr(args ...interface{}) { |
| | ui.fprint(os.Stderr, args) |
| | } |
| |
|
| | func (ui *stdUI) IsTerminal() bool { |
| | return false |
| | } |
| |
|
| | func (ui *stdUI) WantBrowser() bool { |
| | return true |
| | } |
| |
|
| | func (ui *stdUI) SetAutoComplete(func(string) string) { |
| | } |
| |
|
| | func (ui *stdUI) fprint(f *os.File, args []interface{}) { |
| | text := fmt.Sprint(args...) |
| | if !strings.HasSuffix(text, "\n") { |
| | text += "\n" |
| | } |
| | f.WriteString(text) |
| | } |
| |
|
| | |
| | type oswriter struct{} |
| |
|
| | func (oswriter) Open(name string) (io.WriteCloser, error) { |
| | f, err := os.Create(name) |
| | return f, err |
| | } |
| |
|