Created
July 29, 2016 06:00
-
-
Save JesseEisen/b189ac76178f21fb946e296f53dc98ab to your computer and use it in GitHub Desktop.
count and compare nm command output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
#usage: | |
#first step: generate the output | |
# nm -S --size-sort xxx1 > nm_output1 | |
# nm -S --size-sort xxx2 > nm_output2 | |
#second step: generate the count or diff | |
# ./nmcmp.sh nm_output1 nm_output2 | |
# ./nmcmp.sh -d nm_output1 nm_output2 ##this will output with diff format. | |
read -d '' awkscript << 'EOF' | |
{ | |
if(NF == 1) | |
next | |
$5 =sprintf("%d","0x"$2) | |
Res[$3] += $5 | |
} | |
END{ | |
for(key in Res) | |
{ | |
printf("%s:%d\n",key, Res[key]) | |
count+=Res[key] | |
} | |
printf("total:%d\n",count); | |
} | |
EOF | |
ask() { | |
local answer green color_off | |
green="\033[32m" | |
color_off="\033[0m" | |
args=$(printf '%q ' "$@") | |
printf '%s: Do you want to run "%b%s%b"? [y/N] ' "$0" "$green" "${args% }" "$color_off" | |
read -s -n1 answer | |
echo | |
case $answer in | |
([Yy]) "$@";; | |
esac | |
} | |
i=0 | |
flag=0 | |
moreThanTwo=1 | |
while (( "$#" )); do | |
if [[ $1 = '-d' ]]; then | |
flag=1 | |
shift | |
continue | |
fi | |
if [ -f "$1" ] ; then | |
tmpfile="nmDiff_""$1""_""$i" | |
printf "file %s detail: \n" "$1" > "$tmpfile" | |
printf "%s\n" "===========================" >> "$tmpfile" | |
awk --non-decimal-data "$awkscript" "$1" | sed 's/n/\n/g' | sort >> "$tmpfile" | |
printf "%s\n\n" "============================" >> "$tmpfile" | |
shift | |
((i+=1)) | |
else | |
printf '%s is not exsist\n' "$1" | |
echo | |
moreThanTwo=0 | |
shift | |
fi | |
done | |
if (($flag == 1 && $moreThanTwo == 1)); then | |
diff nmDiff* -y -W 80 | |
else | |
cat nmDiff* | |
fi | |
ask rm -rf nmDiff* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment