Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
G

gops

> 编程语言
Open source

A tool to list and diagnose Go processes currently running on your system

7.0K stars0 likes2 views
WebsiteGitHub

About

A tool to list and diagnose Go processes currently running on your system

gops

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

bash
$ gops
983   980    uplink-soecks  go1.9   /usr/local/bin/uplink-soecks
52697 52695  gops           go1.10  /Users/jbd/bin/gops
4132  4130   foops        * go1.9   /Users/jbd/bin/foops
51130 51128  gocode         go1.9.2 /Users/jbd/bin/gocode

Installation

To install the latest version of gops:

bash
$ go get github.com/google/gops

or

bash
$ go install github.com/google/gops@latest

To install a specific gops version, for example v0.3.19:

bash
$ go install github.com/google/[email protected]

Diagnostics

For processes that start 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.

go
package main

import (
	"log"
	"time"

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

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

Otherwise, you could set GOPS_CONFIG_DIR environment variables to assign your config dir. Default, gops will use the current user's home directory(AppData on windows).

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.

Listing all processes running locally

To print all go processes, run gops without arguments:

bash
$ gops
983   980    uplink-soecks  go1.9   /usr/local/bin/uplink-soecks
52697 52695  gops           go1.10  /Users/jbd/bin/gops
4132  4130   foops        * go1.9   /Users/jbd/bin/foops
51130 51128  gocode         go1.9.2 /Users/jbd/bin/gocode

The output displays:

  • PID
  • PPID
  • Name of the program
  • Go version used to build the program
  • Location of the associated program

Note that processes running the agent are marked with * next to the PID (e.g. 4132*).

$ gops <pid> [duration]

To report more information about a process, run gops followed by a PID:

bash
$ gops <pid>
parent PID:	5985
threads:	27
memory usage:	0.199%
cpu usage:	0.139%
username:	jbd
cmd+args:	/Applications/Splice.app/Contents/Resources/Splice Helper.app/Contents/MacOS/Splice Helper -pid 5985
local/remote:	127.0.0.1:56765 <-> :0 (LISTEN)
local/remote:	127.0.0.1:56765 <-> 127.0.0.1:50955 (ESTABLISHED)
local/remote:	100.76.175.164:52353 <-> 54.241.191.232:443 (ESTABLISHED)

If an optional duration is specified in the format as expected by time.ParseDuration, the CPU usage for the given time period is reported in addition:

bash
$ gops <pid> 2s
parent PID:	5985
threads:	27
memory usage:	0.199%
cpu usage:	0.139%
cpu usage (2s):	0.271%
username:	jbd
cmd+args:	/Applications/Splice.app/Contents/Resources/Splice Helper.app/Contents/MacOS/Splice Helper -pid 5985
local/remote:	127.0.0.1:56765 <-> :0 (LISTEN)
local/remote:	127.0.0.1:56765 <-> 127.0.0.1:50955 (ESTABLISHED)
local/remote:	100.76.175.164:52353 <-> 54.241.191.232:443 (ESTABLISHED)

$ gops tree

To display a process tree with all the running Go processes, run the following command:

bash
$ gops tree

...
├── 1
│   └── 13962 [gocode] {go1.9}
├── 557
│   └── 635 [com.docker.supervisor] {go1.9.2}
│       └── 638 [com.docker.driver.amd64-linux] {go1.9.2}
└── 13744
    └── 67243 [gops] {go1.10}

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

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

…

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

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

bash
$ 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 setgc (<pid>|<addr>)

Sets the garbage collection target to a certain percentage. The following command sets it to 10%:

bash
$ gops setgc (<pid>|<addr>) 10

The following command turns off the garbage collector:

bash
$ gops setgc (<pid>|<addr>) off

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

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

bash
$ 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 interactively examine the profiles.

To enter the CPU profile, run:

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

To enter the heap profile, run:

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

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

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

Issues· 34 open

View all issuesOpen on GitHub
  • #269

    Support debug.WriteHeapDump?

    Updated Dec 1, 2025
  • #267

    New release?

    Updated Sep 8, 2025
  • #253

    Add method to get port used

    Updated Aug 2, 2024
  • #238

    Missing Go process (with agent)

    Updated Dec 5, 2023
  • #42

    killed $GOPATH/bin/gops

    Updated Oct 16, 2023
  • #31

    Using TMPDIR instead of current users home.

    Updated Oct 13, 2023
  • #222

    Any restrictions on rootless containers?

    Updated Aug 16, 2023
  • #216

    The reported CPU usage is much higher or lower than top reported value?

    Updated Jun 19, 2023
  • #168

    Couldn't resolve addr or pid <pid> to TCPAddress

    Updated Feb 12, 2023
  • #197

    json output?

    Updated Jan 27, 2023

> Tags

Gocpu-profilediagnosticsgogo-tools

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 22, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言