Git Product home page Git Product logo

gops's Introduction

gops

GitHub Action Status GoDoc

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

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

$ go get github.com/google/gops

or

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

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

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

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:

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

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

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

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

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

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

The following command turns off the garbage collector:

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

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

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

gops's People

Contributors

ale64bit avatar cezarsa avatar dastergon avatar dependabot[bot] avatar ferhatelmas avatar glibsm avatar holygeek avatar kakilangit avatar keanpedersen avatar kumakichi avatar mattn avatar mtardy avatar nabeken avatar pborzenkov avatar pieterlouw avatar rakyll avatar segevda avatar shawnps avatar shihanng avatar sudo-suhas avatar tklauser avatar utrack avatar vadorovsky avatar xaurx avatar yarcat avatar yashladha avatar yasushi-saito avatar zbindenren avatar zhsj avatar zuorambo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gops's Issues

Print undetermined processes

When we cannot locate a binary on the disk, we mention the number of such cases in the output of gops. Rather than just mentioning the number for the undetermined processes, also print the details of them. So, the user can manually examine and determine whether they are go binaries or not.

Error with go get.

Error -

#github.com/google/gops/internal/objfile
go/src/github.com/google/gops/internal/objfile/goobj.go:119: undefined: gosym.PCValue
go/src/github.com/google/gops/internal/objfile/goobj.go:126: undefined: gosym.PCValue

go env

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH=""
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/2w/fcrm_b9n28d1knhgqmvl24j8bjsl2j/T/go-build300906419=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"

go pprof unable to parse files generated by gops pprof

Command : gops.exe pprof-cpu <addr>

Output :

Profiling CPU now, will take 30 secs...
Profile dump saved to: <Home>\AppData\Local\Temp\2\profile717781735
Profiling dump saved to: <Home>\AppData\Local\Temp\2\profile717781735
Binary file saved to: <Home>\AppData\Local\Temp\2\binary243888410
<Home>\AppData\Local\Temp\2\binary243888410: parsing profile: unrecognized profile format
<Home>\AppData\Local\Temp\2\profile717781735: parsing profile: unrecognized profile format
failed to fetch any source profiles
exit status 1

Platform : Windows 2016 Datacenter

fail with pprof-cpu: failed to read the binary

I used gops with Ubuntu 16.04 LTS, built with ccfb39d

➜  ~  gops
3078	gops	(/usr/bin/gops)
2708	filebeat	(/usr/share/filebeat/bin/filebeat)
1332*	file	(/code/file)
➜  ~ gops pprof-cpu 1332
Profiling CPU now, will take 30 secs...
failed to read the binary

Write cpu profile to socket

The cpu profile is taken by the agent but never written to the socket. Happy to submit a PR for the change if needed.

couldn't get port by PID

gops memstats 27281
couldn't get port by PID: dial tcp 127.0.0.1:0: connect: can't assign requested address
when i use addr,long time no response.
i use go version go1.10 darwin/amd64.
i remember it works before,perhaps i updated the go version.

panic when run without pid

gops gc
panic: runtime error: index out of range

goroutine 1 [running]:
main.main()
        /home/srv_web/.gopath/src/github.com/google/gops/main.go:75 +0x3b9

where is the cmds defined

