parseFlags parses the command lines through the specified flags package and returns the source of the profile and optionally the command for the kind of report to generate (nil for interactive use).
(o *plugin.Options)
| 44 | // and returns the source of the profile and optionally the command |
| 45 | // for the kind of report to generate (nil for interactive use). |
| 46 | func parseFlags(o *plugin.Options) (*source, []string, error) { |
| 47 | flag := o.Flagset |
| 48 | // Comparisons. |
| 49 | flagDiffBase := flag.StringList("diff_base", "", "Source of base profile for comparison") |
| 50 | flagBase := flag.StringList("base", "", "Source of base profile for profile subtraction") |
| 51 | // Source options. |
| 52 | flagSymbolize := flag.String("symbolize", "", "Options for profile symbolization") |
| 53 | flagBuildID := flag.String("buildid", "", "Override build id for first mapping") |
| 54 | flagTimeout := flag.Int("timeout", -1, "Timeout in seconds for fetching a profile") |
| 55 | flagAddComment := flag.String("add_comment", "", "Free-form annotation to add to the profile") |
| 56 | flagAllFrames := flag.Bool("all_frames", false, "Ignore drop_frames and keep_frames regexps") |
| 57 | // CPU profile options |
| 58 | flagSeconds := flag.Int("seconds", -1, "Length of time for dynamic profiles") |
| 59 | // Heap profile options |
| 60 | flagInUseSpace := flag.Bool("inuse_space", false, "Display in-use memory size") |
| 61 | flagInUseObjects := flag.Bool("inuse_objects", false, "Display in-use object counts") |
| 62 | flagAllocSpace := flag.Bool("alloc_space", false, "Display allocated memory size") |
| 63 | flagAllocObjects := flag.Bool("alloc_objects", false, "Display allocated object counts") |
| 64 | // Contention profile options |
| 65 | flagTotalDelay := flag.Bool("total_delay", false, "Display total delay at each region") |
| 66 | flagContentions := flag.Bool("contentions", false, "Display number of delays at each region") |
| 67 | flagMeanDelay := flag.Bool("mean_delay", false, "Display mean delay at each region") |
| 68 | flagTools := flag.String("tools", os.Getenv("PPROF_TOOLS"), "Path for object tool pathnames") |
| 69 | |
| 70 | flagHTTP := flag.String("http", "", "Present interactive web UI at the specified http host:port") |
| 71 | flagNoBrowser := flag.Bool("no_browser", false, "Skip opening a browser for the interactive web UI") |
| 72 | |
| 73 | // Flags that set configuration properties. |
| 74 | cfg := currentConfig() |
| 75 | configFlagSetter := installConfigFlags(flag, &cfg) |
| 76 | |
| 77 | flagCommands := make(map[string]*bool) |
| 78 | flagParamCommands := make(map[string]*string) |
| 79 | for name, cmd := range pprofCommands { |
| 80 | if cmd.hasParam { |
| 81 | flagParamCommands[name] = flag.String(name, "", "Generate a report in "+name+" format, matching regexp") |
| 82 | } else { |
| 83 | flagCommands[name] = flag.Bool(name, false, "Generate a report in "+name+" format") |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | args := flag.Parse(func() { |
| 88 | o.UI.Print(usageMsgHdr + |
| 89 | usage(true) + |
| 90 | usageMsgSrc + |
| 91 | flag.ExtraUsage() + |
| 92 | usageMsgVars) |
| 93 | }) |
| 94 | if len(args) == 0 { |
| 95 | return nil, nil, errors.New("no profile source specified") |
| 96 | } |
| 97 | |
| 98 | var execName string |
| 99 | // Recognize first argument as an executable or buildid override. |
| 100 | if len(args) > 1 { |
| 101 | arg0 := args[0] |
| 102 | if file, err := o.Obj.Open(arg0, 0, ^uint64(0), 0, ""); err == nil { |
| 103 | file.Close() |
searching dependent graphs…