1
0
mirror of https://github.com/google/gops.git synced 2024-11-19 20:31:58 +02:00
A tool to list and diagnose Go processes currently running on your system
Go to file
2017-09-11 19:50:16 -07:00
.circleci switch to Circle CI 2017-09-04 10:09:16 -07:00
agent agent: don't close on interrupt by default (#49) 2017-09-11 19:50:16 -07:00
examples/hello agent: don't close on interrupt by default (#49) 2017-09-11 19:50:16 -07:00
goprocess goversion: use rsc.io/goversion/version instead of internal package (#47) 2017-09-04 11:53:45 -07:00
internal internal, vendor: remove unused code (#48) 2017-09-06 12:15:36 -06:00
signal add remote mode support (#30) 2017-03-02 11:51:14 -08:00
vendor internal, vendor: remove unused code (#48) 2017-09-06 12:15:36 -06:00
cmd.go Print filenames on client for pprof and trace dumps (#38) 2017-07-27 00:54:08 -07:00
Gopkg.lock vendor: dep ensure again 2017-09-04 11:54:34 -07:00
Gopkg.toml all: run dep init again 2017-07-28 14:45:08 -07:00
LICENSE add license 2016-11-03 16:56:19 -07:00
main_test.go shorthen devel build version string 2017-09-04 20:08:19 -07:00
main.go agent indicator should be postfix 2017-09-04 23:05:17 -07:00
README.md README: add build status badge 2017-09-04 11:23:37 -07:00

gops

Build status GoDoc

gops is a command to list and diagnose Go processes currently running on your system.

$ 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)

Installation

$ go get -u github.com/google/gops

Diagnostics

For processes that starts the diagnostics agent, gops can report additional information such as the current stack trace, Go version, memory stats, etc.

In order to start the diagnostics agent, see the hello example.

package main

import (
	"log"
	"time"

	"github.com/google/gops/agent"
)

func main() {
	if err := agent.Listen(nil); err != nil {
		log.Fatal(err)
	}
	time.Sleep(time.Hour)
}

Manual

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

To print all go processes, run gops without arguments:

$ 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*).

$ gops stack (<pid>|<addr>)

In order to print the current stack trace from a target program, run the following command:

$ gops stack (<pid>|<addr>)
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
# ...

$ gops memstats (<pid>|<addr>)

To print the current memory stats, run the following command:

$ gops memstats (<pid>|<addr>)

$ gops gc (<pid>|<addr>)

If you want to force run garbage collection on the target program, run gc. It will block until the GC is completed.

$ gops version (<pid>|<addr>)

gops reports the Go version the target program is built with, if you run the following:

$ gops version (<pid>|<addr>)
devel +6a3c6c0 Sat Jan 14 05:57:07 2017 +0000

$ gops stats (<pid>|<addr>)

To print the runtime statistics such as number of goroutines and GOMAXPROCS.

Profiling

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:

$ gops pprof-cpu (<pid>|<addr>)

To enter the heap profile, run:

$ gops pprof-heap (<pid>|<addr>)
Execution trace

gops allows you to start the runtime tracer for 5 seconds and examine the results.

$ gops trace (<pid>|<addr>)