From 6379e59497c3d5e381cc5125461f0bbc51fd3e34 Mon Sep 17 00:00:00 2001 From: Jaana Burcu Dogan Date: Sun, 1 Jan 2017 19:54:15 -0800 Subject: [PATCH] Remove the -p flag. Fixes #25. --- README.md | 17 +++++++++-------- main.go | 21 ++++++++++----------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 52a72df..d6db599 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ func main() { #### 0. listing all processes To print all go processes, run `gops` without arguments: + ```sh $ gops 983 uplink-soecks (/usr/local/bin/uplink-soecks) @@ -62,8 +63,7 @@ Note that processes running the agent are marked with `*` next to the PID (e.g. In order to print the current stack trace from a target program, run the following command: ```sh -$ gops stack -p= - +$ gops stack ``` #### 2. memstats @@ -71,7 +71,7 @@ $ gops stack -p= To print the current memory stats, run the following command: ```sh -$ gops memstats -p= +$ gops memstats ``` #### 3. pprof @@ -82,13 +82,13 @@ it shells out to the `go tool pprof` and let you interatively examine the profil To enter the CPU profile, run: ```sh -$ gops pprof-cpu -p= +$ gops pprof-cpu ``` To enter the heap profile, run: ```sh -$ gops pprof-heap -p= +$ gops pprof-heap ``` #### 4. gc @@ -97,7 +97,7 @@ If you want to force run garbage collection on the target program, run the follo It will block until the GC is completed. ```sh -$ gops gc -p= +$ gops gc ``` #### 5. version @@ -105,12 +105,13 @@ $ gops gc -p= gops reports the Go version the target program is built with, if you run the following: ```sh -$ gops version -p= +$ gops version ``` #### 6. vitals To print the runtime statistics such as number of goroutines and `GOMAXPROCS`, run the following: + ```sh -$ gops vitals -p= +$ gops vitals ``` diff --git a/main.go b/main.go index 33af95f..7b3c7b9 100644 --- a/main.go +++ b/main.go @@ -6,10 +6,10 @@ package main import ( - "flag" "fmt" "log" "os" + "strconv" "strings" "github.com/google/gops/internal/objfile" @@ -19,8 +19,8 @@ import ( const helpText = `Usage: gops is a tool to list and diagnose Go processes. - gops Lists all Go processes currently running. - gops [cmd] -p= See the section below. + gops Lists all Go processes currently running. + gops cmd See the commands below. Commands: gc Runs the garbage collector and blocks until successful. @@ -50,18 +50,17 @@ func main() { if cmd == "help" { usage("") } + if len(os.Args) < 3 { + usage("missing PID") + } + pid, err := strconv.Atoi(os.Args[2]) + if err != nil { + usage("PID should be numeric") + } fn, ok := cmds[cmd] if !ok { usage("unknown subcommand") } - - var pid int - flag.IntVar(&pid, "p", -1, "") - flag.CommandLine.Parse(os.Args[2:]) - if pid == -1 { - usage("missing -p= flag") - } - if err := fn(pid); err != nil { fmt.Fprintf(os.Stderr, "%v\n", err) os.Exit(1)