對於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/