美文网首页
perf分析C++性能

perf分析C++性能

作者: vilian_acfc | 来源:发表于2019-04-10 15:26 被阅读0次
    使用脚本
    
    #! /bin/sh
    
    perf_ver=`perf --version`
    
    if [[ ! $perf_ver =~ "perf version" ]]
    
    then
    
      echo "perf is not installed yet. please use 'yum -y install perf' to install first."
    
      exit 1
    
    fi
    
    if [[ ! -n "$1" ]] || [[ ! -n "$2" ]]
    
    then
    
    echo "$0 进程id 抓取时间"
    
    exit 1
    
    fi
    
    flameGraph=/data/vilian/tools/FlameGraph
    
    output=/data/vilian/svg
    
    file=$RANDOM
    
    if [[ ! -d "$flameGraph" ]]
    
    then
    
      echo "flameGraph is not exist. please use 'git clone https://github.com/brendangregg/FlameGraph.git' to get it."
    
      exit 1
    
    fi
    
    if [[ ! -d "$output" ]]
    
    then
    
      mkdir -p $output
    
    fi
    
    cd $output
    
    if [[ ! -n "perf.data" ]]
    
    then
    
    `rm -f perf.data`
    
    fi
    
    timeout $2 perf record -e cpu-clock -g -p $1
    
    `perf script -i perf.data &> perf$file.unfold`
    
    `$flameGraph/stackcollapse-perf.pl perf$file.unfold &> perf$file.folded`
    
    `$flameGraph/flamegraph.pl perf$file.folded > perf$file.svg`
    
    echo "output=$output/perf$file.svg"
    
    

    相关文章

      网友评论

          本文标题:perf分析C++性能

          本文链接:https://www.haomeiwen.com/subject/maaniqtx.html