Go 調試

pprof

web

package main

import (
    "encoding/json"
    "fmt"
    "net/http"
    _ "net/http/pprof"
    "time"
)

func main() {
    go func() {
        for {
            fmt.Println(1111)
        }
    }()

    fmt.Println("start api server...")
    panic(http.ListenAndServe(":8080", nil))
}

使用生成火焰圖

go tool pprof -http=:8081 -seconds 10  http://localhost:6060/debug/pprof/profile

http://127.0.0.1:8081/ui/flamegraph?si=cpu 查看cpu時長

參考

https://zhuanlan.zhihu.com/p/71529062

https://eddycjy.com/posts/go/tools/2018-09-15-go-tool-pprof/

prometheus metrics

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章