使用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/

猜你喜欢

转载自www.cnblogs.com/rongfengliang/p/12097184.html
今日推荐