GO PPROF 高cpu负载分析
参考文档
http://www.topgoer.com/其他/pprof性能调优.html
https://blog.wolfogre.com/posts/go-ppof-practice/#前言
编写源码
package main
import (
"fmt"
"net/http"
_ "net/http/pprof"
"runtime"
)
func main() {
runtime.GOMAXPROCS(1)
runtime.SetMutexProfileFraction(1)
runtime.SetBlockProfileRate(1)
registerProf()
CupWait{}.CpuWait()
}
func registerProf() {
port := ":8060"
go func() {
err := http.ListenAndServe(port, nil)
if err != nil {
panic("pprof start error" + err.Error())
}
}()
}
type CupWait struct {
}
func (c CupWait) CpuWait() {
fmt.Println("cpu wait start")
for i := 0; i < 1000000000000; i++ {
}
fmt.Println("cpu wait end")
}
执行分析命令
go tool pprof -http=:8000 http://127.0.0.1:8060/debug/pprof/profile
go tool pprof -seconds=5 http://localhost:8080/debug/pprof/profile
go tool pprof http://localhost:6060/debug/pprof/profile
curl -o cpu.out http://localhost:8060/debug/pprof/profile
go tool pprof -http=:8000 cpu.out