2017年12月8日星期五

MySQL FlameGraph

MySQL  FlameGraph

https://poormansprofiler.org/
http://www.brendangregg.com/FlameGraphs/cpuflamegraphs.html#perf
https://github.com/brendangregg/FlameGraph/
http://queue.acm.org/detail.cfm?id=2927301

method1 gdb
https://github.com/brendangregg/FlameGraph/blob/master/stackcollapse-gdb.pl

#!/bin/sh
for x in $(seq 1 5)
do
     gdb -ex "set pagination 0" -ex "thread apply all bt" -batch -p `pidof mysqld` >> gdb.txt
     sleep 0.01
done

cat gdb.txt | perl stackcollapse-gdb.pl > out.gdb-folded
perl flamegraph.pl out.gdb-folded > gdb-mysql.svg


method2 perf
https://github.com/brendangregg/FlameGraph/blob/master/stackcollapse-perf.pl
https://github.com/torvalds/linux/tree/master/tools/perf/Documentation

perf record -a -g -F 997 --pid `pidof mysqld` sleep 60
perf script | /home/soft/FlameGraph/stackcollapse-perf.pl > out.perf-folded
/home/soft/FlameGraph/flamegraph.pl out.perf-folded > perf-mysql.svg



Off-CPU
http://www.brendangregg.com/blog/2015-02-26/linux-perf-off-cpu-flame-graph.html
http://oliveryang.net/2015/07/linux-scheduler-profiling-2/
https://github.com/openresty/stapxx
https://github.com/openresty/nginx-systemtap-toolkit


perf script -F comm,pid,tid,cpu,time,period,event,ip,sym,dso | awk '
    NF > 4 { exec = $1; period_ms = int($5 / 1000000) }
    NF > 1 && NF <= 4 && period_ms > 0 { print $2 }
    NF < 2 && period_ms > 0 { printf "%s\n%d\n\n", exec, period_ms }' | \
    /home/soft/FlameGraph/stackcollapse.pl | \
   /home/soft/FlameGraph/flamegraph.pl --countname=ms --title="Off-CPU Time Flame Graph" --colors=io > offcpu.svg
 
 

没有评论:

发表评论