count_invalid_enforce.sh 2.8 KB
Newer Older
1
#!/bin/bash
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

# This script is used to count all PADDLE checks in the paddle/fluid directory,
#   including the total PADDLE check number, the valid check number and the
#   invalid check number under paddle/fluid and its main sub-directories.

# Usage: bash count_invalid_enforce.sh (run in tools directory)

# Result Example:

#     ../paddle/fluid/framework - total: 1065, valid: 267, invalid: 798
#     ../paddle/fluid/imperative - total: 135, valid: 118, invalid: 17
#     ../paddle/fluid/inference - total: 449, valid: 158, invalid: 291
#     ../paddle/fluid/memory - total: 60, valid: 10, invalid: 50
#     ../paddle/fluid/operators - total: 4225, valid: 1061, invalid: 3164
#     ../paddle/fluid/platform - total: 240, valid: 39, invalid: 201
#     ../paddle/fluid/pybind - total: 98, valid: 53, invalid: 45
#     ../paddle/fluid/string - total: 0, valid: 0, invalid: 0
#     ../paddle/fluid/testdata - total: 0, valid: 0, invalid: 0
#     ../paddle/fluid/train - total: 6, valid: 0, invalid: 6
#     ----------------------------
#     PADDLE ENFORCE & THROW COUNT
#     ----------------------------
#     All PADDLE_ENFORCE{_**} & PADDLE_THROW Count: 6278
#     Valid PADDLE_ENFORCE{_**} & PADDLE_THROW Count: 1706
#     Invalid PADDLE_ENFORCE{_**} & PADDLE_THROW Count: 4572

ROOT_DIR=../paddle/fluid
ALL_PADDLE_CHECK_CNT=0
VALID_PADDLE_CHECK_CNT=0

function enforce_scan(){
33
    paddle_check=`grep -r -zoE "(PADDLE_ENFORCE[A-Z_]{0,9}|PADDLE_THROW)\(.[^,\);]*.[^;]*\);\s" $1 || true`
34
    total_check_cnt=`echo "$paddle_check" | grep -cE "(PADDLE_ENFORCE|PADDLE_THROW)" || true`
35
    valid_check_cnt=`echo "$paddle_check" | grep -zoE '(PADDLE_ENFORCE[A-Z_]{0,9}|PADDLE_THROW)\((.[^,;]+,)*.[^";]*(errors::).[^"]*".[^";]{20,}.[^;]*\);\s' | grep -cE "(PADDLE_ENFORCE|PADDLE_THROW)" || true`
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
    eval $2=$total_check_cnt
    eval $3=$valid_check_cnt
}

function walk_dir(){
    for file in `ls $1`
    do
        if [ -d $1"/"$file ];then
            level=$(($2+1))
            if [ $level -le 1 ]; then
                enforce_scan $1"/"$file total_check_cnt valid_check_cnt
                echo $1"/"$file" - total: ${total_check_cnt}, valid: ${valid_check_cnt}, invalid: $(($total_check_cnt-$valid_check_cnt))"
                ALL_PADDLE_CHECK_CNT=$(($ALL_PADDLE_CHECK_CNT+$total_check_cnt))
                VALID_PADDLE_CHECK_CNT=$(($VALID_PADDLE_CHECK_CNT+$valid_check_cnt))
                walk_dir $1"/"$file $level
            fi
        fi
    done
}

walk_dir $ROOT_DIR 0
57 58 59 60 61 62 63

echo "----------------------------"
echo "PADDLE ENFORCE & THROW COUNT"
echo "----------------------------"
echo "All PADDLE_ENFORCE{_**} & PADDLE_THROW Count: ${ALL_PADDLE_CHECK_CNT}"
echo "Valid PADDLE_ENFORCE{_**} & PADDLE_THROW Count: ${VALID_PADDLE_CHECK_CNT}"
echo "Invalid PADDLE_ENFORCE{_**} & PADDLE_THROW Count: $(($ALL_PADDLE_CHECK_CNT-$VALID_PADDLE_CHECK_CNT))"