#! /bin/sh

# Complain about unused statistics fields.
t=__wt.$$
trap 'rm -f $t' 0 1 2 3 13 15

# List of files to search: skip stat.c, it lists all of the fields by
# definition.
l=`sed \
    -e '/src\/support\/stat.c/d' \
    -e '/^[a-z]/!d' \
    -e 's/[	 ].*$//' \
    -e 's,^,../,' filelist`
l="$l `echo ../src/include/*.i ../src/include/os.h`"

(
# Get the list of statistics fields.
search=`sed \
    -e 's/^	int64_t \([a-z_*]*\);$/\1/p' \
    -e d ../src/include/stat.h |
    sort`

# There are some fields that are used, but we can't detect it.
cat << UNUSED_STAT_FIELDS
lock_checkpoint_count
lock_checkpoint_wait_application
lock_checkpoint_wait_internal
lock_commit_timestamp_read_count
lock_commit_timestamp_wait_application
lock_commit_timestamp_wait_internal
lock_commit_timestamp_write_count
lock_dhandle_read_count
lock_dhandle_wait_application
lock_dhandle_wait_internal
lock_dhandle_write_count
lock_metadata_count
lock_metadata_wait_application
lock_metadata_wait_internal
lock_read_timestamp_read_count
lock_read_timestamp_wait_application
lock_read_timestamp_wait_internal
lock_read_timestamp_write_count
lock_schema_count
lock_schema_wait_application
lock_schema_wait_internal
lock_table_read_count
lock_table_wait_application
lock_table_wait_internal
lock_table_write_count
lock_txn_global_read_count
lock_txn_global_wait_application
lock_txn_global_wait_internal
lock_txn_global_write_count
UNUSED_STAT_FIELDS

echo "$search"
fgrep -who "$search" $l) | sort | uniq -u > $t

test -s $t && {
	echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
	echo 'unused statistics fields'
	echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
	cat $t
	exit 1
}
exit 0
