1
0
mirror of https://github.com/google/gops.git synced 2025-02-19 19:59:55 +02:00
Cezar Sa Espinola ca8282f029
agent: allow starting the agent without installing a signal handler
If the application the agent is being installed on also need to run some
shutdown code during an Interrupt signal, it's important to have the
ability to prevent gops agent from calling os.Exit(). This also adds the
requirement of exposing a method to manually cleanup garbage left by the
gops agent.

To allow custom agent flags now and in the future an Agent type was
created with a public boolean field HandleSignals.
2016-12-15 23:08:52 -02:00
2016-11-14 23:07:31 -08:00
2016-11-28 10:45:02 -08:00
2016-11-11 13:46:23 -08:00
2016-11-28 10:45:02 -08:00
2016-11-03 16:56:19 -07:00
2016-11-20 13:16:04 -08:00
2016-11-20 13:16:04 -08: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.Start(); err != nil {
		log.Fatal(err)
	}
	time.Sleep(time.Hour)
}

Diagnostics manual

0. listing all processes

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

1. stack

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

$ gops stack -p=<PID>

2. memstats

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

$ gops memstats -p=<PID>

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.

To enter the CPU profile, run:

$ gops pprof-cpu -p=<PID>

To enter the heap profile, run:

$ gops pprof-heap -p=<PID>

4. gc

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

$ gops gc -p=<PID>

5. version

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

$ gops version -p=<PID>

6. vitals

To print the runtime statistics such as number of goroutines and GOMAXPROCS, run the following:

$ gops vitals -p=<PID>
Description
A tool to list and diagnose Go processes currently running on your system
Readme BSD-3-Clause 8.8 MiB
Languages
Go 100%