62

golang在自定义的https服务器中启用pprof接口

 6 years ago
source link: https://sheepbao.github.io/post/golang_pprof_over_https/?
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
以下所有观点都是个人愚见,有不同建议或补充的的欢迎emial, aboutme原文章地址pprof的简介 pprof是golang标准库里面的其中一个库,它通过其HTTP服务器得到运行时的分析数据,从而给pprof可视化工具提供数据分析来源。它可以用来分析性能消耗,分析内存泄漏,死锁等。具体使用可以了解官方包pprof,那我如何在http中使用pprof?如何在已有http或者https服务上使用pprof呢? 这些答案在标准库找不到,随在此记录一下。如何启动pprof 在官方包中已经给出了例子:package main import "net/http" import _ "net/http/pprof" // 初始化pprof func main() { // do something ... go func() { log.Println(http.ListenAndServe("localhost:6060", nil)) //启动http服务器 }() } 启动完后,就可以使用go自动的工具go tool pprof如:go tool pprof http://localhost:6060/debug/pprof/heap // 获取堆的相关数据 go tool pprof http://localhost:6060/debug/pprof/profile // 获取30s内cpu的相关数据 go tool pprof http://localhost:6060/debug/pprof/block // 在你程序调用 runtime.SetBlockProfileRate ,查看goroutine阻塞的相关数据 go tool pprof http://localhost:6060/debug/pprof/mutex // 在你程序调用 runtime.SetMutexProfileFraction,查看谁占用mutex 为什么我自定义mux的http服务不能用? 启动自定义mux的http服务器package main import ( "net/http" _ "net/http/pprof" ) func main() { // 启动一个自定义mux的http服务器 mux := http.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK