Shell 实现 提取特定函数列表,并统计函数被调用次数

来源:互联网 发布:南宁市广电网络营业厅 编辑:程序博客网 时间:2024/06/07 22:19
写了个脚本,与大家分享下
######################################################Author : yelang#Date   : 2013-04-17#Desc   : 查找所有的头文件,并提取出其中的所有函数,#         将以“ecore_x”开头的函数追加到函数列表。#####################################################headers="/home/inno/headers"funclist="/home/inno/funclist"cat /dev/null > $headerscat /dev/null > $funclistecho "Now we find all header files........"find . -regex ".*\.\(h\)" > $headerscat $headers | while read headerNamedo    cat $headerName | while read line    do        echo $line | grep "[1-9a-zA-Z_](" | awk -F "(" '{print $1}' | awk '{print $NF}'| grep "^ecore_x" >> $funclist    donedone

######################################################Author : yelang#Date   : 2013-04-17#Desc   : 通过函数列表统计每个函数被应用程序调用#         的次数,并将结果保存到文件。#####################################################result="/home/inno/result"pathSet="/home/inno/pathSet"cat /dev/null > $resultcat /dev/null > $pathSetecho "Now we find all cpp and c files"find . -regex ".*\.\(cpp\|c\)" > $pathSetfor funcName in $(cat $1)do    echo "=========================== $funcName ===========================" >> $result     while read filename    do        count=`cat $filename | grep $funcName | wc -l`        echo "$filename find $funcName  $count  "        if [ $count -ne 0 ];then            mesg="$filename    $count"            echo $mesg >> $result        fi    done < $pathSetdone