go pprof使用

package main

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

func dfs(a int) int {
	if a == 0 || a == 1 {
		return 1
	}
	return (dfs(a-1) + dfs(a-2)) % 100
}
func main() {
	go func() {
		log.Println(http.ListenAndServe(":6060", nil))
	}()
	for i := 0; i < 100000000; i++ {
		dfs(10)
	}
}

浏览器访问
http://127.0.0.1:6060/debug/pprof/

在这里插入图片描述
会下载heap文件

使用命令

go tool pprof heap       

分析heap文件
常用命令 top,

yuki@ubuntu  ~/Documents  cd ..1 ↵  247016:00:47 
 yuki@ubuntu  ~  cd Downloads                           ✔  247116:00:52 
 yuki@ubuntu  ~/Downloads  go tool pprof heap           ✔  247216:00:56 
File: ___go_build_main_go
Type: inuse_space
Time: Feb 12, 2023 at 2:28pm (CST)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) top
Showing nodes accounting for 2048.85kB, 100% of 2048.85kB total
Showing top 10 nodes out of 23
      flat  flat%   sum%        cum   cum%
  512.50kB 25.01% 25.01%   512.50kB 25.01%  runtime.allocm
  512.20kB 25.00% 50.01%   512.20kB 25.00%  runtime.malg
  512.12kB 25.00% 75.01%  1024.15kB 49.99%  net/http.ListenAndServe (inline)
  512.03kB 24.99%   100%   512.03kB 24.99%  syscall.anyToSockaddr
         0     0%   100%   512.03kB 24.99%  internal/poll.(*FD).Accept
         0     0%   100%   512.03kB 24.99%  internal/poll.accept
         0     0%   100%  1024.15kB 49.99%  main.main.func1
         0     0%   100%   512.03kB 24.99%  net.(*TCPListener).Accept
         0     0%   100%   512.03kB 24.99%  net.(*TCPListener).accept
         0     0%   100%   512.03kB 24.99%  net.(*netFD).accept
(pprof) 

火焰图

安装 graphviz

sudo apt install graphviz

运行命令

go tool pprof -http=:8080 "http://127.0.0.1:6060/debug/pprof/heap" 

显示
在这里插入图片描述
选择 flame graph
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值