golang pprof 应用

目录

1 在main 函数 添加下面代码 

2 采集数据 (会存到一个目录 看提示框)

3 分析采集的数据

4 结果展示


1 在main 函数 添加下面代码 

package main

import (
	"fmt"
	"log"
	"net/http"
	_ "net/http/pprof"
)

func main() {


	go func() {
		log.Println(http.ListenAndServe("localhost:6060", nil))
	}()



	// 定义处理请求的函数
	handler := func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "Hello, World!")
	}

	// 注册处理函数
	http.HandleFunc("/", handler)

	// 启动HTTP服务器
	http.ListenAndServe(":8888", nil)
}

2 采集数据 (会存到一个目录 看提示框)

2 采集数据 (会存到一个目录 看提示框)
go tool pprof http://localhost:6060/debug/pprof/profile

3 分析采集的数据


3 分析采集的数据
go tool pprof -http localhost:3001 ./pprof.samples.cpu.002.pb.gz



4 常用命令行分析
top 10 列出前10
web   调用 graphviz 生成svg图片,然后打开
list  查看具体的函数分析
pdf   命令可以生成可视化的pdf文件
help  命令可以提供所有pprof支持的命令说明

4 结果展示

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值