Makefile.rules: Add targets to see file size differences

Since the ec binaries are so tight on space, it would be nice to be
able to see just how much changes are affecting the size.  This allows
users to easily do before/after comparisons.

Sample output:
build/sweetberry/RW/ec.RW.flat shrank by 44 bytes: (43828 to 43784)
build/twinkie/RO/ec.RO.flat shrank by 64 bytes: (46312 to 46248)
build/twinkie/RW/ec.RW.flat shrank by 40 bytes: (45900 to 45860)
build/wheatley/RW/ec.RW.flat shrank by 40 bytes: (102692 to 102652)
Compared 156 of 156 files.
81 files changed.
Total size change: -3100 bytes.
Average size change: -38 bytes.

BRANCH=none
BUG=none
TEST=make clobber buildall -j; make savesizes
[change some code that changes file sizes]
make clobber buildall -j ; make newsizes
[Shows size differences]

Change-Id: I48b440063eb6eb6c00900af3d0dfa075be6f9ec7
Signed-off-by: Martin Roth <martinroth@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/410860
Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
This commit is contained in:
Martin Roth 2016-11-12 14:45:33 -07:00 committed by chrome-bot
parent ae632fa21e
commit c66d36761f
2 changed files with 63 additions and 0 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@ TAGS
cscope.*
.tests-passed
.failedboards/
.sizes.txt

View File

@ -7,6 +7,9 @@
# Embedded Controller firmware build system - common targets
#
FLATSIZE_FILE ?= .sizes.txt
BUILD_DIR := $(firstword $(subst /, ,$(out)))
build-utils := $(foreach u,$(build-util-bin),$(out)/util/$(u))
host-utils := $(foreach u,$(host-util-bin),$(out)/util/$(u))
build-srcs := $(foreach u,$(build-util-bin),$(sort $($(u)-objs:%.o=util/%.c) util/$(u).c))
@ -386,6 +389,65 @@ clean:
clobber:
-rm -rf build TAGS cscope.files cscope.out
.PHONY: savesizes
savesizes:
@find $(BUILD_DIR) -name '*.flat' -printf "%s %p\n" | sort --key 2 > \
$(FLATSIZE_FILE)
@if [ -s $(FLATSIZE_FILE) ]; then \
echo "Saved sizes for $$(cat $(FLATSIZE_FILE) | wc -l) files"; \
else \
echo "Error: No file sizes saved. Are they built?"; \
fi
.PHONY: newsizes
newsizes:
@if [ ! -s "$(FLATSIZE_FILE)" ]; then \
echo "Error: no saved size file ($(FLATSIZE_FILE))."; \
echo " Run 'make savesizes' first"; \
exit 1; \
fi
@FILES_CHANGED=0; \
FILES_IN_LIST=0; \
FILES_COMPARED=0; \
FILE_SIZE_CHANGE=0; \
NEW_SIZES=$$(find $(BUILD_DIR) -name '*.flat' -printf "%s %p\n"); \
while read -r -u 10 line; do \
FILES_IN_LIST=$$((FILES_IN_LIST+1)); \
FLATFILE=$$(echo "$$line" | cut -f2 -d ' '); \
FLATSIZE_ORG=$$(echo "$$line" | cut -f1 -d ' '); \
FLATSIZE_NEW="$$(grep "$$FLATFILE" <<< "$$NEW_SIZES" | \
sed 's/ .*$$//')"; \
if [ -n "$$FLATSIZE_NEW" ]; then \
FILES_COMPARED=$$((FILES_COMPARED+1)); \
if [ "$$FLATSIZE_NEW" -gt "$$FLATSIZE_ORG" ]; then \
FILES_CHANGED=$$((FILES_CHANGED+1)); \
FILE_SIZE_CHANGE=$$((FILE_SIZE_CHANGE+ \
FLATSIZE_NEW-FLATSIZE_ORG)); \
printf "%s grew by %s bytes: (%d to %d)\n" \
"$$FLATFILE" \
"$$((FLATSIZE_NEW-FLATSIZE_ORG))" \
"$$FLATSIZE_ORG" "$$FLATSIZE_NEW"; \
elif [ "$$FLATSIZE_NEW" -lt "$$FLATSIZE_ORG" ]; then \
FILES_CHANGED=$$((FILES_CHANGED+1)); \
FILE_SIZE_CHANGE=$$((FILE_SIZE_CHANGE+ \
FLATSIZE_NEW-FLATSIZE_ORG)); \
printf "%s shrank by %s bytes: (%d to %d)\n" \
"$$FLATFILE" \
"$$((FLATSIZE_ORG-FLATSIZE_NEW))" \
"$$FLATSIZE_ORG" "$$FLATSIZE_NEW"; \
fi; \
fi; \
done 10< "$(FLATSIZE_FILE)"; \
echo "Compared $$FILES_COMPARED of $$FILES_IN_LIST files."; \
if [ $$FILES_COMPARED -ne 0 ] && [ $$FILES_CHANGED -eq 0 ]; then \
echo "File sizes are unchanged."; \
else \
printf "%d files changed.\n" "$$FILES_CHANGED"; \
printf "Total size change: %s bytes.\n" "$$FILE_SIZE_CHANGE"; \
printf "Average size change: %d bytes.\n" \
"$$((FILE_SIZE_CHANGE / FILES_CHANGED))"; \
fi
.SECONDARY:
-include $(deps)