go tool pprof using application PID instead of http endpoint -


right now, profile go applications using go tool pprof this:

go tool pprof http://localhost:8080/debug/pprof/profile 

i want use pprof tool on arbitrary go process running http server on unknown port. information have process pid. need 1 of 2 things:

  • get go processes port number pid.
  • profile running process directly. example, go tool pprof 10303 pid 10303.

would either of these work?

service discovery designed resolve problems this. simple solution create tmp file every pid, writing each port according file. , read port when need go tool pprof.

http.listenandserve("localhost:" + port, nil) tmpfilepath := filepath.join(os.tempdir(), "myport_" + strconv.formatint(os.getpid(), 10)) f, _ := os.openfile(tmpfilepath, os.o_rdwr|os.o_create|os.o_excl, 0600) f.write(byte[](strconv.formatint(port, 10))) f.close() 

in go tool prof bash: go tool http://localhost:`cat /tmp/myport_10303`/debug/pprof/profile

not tested in real, maybe syntax error

update:

another way not change go source is, use bash command netstat/lsof find out listening port of go process. like:

netstat -antp | grep 10303| grep listen | awk '{ print $4 }' | awk -f: '{print $2}' 

not best bash script think, reference.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -