golang - net/http/pprof 不起作用

标签 go pprof

我有客户 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 包注入(inject) 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))
}

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

最佳答案

您设置的“WriteTimeout”小于配置文件写入时间。

在 pprof.StartCPUProfile() 执行时,它已经开始写入,参见:

因此 http.WriteTimeout 必须大于配置文件写入时间。

抱歉我的英语不好。

关于golang - net/http/pprof 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20854237/

相关文章:

ide - 你用什么写Go

java - 加密Java代码转Go代码

dns - 如何在我的 go 应用程序中读取 consul SRV 记录?

go - pprof(对于 golang)不显示我的包的详细信息

go - Go 如何以及何时为有界队列 channel 分配内存?

go - 制作一个结构 "range-able"?

go - "Memory used"公制 : Go tool pprof vs docker stats

go - exec.Command 没有注册来自 Go 自己的 pprof 工具的错误

go - 序列化 goroutines(并行化但保证顺序)