2016-11-12 01:44:07 +02:00
|
|
|
# gops [![Build Status](https://travis-ci.org/google/gops.svg?branch=master)](https://travis-ci.org/google/gops)
|
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)
|
|
|
|
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() {
|
|
|
|
if err := agent.Start(); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
time.Sleep(time.Hour)
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2016-11-11 22:05:26 +02:00
|
|
|
Please note that diagnostics features are only supported on Unix-like systems for now.
|
2016-11-11 21:45:10 +02:00
|
|
|
We are planning to add Windows support in the near future.
|
2016-11-06 08:57:18 +02:00
|
|
|
|
2016-11-14 08:29:02 +02:00
|
|
|
### Diagnostics manual
|
|
|
|
|
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
|
|
|
|
$ gops stack -p=<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
|
|
|
|
$ gops memstats -p=<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
|
|
|
|
$ gops pprof-cpu -p=<PID>
|
2016-11-06 08:57:18 +02:00
|
|
|
```
|
2016-11-14 08:29:02 +02:00
|
|
|
|
|
|
|
To enter the heap profile, run:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
$ gops pprof-mem -p=<PID>
|
2016-11-06 08:57:18 +02:00
|
|
|
```
|
|
|
|
|
2016-11-14 08:29:02 +02:00
|
|
|
#### 4. 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
|
|
|
|
$ gops gc -p=<PID>
|
2016-11-06 08:57:18 +02:00
|
|
|
```
|
2016-11-14 08:29:02 +02:00
|
|
|
|
|
|
|
#### 5. version
|
|
|
|
|
|
|
|
gops reports the Go version the target program is built with, if you run the following:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
$ gops version -p=<PID>
|
2016-11-06 08:57:18 +02:00
|
|
|
```
|
2016-11-14 08:29:02 +02:00
|
|
|
|