第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

使用 net/http/pprof 分析使用 Gorilla 的 mux 構(gòu)建的 Go

使用 net/http/pprof 分析使用 Gorilla 的 mux 構(gòu)建的 Go

Go
喵喵時(shí)光機(jī) 2021-06-29 16:12:20
我有一個(gè)用 Go 編寫(xiě)的相對(duì)較大的 Web 應(yīng)用程序,它使用Gorilla 的 mux進(jìn)行路由。我最近意識(shí)到我的 Web 應(yīng)用程序很慢,我想分析 Web 應(yīng)用程序。閱讀后,似乎net/http/pprof是我需要的。但我不能讓它與mux 一起運(yùn)行;即使是最微不足道的 Web 應(yīng)用程序。有誰(shuí)知道如何使它工作?這是一個(gè)不起作用的普通代碼示例(即在 處不提供任何內(nèi)容/debug)。package mainimport (    "fmt"    "github.com/gorilla/mux"    "math"    "net/http")import _ "net/http/pprof"func SayHello(w http.ResponseWriter, r *http.Request) {    for i := 0; i < 1000000; i++ {        math.Pow(36, 89)    }    fmt.Fprint(w, "Hello!")}func main() {    r := mux.NewRouter()    r.HandleFunc("/hello", SayHello)    http.ListenAndServe(":6060", r)}
查看完整描述

3 回答

?
FFIVE

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超6個(gè)贊

user983716 - 感謝您的問(wèn)題和解決方案!


我無(wú)法使用網(wǎng)絡(luò)索引 ( http://[my-server]/debug/pprof ) 中的鏈接,直到我在您的解決方案中添加了幾行,如下所示:


...


func AttachProfiler(router *mux.Router) {

    router.HandleFunc("/debug/pprof/", pprof.Index)

    router.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)

    router.HandleFunc("/debug/pprof/profile", pprof.Profile)

    router.HandleFunc("/debug/pprof/symbol", pprof.Symbol)


    // Manually add support for paths linked to by index page at /debug/pprof/

    router.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine"))

    router.Handle("/debug/pprof/heap", pprof.Handler("heap"))

    router.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate"))

    router.Handle("/debug/pprof/block", pprof.Handler("block"))

}


...

如果有人遇到同樣的問(wèn)題,我希望這會(huì)有所幫助!


查看完整回答
反對(duì) 回復(fù) 2021-07-05
  • 3 回答
  • 0 關(guān)注
  • 381 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)