2017-09-04 18:45:22 +02:00
|
|
|
# gops
|
|
|
|
|
2017-09-04 20:23:31 +02:00
|
|
|
[![Build status](https://circleci.com/gh/google/gops/tree/master.svg?style=shield&circle-token=2637dc1e57d5407ae250480a86a2e553a7d20482)](https://circleci.com/gh/google/gops)
|
2017-09-19 03:21:51 +02:00
|
|
|
[![GoDoc](https://godoc.org/github.com/google/gops?status.svg)](https://godoc.org/github.com/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
|
|
|
|
2017-09-14 00:09:42 +02:00
|
|
|
```sh
|
2016-11-06 08:49:51 +02:00
|
|
|
$ gops
|
2017-09-14 00:09:42 +02:00
|
|
|
983 980 uplink-soecks go1.9 (/usr/local/bin/uplink-soecks)
|
|
|
|
52697 52695 gops go1.9 (/Users/jbd/bin/gops)
|
|
|
|
4132 4130 foops* go1.9 (/Users/jbd/bin/foops)
|
|
|
|
51130 51128 gocode go1.9 (/Users/jbd/bin/gocode)
|
2016-11-06 08:49:51 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
2017-09-14 00:09:42 +02:00
|
|
|
```sh
|
2016-11-06 08:49:51 +02:00
|
|
|
$ 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() {
|
2017-10-04 08:22:55 +02:00
|
|
|
if err := agent.Listen(agent.Options{}); err != nil {
|
2016-11-14 08:29:02 +02:00
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
time.Sleep(time.Hour)
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2017-01-20 23:19:03 +02:00
|
|
|
### Manual
|
2016-11-14 08:29:02 +02:00
|
|
|
|
2017-03-02 21:51:14 +02:00
|
|
|
It is possible to use gops tool both in local and remote mode.
|
|
|
|
|
|
|
|
Local mode requires that you start the target binary as the same user that runs gops binary.
|
|
|
|
To use gops in a remote mode you need to know target's agent address.
|
|
|
|
|
|
|
|
In Local mode use process's PID as a target; in Remote mode target is a `host:port` combination.
|
|
|
|
|
|
|
|
#### 0. Listing all processes running locally
|
2016-11-16 22:38:16 +02:00
|
|
|
|
|
|
|
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
|
2017-09-14 00:09:42 +02:00
|
|
|
983 980 uplink-soecks go1.9 (/usr/local/bin/uplink-soecks)
|
|
|
|
52697 52695 gops go1.9 (/Users/jbd/bin/gops)
|
|
|
|
4132 4130 foops* go1.9 (/Users/jbd/bin/foops)
|
|
|
|
51130 51128 gocode go1.9 (/Users/jbd/bin/gocode)
|
2016-11-16 22:38:16 +02:00
|
|
|
```
|
|
|
|
|
2017-09-14 00:09:42 +02:00
|
|
|
The output displays:
|
|
|
|
* PID
|
|
|
|
* PPID
|
|
|
|
* name of the program
|
|
|
|
* Go version used to build the program,
|
|
|
|
* Location of the associated program
|
|
|
|
|
2016-11-16 22:38:16 +02:00
|
|
|
Note that processes running the agent are marked with `*` next to the PID (e.g. `4132*`).
|
2016-11-06 08:57:18 +02:00
|
|
|
|
2017-03-02 21:51:14 +02:00
|
|
|
#### $ gops stack (\<pid\>|\<addr\>)
|
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:
|
|
|
|
|
2017-01-20 23:19:03 +02:00
|
|
|
|
2016-11-14 08:29:02 +02:00
|
|
|
```sh
|
2017-03-02 21:51:14 +02:00
|
|
|
$ gops stack (<pid>|<addr>)
|
2017-01-20 23:19:03 +02:00
|
|
|
gops stack 85709
|
|
|
|
goroutine 8 [running]:
|
|
|
|
runtime/pprof.writeGoroutineStacks(0x13c7bc0, 0xc42000e008, 0xc420ec8520, 0xc420ec8520)
|
|
|
|
/Users/jbd/go/src/runtime/pprof/pprof.go:603 +0x79
|
|
|
|
runtime/pprof.writeGoroutine(0x13c7bc0, 0xc42000e008, 0x2, 0xc428f1c048, 0xc420ec8608)
|
|
|
|
/Users/jbd/go/src/runtime/pprof/pprof.go:592 +0x44
|
|
|
|
runtime/pprof.(*Profile).WriteTo(0x13eeda0, 0x13c7bc0, 0xc42000e008, 0x2, 0xc42000e008, 0x0)
|
|
|
|
/Users/jbd/go/src/runtime/pprof/pprof.go:302 +0x3b5
|
|
|
|
github.com/google/gops/agent.handle(0x13cd560, 0xc42000e008, 0xc420186000, 0x1, 0x1, 0x0, 0x0)
|
|
|
|
/Users/jbd/src/github.com/google/gops/agent/agent.go:150 +0x1b3
|
|
|
|
github.com/google/gops/agent.listen()
|
|
|
|
/Users/jbd/src/github.com/google/gops/agent/agent.go:113 +0x2b2
|
|
|
|
created by github.com/google/gops/agent.Listen
|
|
|
|
/Users/jbd/src/github.com/google/gops/agent/agent.go:94 +0x480
|
|
|
|
# ...
|
2016-11-06 08:57:18 +02:00
|
|
|
```
|
2016-11-14 08:29:02 +02:00
|
|
|
|
2017-03-02 21:51:14 +02:00
|
|
|
#### $ gops memstats (\<pid\>|\<addr\>)
|
2016-11-14 08:29:02 +02:00
|
|
|
|
|
|
|
To print the current memory stats, run the following command:
|
|
|
|
|
|
|
|
```sh
|
2017-03-02 21:51:14 +02:00
|
|
|
$ gops memstats (<pid>|<addr>)
|
2016-11-06 08:57:18 +02:00
|
|
|
```
|
|
|
|
|
2016-11-14 08:29:02 +02:00
|
|
|
|
2017-03-02 21:51:14 +02:00
|
|
|
#### $ gops gc (\<pid\>|\<addr\>)
|
2016-11-06 08:57:18 +02:00
|
|
|
|
2017-01-20 23:19:03 +02:00
|
|
|
If you want to force run garbage collection on the target program, run `gc`.
|
|
|
|
It will block until the GC is completed.
|
2016-11-06 08:57:18 +02:00
|
|
|
|
2017-10-08 20:11:38 +02:00
|
|
|
#### $gops setgc (\<pid\>|\<addr\>) <perc>
|
|
|
|
|
|
|
|
Sets the garbage collection target to a certain percentage.
|
|
|
|
The following command sets it to 10%:
|
|
|
|
|
|
|
|
``` sh
|
|
|
|
$ gops setgc (<pid>|<addr>) 10
|
|
|
|
```
|
|
|
|
|
2016-11-14 08:29:02 +02:00
|
|
|
|
2017-03-02 21:51:14 +02:00
|
|
|
#### $ gops version (\<pid\>|\<addr\>)
|
2017-01-20 23:19:03 +02:00
|
|
|
|
|
|
|
gops reports the Go version the target program is built with, if you run the following:
|
2016-11-14 08:29:02 +02:00
|
|
|
|
|
|
|
```sh
|
2017-03-02 21:51:14 +02:00
|
|
|
$ gops version (<pid>|<addr>)
|
2017-01-20 23:19:03 +02:00
|
|
|
devel +6a3c6c0 Sat Jan 14 05:57:07 2017 +0000
|
2016-11-06 08:57:18 +02:00
|
|
|
```
|
|
|
|
|
2017-03-02 21:51:14 +02:00
|
|
|
#### $ gops stats (\<pid\>|\<addr\>)
|
2017-01-20 23:09:45 +02:00
|
|
|
|
2017-01-20 23:19:03 +02:00
|
|
|
To print the runtime statistics such as number of goroutines and `GOMAXPROCS`.
|
2017-01-20 23:09:45 +02:00
|
|
|
|
2017-01-20 23:19:03 +02:00
|
|
|
#### Profiling
|
2017-01-20 23:09:45 +02:00
|
|
|
|
2016-11-06 08:57:18 +02:00
|
|
|
|
2017-01-20 23:19:03 +02:00
|
|
|
##### 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.
|
|
|
|
|
|
|
|
To enter the CPU profile, run:
|
2016-11-06 08:57:18 +02:00
|
|
|
|
2016-11-14 08:29:02 +02:00
|
|
|
```sh
|
2017-03-02 21:51:14 +02:00
|
|
|
$ gops pprof-cpu (<pid>|<addr>)
|
2016-11-06 08:57:18 +02:00
|
|
|
```
|
2016-11-14 08:29:02 +02:00
|
|
|
|
2017-01-20 23:19:03 +02:00
|
|
|
To enter the heap profile, run:
|
2016-11-14 08:29:02 +02:00
|
|
|
|
|
|
|
```sh
|
2017-03-02 21:51:14 +02:00
|
|
|
$ gops pprof-heap (<pid>|<addr>)
|
2016-11-06 08:57:18 +02:00
|
|
|
```
|
2016-11-14 08:29:02 +02:00
|
|
|
|
2017-03-02 21:52:43 +02:00
|
|
|
##### Execution trace
|
2016-11-16 22:38:16 +02:00
|
|
|
|
2017-01-20 23:19:03 +02:00
|
|
|
gops allows you to start the runtime tracer for 5 seconds and examine the results.
|
2017-01-02 05:54:15 +02:00
|
|
|
|
2016-11-16 22:38:16 +02:00
|
|
|
```sh
|
2017-03-02 21:51:14 +02:00
|
|
|
$ gops trace (<pid>|<addr>)
|
2016-11-16 22:38:16 +02:00
|
|
|
```
|
2017-01-20 23:19:03 +02:00
|
|
|
|