func main() {
if len(os.Args) < 2 {
processes()
return
}

cmd := os.Args[1]
if cmd == "help" {
	usage("")
}
fn, ok := cmds[cmd]
if !ok {
	usage("unknown subcommand")
}

Stacktrace in 'debug=1' format

Hi!

I'd like to propose a feature that allows to (optionally) dump a stack track in debug=1 format. Currently agent hardcodes it to debug=2.

While debug=2 format is probably more readable, debug=1 has a rather large advantage - it includes pprof labels. This is especially handy when there are many goroutines doing similar work but handling different tasks/assignments/etc.

If there are no objections, I can probably prepare a PR. I think introducing a new command to preserve backward compatibility is the way to go here.

Remove the -p flag

Just use the last arg to find out the PID. Typing -p each time to use gops is not very user friendly.

Report process info

gops can report more process info (e.g. https://godoc.org/github.com/shirou/gopsutil/process) for a PID. The only downside is that this command will be asymmetrical because we cannot provide the same functionality for the processes working remotely.

$ gops <pid>
Create time: XXX
Number of threads: 4
Number of context switches: X
Number of file descriptors: X
Number of open files: X

Connections
...

@odeke-em, what do you think?

gops stack 38744 => Couldn't resolve addr or pid 38744 to TCPAddress: couldn't get port for PID 38744:

$ gops tree
...
├── 27500
│   └── 38707 (go) {go1.15.4}
│   └── 38744 (main) {go1.15.4}
│   └── 38745 (main) {go1.15.4}
└── 28308
└── 38862 (gops) {go1.15.4}

$ gops 38707
parent PID: 27500
threads: 21
memory usage: 0.265%
cpu usage: 1.372%
username: admin
cmd+args: go run main.go service api
elapsed time: 03:58

$ gops stack 38707
Couldn't resolve addr or pid 38707 to TCPAddress: couldn't get port for PID 38707: open /Users/admin/Library/Application Support/gops/38707: no such file or directory

how to get it ?

used MacBook-Pro-7

Missing list of Golang versions supported in the documentation.

I just noticed that the documentation does not have list golang versions supported by this package. It cannot run using other golang versions apart from go1.12

go build github.com/google/gops/signal: module requires Go 1.12
go build github.com/google/gops/internal: module requires Go 1.12
``

gops crash

for easy to crash, build the hello example as windows exe program.
launch the exe program ten times.
then just use gops in console, it is happen.

What's the gops's roadmap ?

In java domain, they have JMX and jmxtrans, so they could build an platform to monitoring the java application clusters.
With the help of grafanakibanagangliaprometheus or zabbixopenfalcon, they could config one monitoring solution which has displaying and alerting feature.

So, what can our gops do ?
Now, we could report real-time runtime info by agent mode.
But, the representation is not enough and not intuitive.
Otherwise, we want collect real-time info and record history data.
I think we could report mertics to time-series DB(as InfluxDB).
We could support runtime monitoring solution for golang ecology.

Using TMPDIR instead of current users home.

It may be a better idea to use TMPDIR instead of current user's home directory for writing gops port files. The homedir may not be writable, while TMPDIR is. It also allows us to run gops binary with a different user than the app embedding the gops agent.

New release?

Hi there,

Would it be possible to cut a new release? It would be especially nice to get #87 in a released version.

Thanks!

stat the pid file to report agent running processes

Currently, we are looking for the agent symbol's existence to report if a process is running the agent. This assertion doesn't help if the agent is closed. We should instead stat the gops pid file for the process to see if the agent is actively listening.

(newest) gops crashed in go1.15

for easy to crash, build the hello example as windows exe program.
launch the exe program ten times.
then just use gops in console, it is happen.

Gops hangs if there are too many Go processes to examine

If you have more than ten (I believe) Go processes, gops will hang in goprocess/gp.go's FindAll() function. This happens because the 'for .. range pss { ...}' loop attempts to obtain a limitCh token before starting the goroutine, but the goroutines only release their token after they have sent their reply to the found channel. Since the found channel is unbuffered and is only read from by the main code after the 'for .. range pss {}' loop finishes, this deadlocks if the number of goroutines would ever be limited.

I think either the entire 'for .. range pss { ... }' loop needs to be in a goroutine so that it doesn't block reading from the found channel, or the limitCh token must be released by the code before sending to found. The former change seems easier and I think it's correct.

improve docs to mention ptrace_scope

I have to execute echo 0 > /proc/sys/kernel/yama/ptrace_scope to get gops running
GoLand use to remind me, but does not anymore and gops just hangs without this setting

wort mentioning that in the docs?

killed $GOPATH/bin/gops

How should i deal with this error?

Error

killed $GOPATH/bin/gops

go version

go version go1.8 darwin/amd64

go env

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/william/gocode"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/hk/hn36zx657pb9s_509zcdr4cr0000gp/T/go-build134432162=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

Cannot run stack command

I kept getting 'connection refused' info when trying to run 'gops stack (|)' command.

[root@izj6c44nzox6sb97nzgmhyz ~]# gops
13136 13128 containerd unknown Go version /usr/local/bin/containerd
13650 13235 gops go1.9.1 /usr/local/go/bin/gops
13128 7610 pouchd go1.9.1 /usr/local/bin/pouchd
[root@izj6c44nzox6sb97nzgmhyz ~]# gops stack 13128
couldn't get port by PID: dial tcp 127.0.0.1:0: getsockopt: connection refused

How to use this package

Hi,

I'm not clear on how this package is actually working, when I try to follow the steps on the readme.md I'm running into: no such file or directory

This is the complete logs:

test@test:~# /opt/gocode/bin/gops
2153	        grafana-server	(/usr/sbin/grafana-server)
4496	        influxd	(/usr/bin/influxd)
4506 	gops	(/opt/gocode/bin/gops)

90 processes left undetermined
test@test:~# /opt/gocode/bin/gops stack -p=4496
open /test/.config/gops/4496: no such file or directory

Any ideas ?

Cheers.

Amazon triple containing

Hi, I'm very glad to find you on this website. I'm a developer from China. Now I does working on Bluetooth Sigmesh . I plan to access the Amazon echo for my device , and then I recgnized before I need the BLE Mesh Credentials- A triple containing the OOB Type (Static only for now), OOB Data (pub key), and Device UUID.
But I has clicked entire website still connot find out the documentation for how to get my triple containing.
May I get some help form you , very appreciate.

How to set text browser with the pprof signal

I use gops on the centos, and when I use gops trace pid, it'll pause when Opening browser.
I hope there is a way to connect browser to the gops, such as links, elinks, etc...
Because it's not safe for us to export a certain http port. So we need use gops on the server instead of local windows computer.

[feature request] add column header

when we run ps without any args, its output includes column header like this:

# ps
  PID TTY          TIME CMD
22671 pts/0    00:00:00 bash
23572 pts/0    00:00:00 ps

currently gops does not have column header, those newcomer users may not know meanings of 1st and 2nd column

i have a problem

go build
package .
imports github.com/google/gops/internal/objfile: use of internal package not allowed

Report the vitals

$ gops vitals might report the vitals such as number of goroutines, threads, GOMAXPROCS, NumCPU and NumGoroutine.

use current work dir or temp dir to avoid ConfigDir error

unable to get current user home directory: os/user lookup failed; $HOME is empty

I build my application on instance A and run it on instance B.
The app run as user root and the env variable $HOME is /root.
But i got the follow error.

Maybe we should use temp dir

func ConfigDir() (string, error) {
	if runtime.GOOS == "windows" {
		return filepath.Join(os.Getenv("APPDATA"), "gops"), nil
	}
	homeDir := guessUnixHomeDir()
	if homeDir == "" {
                // os.TempDir() or filepath.Abs(filepath.Dir(os.Args[0]))
		return "", errors.New("unable to get current user home directory: os/user lookup failed; $HOME is empty")
	}
	return filepath.Join(homeDir, ".config", "gops"), nil
}

Report version from binary file

$ gops <path_to_binary> 

can report the Go version for those who wants to investigate the build version without having to run the binary.

agent security?

Nice stuff!
Do I understand correctly that the agent socket is pretty much unprotected (accessible to any user on the system) by default, or am I missing something? Maybe a note in the readme about this would help?

Tag new release?

WIth some of the recent changes, it would be nice to tag a new release. I think I have the permissions to tag a new release, but I wanted to check with you whether it is OK if I do so? @rakyll @odeke-em

Alpine Couldn't resolve addr or pid 1 to TCPAddress: couldn't get port for PID 1: open /root/.config/gops/1: no such file or directory

gops build with export CGO_ENABLED=0, some command works, some command doesn't work:

$ uname -a 
Linux phoenix-7bd56c4576-7k8th 4.19.112+ #1 SMP Fri Sep 4 12:00:04 PDT 2020 x86_64 Linux

$ gops 
319 41 gops     go1.15.6 /tmp/gops
1   0  phoenix  go1.13.5 /usr/local/bin/phoenix

$ gops 1
threads:        31
memory usage:   0.009%
cpu usage:      0.160%
username:       root
cmd+args:       phoenix
elapsed time:   07-18:32:21
local/remote:   :::8123 <-> :::0 (LISTEN)
local/remote:   10.74.28.74:38295 <-> 172.22.72.122:8125 (NONE)

$ gops memstats 1
Couldn't resolve addr or pid 1 to TCPAddress: couldn't get port for PID 1: open /root/.config/gops/1: no such file or directory

$ gops stack 1
Couldn't resolve addr or pid 1 to TCPAddress: couldn't get port for PID 1: open /root/.config/gops/1: no such file or directory

$ gops pprof-heap 1
Couldn't resolve addr or pid 1 to TCPAddress: couldn't get port for PID 1: open /root/.config/gops/1: no such file or directory

Error installing gops

λ go get -u github.com/google/gops
# github.com/google/gops/vendor/github.com/StackExchange/wmi
src\github.com\google\gops\vendor\github.com\StackExchange\wmi\wmi.go:377:22: safeArray.ToValueArray undefined (type *ole.SafeArrayConversion has no field or method ToValueArray)

I have Go 1.10 installed:

λ go version
go version go1.10 windows/amd64

Communication via HTTP

With the pull request #30 seem will be accepted I want to make it a step further by making the gops tool "speak" with agents via HTTP rather than reading each single by via TCP.

Benefit:

  • More firewall friendly and save a port (in my work place 80 is always open)
  • Easier to extend

I will happy to work on this if accepted.

Consider some way to configure unix socket path

Just reviewing the code and would love a way to move that socket out of /tmp to say /var/run for services. Reason I mention it is the PrivateTmp feature provided by systemd.

Maybe an environment variable would be the simplest way to override?

Cheers

Support runtime.SetGCPercent

Provide a command similar to runtime.SetGCPercent to change the GC percentage dynamically during runtime.

$ gops setgc -p=<pid> 60 # Sets GC to 60%
$ gops setgc -p=<pid> -1 # Disables GC

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.