summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Roth <martinroth@chromium.org>2016-11-12 14:45:33 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-11-15 17:43:21 -0800
commitc66d36761f9b590f10218a434e0cf9a320fd4424 (patch)
tree662df317cecd847044f39b8708ceb5fe74423c87
parentae632fa21e14dd0e345cdef876268c6ffd8c13cb (diff)
downloadchrome-ec-c66d36761f9b590f10218a434e0cf9a320fd4424.tar.gz
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>
-rw-r--r--.gitignore1
-rw-r--r--Makefile.rules62
2 files changed, 63 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index f2d61eabaa..cd7ce6b7b7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ TAGS
cscope.*
.tests-passed
.failedboards/
+.sizes.txt
diff --git a/Makefile.rules b/Makefile.rules
index 4d028149e7..f1bd06374b 100644
--- a/Makefile.rules
+++ b/Makefile.rules
@@ -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)