Kostya Serebryany | 5b7cb1d | 2012-05-10 15:10:03 +0000 | [diff] [blame] | 1 | #!/bin/bash |
Alexey Samsonov | a8bf509 | 2015-12-07 20:18:50 +0000 | [diff] [blame] | 2 | # |
| 3 | # Script that prints information about generated code in TSan runtime. |
Kostya Serebryany | 5b7cb1d | 2012-05-10 15:10:03 +0000 | [diff] [blame] | 4 | |
| 5 | set -e |
| 6 | set -u |
| 7 | |
Alexey Samsonov | a8bf509 | 2015-12-07 20:18:50 +0000 | [diff] [blame] | 8 | if [[ "$#" != 1 ]]; then |
| 9 | echo "Usage: $0 /path/to/binary/built/with/tsan" |
| 10 | exit 1 |
| 11 | fi |
| 12 | |
Kostya Serebryany | 5b7cb1d | 2012-05-10 15:10:03 +0000 | [diff] [blame] | 13 | get_asm() { |
Alexey Samsonov | a8bf509 | 2015-12-07 20:18:50 +0000 | [diff] [blame] | 14 | grep __tsan_$1.: -A 10000 ${OBJDUMP_CONTENTS} | \ |
Kostya Serebryany | 5b7cb1d | 2012-05-10 15:10:03 +0000 | [diff] [blame] | 15 | awk "/[^:]$/ {print;} />:/ {c++; if (c == 2) {exit}}" |
| 16 | } |
| 17 | |
| 18 | list="write1 \ |
| 19 | write2 \ |
| 20 | write4 \ |
| 21 | write8 \ |
| 22 | read1 \ |
| 23 | read2 \ |
| 24 | read4 \ |
| 25 | read8 \ |
| 26 | func_entry \ |
| 27 | func_exit" |
| 28 | |
Alexey Samsonov | a8bf509 | 2015-12-07 20:18:50 +0000 | [diff] [blame] | 29 | BIN=$1 |
| 30 | OUTPUT_DIR=$(mktemp -t -d analyze_libtsan_out.XXXXXXXX) |
| 31 | OBJDUMP_CONTENTS=${OUTPUT_DIR}/libtsan_objdump |
| 32 | NM_CONTENTS=${OUTPUT_DIR}/libtsan_nm |
| 33 | |
| 34 | objdump -d $BIN > ${OBJDUMP_CONTENTS} |
| 35 | nm -S $BIN | grep "__tsan_" > ${NM_CONTENTS} |
Kostya Serebryany | 5b7cb1d | 2012-05-10 15:10:03 +0000 | [diff] [blame] | 36 | |
| 37 | for f in $list; do |
Alexey Samsonov | a8bf509 | 2015-12-07 20:18:50 +0000 | [diff] [blame] | 38 | file=${OUTPUT_DIR}/asm_$f.s |
Kostya Serebryany | 5b7cb1d | 2012-05-10 15:10:03 +0000 | [diff] [blame] | 39 | get_asm $f > $file |
| 40 | tot=$(wc -l < $file) |
Alexey Samsonov | a8bf509 | 2015-12-07 20:18:50 +0000 | [diff] [blame] | 41 | size=$(grep __tsan_$f$ ${NM_CONTENTS} | awk --non-decimal-data '{print ("0x"$2)+0}') |
Kostya Serebryany | 5b7cb1d | 2012-05-10 15:10:03 +0000 | [diff] [blame] | 42 | rsp=$(grep '(%rsp)' $file | wc -l) |
| 43 | push=$(grep 'push' $file | wc -l) |
| 44 | pop=$(grep 'pop' $file | wc -l) |
| 45 | call=$(grep 'call' $file | wc -l) |
| 46 | load=$(egrep 'mov .*\,.*\(.*\)|cmp .*\,.*\(.*\)' $file | wc -l) |
| 47 | store=$(egrep 'mov .*\(.*\),' $file | wc -l) |
| 48 | mov=$(grep 'mov' $file | wc -l) |
| 49 | lea=$(grep 'lea' $file | wc -l) |
| 50 | sh=$(grep 'shr\|shl' $file | wc -l) |
| 51 | cmp=$(grep 'cmp\|test' $file | wc -l) |
| 52 | printf "%10s tot %3d; size %4d; rsp %d; push %d; pop %d; call %d; load %2d; store %2d; sh %3d; mov %3d; lea %3d; cmp %3d\n" \ |
| 53 | $f $tot $size $rsp $push $pop $call $load $store $sh $mov $lea $cmp; |
| 54 | done |