#!/bin/sh if [ $# -ne 3 ] then echo "Usage: ./`basename $0` lua/c PID NAME" exit fi pid=$2 name=$3 if [ ! -d /opt/openresty-systemtap-toolkit ];then cd /opt && git clone https://github.com/openresty/openresty-systemtap-toolkit fi if [ ! -d /opt/FlameGraph ];then cd /opt && git clone https://github.com/brendangregg/FlameGraph fi if [ $1 == "lua" ]; then /opt/openresty-systemtap-toolkit/ngx-sample-lua-bt -p $pid --luajit20 -t 30 >temp.bt /opt/openresty-systemtap-toolkit/fix-lua-bt temp.bt >${name}.bt elif [ $1 == "c" ]; then /opt/nginx-systemtap-toolkit/sample-bt -p $pid -t 10 -u > ${name}.bt else echo "type is only lua/c" exit fi /opt/FlameGraph/stackcollapse-stap.pl ${name}.bt >${name}.cbt /opt/FlameGraph/flamegraph.pl ${name}.cbt >${name}.svg rm -f temp.bt ${name}.bt ${name}.cbt