pprof是什么
参考:https://wxsm.space/2023/go-pprof-note/
参考:https://juejin.cn/post/6961301143285104653
- go语言的性能分析和可视化工具
- 原理
- 数据收集
- 采样:默认10ms采样一次
 - 插桩:函数出入口添加代码记录函数信息
 
 - 数据展示
- 文本
 - 图形化:火焰图
 - web界面
 
 
 - 数据收集
 
 - 原理
 
怎么用
package main
import (
	"log"
	"net/http"
	_ "net/http/pprof"
	"time"
)
func work(w http.ResponseWriter, r *http.Request) {
	start := time.Now()
	result := 0
	for i := 0; i < 100000000; i++ {
		result += i
	}
	duration := time.Since(start)
	log.Printf("Done in %v. Result: %d", duration, result)
	w.Write([]byte("Done"))
}
func main() {
	http.HandleFunc("/work", work)
	log.Println("Server is starting...")
	log.Fatal(http.ListenAndServe(":8080", nil))
}
        - _ "net/http/pprof"
- 添加这个之后,会调用pprof的init函数