| #!/bin/bash |
| |
| tmp=tmp-bench-size-$$ |
| |
| if [ `uname` = "Darwin" ] ; then |
| # e.g., `total 20986192` |
| totalawk='$1 == "total" {print $2}' |
| # e.g., ` Section __text: 1445477` |
| otherawk='$2 == "__%s:" {print $3}' |
| size -m "$1" > $tmp |
| else |
| x=`which gsize` |
| # e.g., `Total 3879861` |
| totalawk='$1 == "Total" {print $2}' |
| # e.g., `.text 1269331 4207296` |
| # Field 2 is size, field 3 is address. |
| otherawk='$1 == ".%s" {print $2}' |
| if [ "x$x" = "x" ] ; then |
| size -A "$1" > $tmp |
| else |
| "$x" -A "$1" > $tmp |
| fi |
| fi |
| |
| # $1: size output file |
| # $2: section name (without leading .) |
| function find_section() { |
| cmd="$(printf "${otherawk}" $2)" |
| out=$(awk -Wposix "${cmd}" < $1) |
| if [[ "${out}" == "" ]]; then |
| echo 0 |
| else |
| echo ${out} |
| fi |
| } |
| |
| |
| # note total is different |
| total=$(awk -Wposix "${totalawk}" < ${tmp}) |
| |
| text=$(find_section "${tmp}" "text") |
| gopclntab=$(find_section "${tmp}" "gopclntab") |
| rodata=$(find_section "${tmp}" "rodata") |
| data=$(find_section "${tmp}" "data") |
| |
| zdebug_info=$(find_section "${tmp}" "zdebug_info") |
| zdebug_loc=$(find_section "${tmp}" "zdebug_loc") |
| zdebug_line=$(find_section "${tmp}" "zdebug_line") |
| zdebug_ranges=$(find_section "${tmp}" "zdebug_ranges") |
| zdebug_frame=$(find_section "${tmp}" "zdebug_frame") |
| zdebug_abbrev=$(find_section "${tmp}" "zdebug_abbrev") |
| zdebug_pubname=$(find_section "${tmp}" "zdebug_pubname") |
| zdebug_pubtype=$(find_section "${tmp}" "zdebug_pubtype") |
| |
| echo "goos: $GOOS" |
| echo "goarch: $GOARCH" |
| echo "pkg:" # Erase any inherited pkg if files are concatenated |
| |
| if echo $total | egrep -q '[0-9]+' ; then |
| echo Unit total-bytes assume=exact |
| echo "Benchmark${2}" 1 ${total} total-bytes |
| fi |
| |
| if echo $text | egrep -q '[0-9]+' ; then |
| echo Unit text-bytes assume=exact |
| echo "Benchmark${2}" 1 ${text} text-bytes |
| fi |
| |
| if echo $data | egrep -q '[0-9]+' ; then |
| echo Unit data-bytes assume=exact |
| echo "Benchmark${2}" 1 ${data} data-bytes |
| fi |
| |
| if echo $rodata | egrep -q '[0-9]+' ; then |
| echo Unit rodata-bytes assume=exact |
| echo "Benchmark${2}" 1 ${rodata} rodata-bytes |
| fi |
| |
| if echo $gopclntab | egrep -q '[0-9]+' ; then |
| echo Unit pclntab-bytes assume=exact |
| echo "Benchmark${2}" 1 ${gopclntab} pclntab-bytes |
| fi |
| |
| zdebug=`expr ${zdebug_info} + ${zdebug_loc} + ${zdebug_line} + ${zdebug_ranges} + ${zdebug_frame} + ${zdebug_abbrev} + ${zdebug_pubname} + ${zdebug_pubtype}` |
| |
| if echo $zdebug | egrep -q '[0-9]+' ; then |
| echo Unit zdebug-bytes assume=exact |
| echo "Benchmark${2}" 1 ${zdebug} zdebug-bytes |
| fi |
| |
| rm $tmp |