google / gops

A tool to list and diagnose Go processes currently running on your system
BSD 3-Clause "New" or "Revised" License
6.7k stars 333 forks source link

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

Open fighthorse opened 3 years ago

fighthorse commented 3 years ago

$ 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

mrbuk commented 3 years ago

You might try to run the commands against a process that does not have the gops agent running.

This is not clear from the Github README.md but it is mentioned in the help:

> gops help
gops is a tool to list and diagnose Go processes.

Usage:
  gops <cmd> <pid|addr> ...
  gops <pid> # displays process info
  gops help  # displays this help message

Commands:
  stack      Prints the stack trace.
  gc         Runs the garbage collector and blocks until successful.
  setgc      Sets the garbage collection target percentage.
  memstats   Prints the allocation and garbage collection stats.
  version    Prints the Go version used to build the program.
  stats      Prints runtime stats.
  trace      Runs the runtime tracer for 5 secs and launches "go tool trace".
  pprof-heap Reads the heap profile and launches "go tool pprof".
  pprof-cpu  Reads the CPU profile and launches "go tool pprof".

All commands require the agent running on the Go process.
"*" indicates the process is running the agent.

I am referring to the following part All commands require the agent running on the Go process.

When you run gops against a process that has the agent running you will see a local/remote field reported. That field contains the port gops connects against when running e.g. gops stack

> gops 64646                                                                                                                                                                       (1) 10:01:32 
parent PID: 64507
threads:    7
memory usage:   0.019%
cpu usage:  0.000%
username:   mbukowski
cmd+args:   /tmp/go-build1553357288/b001/exe/main
elapsed time:   04:16
local/remote:   127.0.0.1:35097 <-> 0.0.0.0:0 (LISTEN)

In contrast a process without the agent running doesn't report local/remote

> gops 39343                                                                                                                                                                           10:02:00 
parent PID: 15306
threads:    9
memory usage:   0.038%
cpu usage:  0.000%
username:   mbukowski
cmd+args:   starlark
elapsed time:   01-22:10:03

You can running gops against the pid of go run github.com/mrbuk/hello-gops and it should work.