2016-11-14 10:08:24 +02:00
|
|
|
# gops [![Build Status](https://travis-ci.org/google/gops.svg?branch=master)](https://travis-ci.org/google/gops) [![GoDoc](https://godoc.org/github.com/google/gops/agent?status.svg)](https://godoc.org/github.com/google/gops/agent)
|
2016-11-06 08:49:51 +02:00
|
|
|
|
2016-11-06 08:57:18 +02:00
|
|
|
gops is a command to list and diagnose Go processes currently running on your system.
|
2016-11-06 08:49:51 +02:00
|
|
|
|
|
|
|
```
|
|
|
|
$ gops
|
2016-11-06 08:50:39 +02:00
|
|
|
983 uplink-soecks (/usr/local/bin/uplink-soecks)
|
|
|
|
52697 gops (/Users/jbd/bin/gops)
|
2016-11-16 22:38:16 +02:00
|
|
|
4132* foops (/Users/jbd/bin/foops)
|
2016-11-06 08:50:39 +02:00
|
|
|
51130 gocode (/Users/jbd/bin/gocode)
|
2016-11-06 08:49:51 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
|
|
```
|
|
|
|
$ go get -u github.com/google/gops
|
|
|
|
```
|
2016-11-06 08:57:18 +02:00
|
|
|
|
|
|
|
## Diagnostics
|
|
|
|
|
2016-11-14 08:29:02 +02:00
|
|
|
For processes that starts the diagnostics agent, gops can report
|
2016-11-06 08:57:18 +02:00
|
|
|
additional information such as the current stack trace, Go version, memory
|
|
|
|
stats, etc.
|
|
|
|
|
2016-11-11 21:50:47 +02:00
|
|
|
In order to start the diagnostics agent, see the [hello example](https://github.com/google/gops/blob/master/examples/hello/main.go).
|
|
|
|
|
2016-11-14 08:29:02 +02:00
|
|
|
``` go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/google/gops/agent"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-12-20 22:27:39 +02:00
|
|
|
if err := agent.Listen(nil); err != nil {
|
2016-11-14 08:29:02 +02:00
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
time.Sleep(time.Hour)
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Diagnostics manual
|
|
|
|
|
2016-11-16 22:38:16 +02:00
|
|
|
#### 0. listing all processes
|
|
|
|
|
|
|
|
To print all go processes, run `gops` without arguments:
|
2017-01-02 05:54:15 +02:00
|
|
|
|
2016-11-16 22:38:16 +02:00
|
|
|
```sh
|
|
|
|
$ gops
|
|
|
|
983 uplink-soecks (/usr/local/bin/uplink-soecks)
|
|
|
|
52697 gops (/Users/jbd/bin/gops)
|
|
|
|
4132* foops (/Users/jbd/bin/foops)
|
|
|
|
51130 gocode (/Users/jbd/bin/gocode)
|
|
|
|
```
|
|
|
|
|
|
|
|
Note that processes running the agent are marked with `*` next to the PID (e.g. `4132*`).
|
2016-11-06 08:57:18 +02:00
|
|
|
|
2016-11-14 08:29:02 +02:00
|
|
|
#### 1. stack
|
2016-11-06 08:57:18 +02:00
|
|
|
|
2016-11-14 08:29:02 +02:00
|
|
|
In order to print the current stack trace from a target program, run the following command:
|
|
|
|
|
|
|
|
```sh
|
2017-01-02 05:54:15 +02:00
|
|
|
$ gops stack <pid>
|
2016-11-06 08:57:18 +02:00
|
|
|
```
|
2016-11-14 08:29:02 +02:00
|
|
|
|
|
|
|
#### 2. memstats
|
|
|
|
|
|
|
|
To print the current memory stats, run the following command:
|
|
|
|
|
|
|
|
```sh
|
2017-01-02 05:54:15 +02:00
|
|
|
$ gops memstats <pid>
|
2016-11-06 08:57:18 +02:00
|
|
|
```
|
|
|
|
|
2016-11-14 08:29:02 +02:00
|
|
|
#### 3. pprof
|
|
|
|
|
|
|
|
gops supports CPU and heap pprof profiles. After reading either heap or CPU profile,
|
|
|
|
it shells out to the `go tool pprof` and let you interatively examine the profiles.
|
2016-11-06 08:57:18 +02:00
|
|
|
|
2016-11-14 08:29:02 +02:00
|
|
|
To enter the CPU profile, run:
|
2016-11-06 08:57:18 +02:00
|
|
|
|
2016-11-14 08:29:02 +02:00
|
|
|
```sh
|
2017-01-02 05:54:15 +02:00
|
|
|
$ gops pprof-cpu <pid>
|
2016-11-06 08:57:18 +02:00
|
|
|
```
|
2016-11-14 08:29:02 +02:00
|
|
|
|
|
|
|
To enter the heap profile, run:
|
|
|
|
|
|
|
|
```sh
|
2017-01-02 05:54:15 +02:00
|
|
|
$ gops pprof-heap <pid>
|
2016-11-06 08:57:18 +02:00
|
|
|
```
|
|
|
|
|
2017-01-20 23:09:45 +02:00
|
|
|
#### 4. trace
|
|
|
|
|
|
|
|
gops allows you to start the runtime tracer for 5 seconds and examine the results.
|
|
|
|
|
|
|
|
```sh
|
|
|
|
$ gops trace <pid>
|
|
|
|
```
|
|
|
|
|
|
|
|
#### 5. gc
|
2016-11-06 08:57:18 +02:00
|
|
|
|
2016-11-14 08:29:02 +02:00
|
|
|
If you want to force run garbage collection on the target program, run the following command.
|
|
|
|
It will block until the GC is completed.
|
2016-11-06 08:57:18 +02:00
|
|
|
|
2016-11-14 08:29:02 +02:00
|
|
|
```sh
|
2017-01-02 05:54:15 +02:00
|
|
|
$ gops gc <pid>
|
2016-11-06 08:57:18 +02:00
|
|
|
```
|
2016-11-14 08:29:02 +02:00
|
|
|
|
2017-01-20 23:09:45 +02:00
|
|
|
#### 6. version
|
2016-11-14 08:29:02 +02:00
|
|
|
|
|
|
|
gops reports the Go version the target program is built with, if you run the following:
|
|
|
|
|
|
|
|
```sh
|
2017-01-02 05:54:15 +02:00
|
|
|
$ gops version <pid>
|
2016-11-06 08:57:18 +02:00
|
|
|
```
|
2016-11-14 08:29:02 +02:00
|
|
|
|
2017-01-20 23:09:45 +02:00
|
|
|
#### 7. stats
|
2016-11-16 22:38:16 +02:00
|
|
|
|
|
|
|
To print the runtime statistics such as number of goroutines and `GOMAXPROCS`, run the following:
|
2017-01-02 05:54:15 +02:00
|
|
|
|
2016-11-16 22:38:16 +02:00
|
|
|
```sh
|
2017-01-03 11:15:13 +02:00
|
|
|
$ gops stats <pid>
|
2016-11-16 22:38:16 +02:00
|
|
|
```
|