get_metrics.sh: use git-grep to cut runtime by >70%
This script currently spends ~16s computing the all_tests variable.
The bulk of this comes from the `grep -r` command to list all #include's
of <kunit/test.h>.
Using git-grep is ~always going to be faster than a `grep -r` which has
to consult the filesystem to find all the files.
Before: `time` output:
real 0m30.015s
user 0m26.132s
sys 0m4.297s
After first git-grep conversion:
real 0m15.371s
user 0m14.138s
sys 0m3.077s
After second (test_case_num)
real 0m8.826s
user 0m9.238s
sys 0m1.800s
Change-Id: If0ee078415179463f34024e45d4290d9f2304dae
Signed-off-by: Daniel Latypov <dlatypov@google.com>
diff --git a/get_metrics.sh b/get_metrics.sh
index 35f3cb6..6a75d0c 100755
--- a/get_metrics.sh
+++ b/get_metrics.sh
@@ -12,7 +12,7 @@
not_tests='lib/kunit/test.c
'
-all_tests=$(for file_name in $(grep -Hrnl -e '#include <kunit/test.h>' | grep -E 'test|_kunit\.c' | grep -v '^Documentation')
+all_tests=$(for file_name in $(git grep -l -e '#include <kunit/test.h>' | grep -E 'test|_kunit\.c' | grep -v '^Documentation')
do
if [[ ! $not_tests =~ (^|[[:space:]])"$file_name"($|[[:space:]]) ]] ; then
printf "$file_name\n"
@@ -22,8 +22,7 @@
tests_total_num=$(echo "$all_tests" | wc -l)
test_authors=$(git --no-pager shortlog --no-merges -n -s -- $all_tests)
test_author_num=$(echo "$test_authors" | wc -l)
-test_case_num=$(find ./ -type f ! -wholename '*/Documentation/*' ! -name 'test.h' ! -name 'get_metrics.sh' -print0 |
- xargs -0 grep 'KUNIT_CASE' | wc -l)
+test_case_num=$(git grep 'KUNIT_CASE' | grep -Ev '^Documentation/|get_metrics.sh|include/kunit/test.h' | wc -l)
if [[ -n $VERBOSE ]]; then