以mysqld 进程为例:
[root@VM-90-225-centos ~]
root 9808 9621 0 19:30 pts/7 00:00:00 grep --color=auto mysqld
root 16104 1 0 17:30 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/VM-90-225-centos.pid
mysql 16415 16104 30 17:30 pts/0 00:37:16 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mariadb/mariadb.log --pid-file=/usr/local/mysql/data/VM-90-225-centos.pid --socket=/var/lib/mysql/mysql.sock
[root@VM-90-225-centos ~]
Warning:
PID/TID switch overriding SYSTEM
^C[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.106 MB perf.data (38 samples) ]
关于perf命令参数:
如果像要采样一段时间可以使用:
perf record -a -g -F99 -p 16415 sleep 60
通过上述步骤可以获得perf.data,并保存到你执行命令的目录下
[root@VM-90-225-centos ~]
total 71664
-rw-r--r-- 1 root root 17643311 Jul 15 2021 dtools
drwxr-xr-x 4 root root 4096 Jul 29 2021 go
drwxr-xr-x 7 59314 users 4096 Dec 21 16:15 iGeneral_client_3
-rw-r--r-- 1 root root 55552131 Jan 27 2021 iGeneral_client_3.tgz
-rw------- 1 root root 165944 Feb 24 19:31 perf.data
drwxr--r-- 4 root root 4096 Jul 29 2021 polaris
drwxr-xr-x 22 root root 4096 Jul 29 2021 protobuf
然后继续:
[root@VM-90-225-centos ~]
[root@VM-90-225-centos ~]
-rw-r--r-- 1 root root 46126 Feb 24 19:32 perf.script
然后需要用到FlameGraph的插件,这里手动去下一下:
git clone https://editor.csdn.net/md?not_checkout=1&articleId=123119285
这里我把它保存到/home/hanhan/ 目录下 然后回到script的目录: 执行:
/home/hanhan/FlameGraph/stackcollapse-perf.pl perf.script | /home/hanhan/FlameGraph/flamegraph.pl > report.svg
然后把svg图下载到本地用浏览器打开
|