加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

golang – net / http / pprof不起作用

发布时间:2020-12-16 19:28:52 所属栏目:大数据 来源:网络整理
导读:我有客户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
我有客户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))
}

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

您将“WriteTimeout”设置为小于配置文件写入时间.

在pprof.StartCPUProfile()执行,它已经开始写,请参阅:

> http://golang.org/src/pkg/runtime/pprof/pprof.go#L565
> http://golang.org/src/pkg/runtime/pprof/pprof.go#L594

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

抱歉我的英语不好.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读