mirror of
https://github.com/google/gops.git
synced 2025-02-19 19:59:55 +02:00
parent
4698eb04b6
commit
6379e59497
17
README.md
17
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=<PID>
|
||||
|
||||
$ gops stack <pid>
|
||||
```
|
||||
|
||||
#### 2. memstats
|
||||
@ -71,7 +71,7 @@ $ gops stack -p=<PID>
|
||||
To print the current memory stats, run the following command:
|
||||
|
||||
```sh
|
||||
$ gops memstats -p=<PID>
|
||||
$ gops memstats <pid>
|
||||
```
|
||||
|
||||
#### 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=<PID>
|
||||
$ gops pprof-cpu <pid>
|
||||
```
|
||||
|
||||
To enter the heap profile, run:
|
||||
|
||||
```sh
|
||||
$ gops pprof-heap -p=<PID>
|
||||
$ gops pprof-heap <pid>
|
||||
```
|
||||
|
||||
#### 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=<PID>
|
||||
$ gops gc <pid>
|
||||
```
|
||||
|
||||
#### 5. version
|
||||
@ -105,12 +105,13 @@ $ gops gc -p=<PID>
|
||||
gops reports the Go version the target program is built with, if you run the following:
|
||||
|
||||
```sh
|
||||
$ gops version -p=<PID>
|
||||
$ gops version <pid>
|
||||
```
|
||||
|
||||
#### 6. vitals
|
||||
|
||||
To print the runtime statistics such as number of goroutines and `GOMAXPROCS`, run the following:
|
||||
|
||||
```sh
|
||||
$ gops vitals -p=<PID>
|
||||
$ gops vitals <pid>
|
||||
```
|
||||
|
21
main.go
21
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=<pid> See the section below.
|
||||
gops Lists all Go processes currently running.
|
||||
gops cmd <pid> 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=<pid> flag")
|
||||
}
|
||||
|
||||
if err := fn(pid); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||
os.Exit(1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user