func (f *flags) usage(ui plugin.UI) { var commandMsg []string for name, cmd := range f.commands { if cmd.HasParam { name = name + "=p" } commandMsg = append(commandMsg, fmt.Sprintf(" -%-16s %s", name, cmd.Usage)) } sort.Strings(commandMsg) text := usageMsgHdr + strings.Join(commandMsg, "\n") + "\n" + usageMsg + "\n" if f.extraUsage != "" { text += f.extraUsage + "\n" } text += usageMsgVars ui.Print(text) }
// grabProfile fetches and symbolizes a profile. func grabProfile(source, exec, buildid string, fetch plugin.Fetcher, sym plugin.Symbolizer, obj plugin.ObjTool, ui plugin.UI, f *flags) (*profile.Profile, error) { source, host, duration := adjustURL(source, *f.flagSeconds, ui) remote := host != "" if remote { ui.Print("Fetching profile from ", source) if duration != 0 { ui.Print("Please wait... (" + duration.String() + ")") } } now := time.Now() // Fetch profile from source. // Give 50% slack on the timeout. p, err := fetch(source, duration+duration/2, ui) if err != nil { return nil, err } // Update the time/duration if the profile source doesn't include it. // TODO(rsilvera): Remove this when we remove support for legacy profiles. if remote { if p.TimeNanos == 0 { p.TimeNanos = now.UnixNano() } if duration != 0 && p.DurationNanos == 0 { p.DurationNanos = int64(duration) } } // Replace executable/buildID with the options provided in the // command line. Assume the executable is the first Mapping entry. if exec != "" || buildid != "" { if len(p.Mapping) == 0 { // Create a fake mapping to hold the user option, and associate // all samples to it. m := &profile.Mapping{ ID: 1, } for _, l := range p.Location { l.Mapping = m } p.Mapping = []*profile.Mapping{m} } if exec != "" { p.Mapping[0].File = exec } if buildid != "" { p.Mapping[0].BuildID = buildid } } if err := sym(*f.flagSymbolize, source, p, obj, ui); err != nil { return nil, err } // Save a copy of any remote profiles, unless the user is explicitly // saving it. if remote && !f.isFormat("proto") { prefix := "pprof." if len(p.Mapping) > 0 && p.Mapping[0].File != "" { prefix = prefix + filepath.Base(p.Mapping[0].File) + "." } if !strings.ContainsRune(host, os.PathSeparator) { prefix = prefix + host + "." } for _, s := range p.SampleType { prefix = prefix + s.Type + "." } dir := os.Getenv("PPROF_TMPDIR") tempFile, err := tempfile.New(dir, prefix, ".pb.gz") if err == nil { if err = p.Write(tempFile); err == nil { ui.PrintErr("Saved profile in ", tempFile.Name()) } } if err != nil { ui.PrintErr("Could not save profile: ", err) } } if err := p.Demangle(obj.Demangle); err != nil { ui.PrintErr("Failed to demangle profile: ", err) } if err := p.CheckValid(); err != nil { return nil, fmt.Errorf("Grab %s: %v", source, err) } return p, nil }