golang – net / http / pprof不起作用

前端之家收集整理的这篇文章主要介绍了golang – net / http / pprof不起作用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有客户http服务:
  1. s := &http.Server{
  2. Addr: config.Port,Handler: Controller.Log(http.DefaultServeMux),ReadTimeout: 3 * time.Second,WriteTimeout: 3 * time.Second,}
  3.  
  4. http.HandleFunc("/exapmle/router/",exampleFunc)
  5.  
  6. err := s.ListenAndServe()
  7. if err != nil {
  8. log.Critical(err)
  9. os.Exit(1)
  10. }

它不起作用:

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

返回错误

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

谢谢.

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

  1. func init() {
  2. http.Handle("/debug/pprof/",http.HandlerFunc(Index))
  3. http.Handle("/debug/pprof/cmdline",http.HandlerFunc(Cmdline))
  4. http.Handle("/debug/pprof/profile",http.HandlerFunc(Profile))
  5. http.Handle("/debug/pprof/symbol",http.HandlerFunc(Symbol))
  6. }

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

您将“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必须大于配置文件写入时间.

抱歉我的英语不好.

猜你在找的Go相关文章