How to use pprof in Go program?
There is a Go package named net/http/pprof,but I can’t use it.
The document says go tool pprof http://localhost:6060/debug/pprof/heap ,which does not work.
And,what does the below _ mean?
import _ "net/http/pprof"
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Based on your comment, the issue might be that you’re not using the correct port number.
If you are running an http server at
http://localhost:9997, then I think you want to run the command withhttp://localhost:9997:According to the net/http/pprof pkg doc page, if your application is already running an http server you do not need to start one and only need to include the
import _ "net/http/pprof"somewhere in your program.http://localhost:6060is the server started as an example and the host and port are arbitrary.import _ "net/http/pprof"means the package is imported but you do not use any of its exported identifiers. According to the go language spec, this will import the package solely for its side effects. These side effects involve, I think, the execution of the init() functions defined in the package’s source files and, apparently, registered variables.Also, you might find this blog post helpful:
http://blog.golang.org/2011/06/profiling-go-programs.html