使用pprof 分析perf 数据

对于perf 工具提供的指标数据,我们可以使用自带的report 以及script 进行查看,同时对于火焰图使用
flamescope 也挺不错,但是如果需要跨平台分析使用pprof结合perf_data_converter 就很方便了,以下
是一个简单的集成使用

perf_data_converter构建使用centos系统

安装perf_data_converter

这个需要构建工具的支持bazel,一些依赖

  • 安装依赖
 
yum install -y elfutils-libelf-devel
yum install -y libcap-devel
  • clone 代码
git clone https://github.com/google/perf_data_converter.git
cd perf_data_converter
bazel build src:perf_to_profile
  • 配置环境变量
    添加perf_data_converter到path 路径

生成一个perf.data 数据

  • 命令
perf record 

转换perf.data

  • 命令
perf_to_profile -i perf.data -o perf-convert
  • 效果
perf_to_profile -i perf.data -o perf-convert
[WARNING:src/quipper/perf_reader.cc:1036] Skipping unsupported event PERF_RECORD_CPU_MAP
[INFO:src/quipper/perf_reader.cc:1027] Number of events stored: 152820
[INFO:src/quipper/perf_parser.cc:268] Parser processed: 3418 MMAP/MMAP2 events, 593 COMM events, 724 FORK events, 169 EXIT events, 146065 SAMPLE events, 144231 of these were mapped
[INFO:src/perf_data_handler.cc:88] Using the build id found for the file name: [kernel.kallsyms], build id: 14504bc038206548e6bb85f4812ead4c3bb427f4.
[INFO:src/perf_data_handler.cc:476] guessing main for pid: 1 /usr/lib/systemd/systemd
[INFO:src/perf_data_handler.cc:476] guessing main for pid: 10415 /usr/lib/systemd/systemd-udevd
[INFO:src/perf_data_handler.cc:476] guessing main for pid: 10503 /usr/libexec/pcp/bin/pmwebd
[INFO:src/perf_data_handler.cc:476] guessing main for pid: 18404 /usr/libexec/pcp/bin/pmproxy
[INFO:src/perf_data_handler.cc:476] guessing main for pid: 4147 /usr/lib/systemd/systemd-journald
[INFO:src/perf_data_handler.cc:476] guessing main for pid: 6618 /usr/libexec/pcp/bin/pmcd
[INFO:src/perf_data_handler.cc:476] guessing main for pid: 777 /usr/lib/systemd/systemd-logind;5df33705 (deleted)
[INFO:src/perf_data_handler.cc:476] guessing main for pid: 783 /usr/lib/polkit-1/polkitd
[WARNING:src/perf_data_handler.cc:349] stat: missing_callchain_mmap 150999/1287082

使用pprof分析

  • pprof 支持的命令
callgrind Outputs a graph in callgrind format
comments Output all profile comments
disasm Output assembly listings annotated with samples
dot Outputs a graph in DOT format
eog Visualize graph through eog
evince Visualize graph through evince
gif Outputs a graph image in GIF format
gv Visualize graph through gv
kcachegrind Visualize report in KCachegrind
list Output annotated source for functions matching regexp
pdf Outputs a graph in PDF format
peek Output callers/callees of functions matching regexp
png Outputs a graph image in PNG format
proto Outputs the profile in compressed protobuf format
ps Outputs a graph in PS format
raw Outputs a text representation of the raw profile
svg Outputs a graph in SVG format
tags Outputs all tags in the profile
text Outputs top entries in text form
top Outputs top entries in text form
topproto Outputs top entries in compressed protobuf format
traces Outputs all profile samples in text form
tree Outputs a text rendering of call graph
web Visualize graph through web browser
weblist Display annotated source in a web browser
o/options List options and their current values
quit/exit/^D Exit pprof
  • 安装pprof
go get -u github.com/google/pprof
  • 分析生成的perf 数据
    加载perf data:
 
pprof perf-convert

简单分析(text):

 

 


过滤处理

 

 

说明

pprof 功能强大,分析golang以及perf 都是很不错的工具,而且可以作为package 集成到golang 应用中,分析系统性能是
很方便的

参考资料

https://github.com/google/perf_data_converter
https://github.com/google/pprof
https://cizixs.com/2017/09/11/profiling-golang-program/

posted on   荣锋亮  阅读(1933)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2018-12-25 debezium mongodb 集成测试
2018-12-25 debezium sql server 集成
2018-12-25 ipfs cluster 模式部署使用(docker-compose 环境运行)
2016-12-25 Sonar安装配置
2016-12-25 SpringCloud Sleuth 使用
2013-12-25 zeroMQ 学习
2013-12-25 SocketIO4Net.Client

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示