Golang中的net/http/pprof无法运行。

8

我有一个客户的HTTP服务:

    s := &http.Server{
            Addr:         config.Port,
            Handler:      Controller.Log(http.DefaultServeMux),
            ReadTimeout:  3 * time.Second,
            WriteTimeout: 3 * time.Second,
    }

    http.HandleFunc("/exapmle/router/", exampleFunc)

    err := s.ListenAndServe()
    if err != nil {
            log.Critical(err)
            os.Exit(1)
    }

无法正常工作:

go tool pprof http://localhost:8201/debug/pprof/profile

返回错误:

Failed to fetch http://localhost:8201/debug/pprof/profile?seconds=30

感谢您的信任。以下是您需要翻译的内容:

谢谢。

编辑: 我认为问题出在我重写了默认的http服务器,net/http/pprof包注入了http处理程序:

func init() {
    http.Handle("/debug/pprof/", http.HandlerFunc(Index))
    http.Handle("/debug/pprof/cmdline", http.HandlerFunc(Cmdline))
    http.Handle("/debug/pprof/profile", http.HandlerFunc(Profile))
    http.Handle("/debug/pprof/symbol", http.HandlerFunc(Symbol))
}

我的代码中处理程序不起作用。


2
你是否在服务器中导入了pprof,使用以下代码:import _ "net/http/pprof" - Charlie Andrews
谢谢 @sir_charles804!将导入更改为该确切字符串解决了我遇到的/debug/pprof 404错误问题! - Jay Taylor
1个回答

10

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接