golang性能调优工具pprof的使用

文章目录

  • 前言
  • 一、cpu
    • 1.下载实例代码
    • 2.运行项目中的main.go文件
    • 3.查看CPU性能数据
    • 4.使用topN(N是可选的数量,也可以不加直接运行)命令来查看占用资源最多的函数
    • 5.查看可能存在问题的具体函数代码
    • 6.使用web命令来调用关系可视化
  • 二、堆内存
    • 1.查看堆内存性能数据
    • 2.在浏览器中进行查看
  • 三、goroutine
    • 1.查看goroutine性能数据
  • 四、mutex
    • 1.查看mutex性能数据
  • 五、mutex
    • 1.查看mutex性能数据


前言

pprof性能工具的使用


一、cpu

1.下载实例代码

实例代码地址https://github.com/wolfogre/go-pprof-practice

2.运行项目中的main.go文件

go run main.go

3.查看CPU性能数据

D:\program\goPath\src\bytedance\go-pprof-practice>go tool pprof "http://localhost:6060/debug/pprof/profile?seconds=10"
Fetching profile over HTTP from http://localhost:6060/debug/pprof/profile?seconds=10
Saved profile in C:\Users\helloworld\pprof\pprof.samples.cpu.001.pb.gz
Type: cpu
Time: May 12, 2022 at 8:51am (CST)
Duration: 10.12s, Total samples = 5.43s (53.68%)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) top
Showing nodes accounting for 5.30s, 97.61% of 5.43s total
Dropped 27 nodes (cum <= 0.03s)
Showing top 10 nodes out of 18
      flat  flat%   sum%        cum   cum%
     4.62s 85.08% 85.08%      4.62s 85.08%  bytedance/go-pprof-practic

你可能感兴趣的:(golang,golang,开发语言,后端)