diff options
author | Martin Roth <martinroth@chromium.org> | 2016-11-12 14:45:33 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2016-11-17 00:00:17 +0000 |
commit | b9f28173a78af6923e50cd7a0388c4873e5f2ab1 (patch) | |
tree | 8ebbc0c08dca6a4562813ee8f30db9620af5f252 | |
parent | 64a204900f6ed0bc92f5d514e61420ba2c7f325e (diff) | |
download | chrome-ec-b9f28173a78af6923e50cd7a0388c4873e5f2ab1.tar.gz |
CHERRY-PICK: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: I3dbb93f517473007b7bd9ca0a7beaca24b9f330f
ORIG-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>
Signed-off-by: james_chao <james_chao@asus.com>
Reviewed-on: https://chromium-review.googlesource.com/411665
Reviewed-by: Shawn N <shawnn@chromium.org>
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile.rules | 62 |
2 files changed, 63 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore index a024f1eedd..899ac60f98 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ tags TAGS cscope.* .tests-passed +.sizes.txt diff --git a/Makefile.rules b/Makefile.rules index 1f776303ff..666abfd10c 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)) @@ -348,6 +351,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) |