In this case I will do the following.
a) Set up a webserver in my program for getting Go profiles (with import _ "net/http/pprof")
b) map a port from outside k8s so that i can run curl localhost:$PORT/debug/pprof/$PROFILE_TYPE to save a profile (say profile-file)
c) Use go tool pprof/goanalyzer to analyze given profile from the profile-file
I would prefer to run this outside my process as the issue we expect to happen is when my program is hung.
I am not sure if the http server would respond & generate profile files.
From the help of goanalyzer it's not very clear how I would pass the profile-file to it.
It's showing how to generate profile-file using go test/tool but not how to pass them to goanalyzer.
# ./goanalyzer -h
Usage of 'go tool trace':
Given a trace file produced by 'go test':
go test -trace=trace.out pkg
Open a web browser displaying trace:
go tool trace [flags] [pkg.test] trace.out
Generate a pprof-like profile from the trace:
go tool trace -pprof=TYPE [pkg.test] trace.out
[pkg.test] argument is required for traces produced by Go 1.6 and below.
Go 1.7 does not require the binary argument.
Supported profile types are:
- net: network blocking profile
- sync: synchronization blocking profile
- syscall: syscall blocking profile
- sched: scheduler latency profile
Flags:
-http=addr: HTTP service address (e.g., ':6060')
-pprof=type: print a pprof-like profile instead
-d: print debug info such as parsed events