[sheepdog] [PATCH 1/2] make: add 'check-ununsed' command

Liu Yuan namei.unix at gmail.com
Sun Sep 1 12:11:19 CEST 2013


'make check-unused' will try to find the possible unused functions that is
defined but used functions.

E.g

yliu at ubuntu-precise:~/sheepdog$ make check-unused
recalculate_vnodes
object_cache_try_to_reclaim
default_cleanup
default_create_and_write
default_exist
default_format
default_get_hash
default_init
default_link
default_purge_obj
default_read
default_remove_object
default_update_epoch
default_write
get_max_copy_number
...

functions listed above are either
1) defined but not used by other c files, indicating that we should define them
static functions
2) defined but not used at all, indicating that we should remove them completely

Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 Makefile.am |    8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/Makefile.am b/Makefile.am
index 81f4a09..0e4ef22 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -94,6 +94,14 @@ check-style:
 		make -C $$dir check-style CHECK_STYLE="$(CHECK_STYLE)"; \
 	done
 
+check-unused:
+	@find -name '*.o' -exec nm -o {} \; | grep -v '^./lib' | grep ' U ' | \
+		awk '{print $$3;}' | uniq > /tmp/sd_used
+	@find -name '*.o' -exec nm -o {} \; | grep -v '^./lib' | grep ' T ' | \
+		awk '{print $$3;}' > /tmp/sd_defined
+	@while read func;do if ! grep -Fq $$func /tmp/sd_used;then \
+		echo $$func; fi; done < /tmp/sd_defined
+
 if BUILD_COVERAGE
 coverage: clean check
 	@rm -rf coverage
-- 
1.7.9.5




More information about the sheepdog mailing list