From 3bf15e71d3e9f7d3512f44063fc8cdccc06834ce Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Mon, 25 Jul 2016 16:03:53 -0700 Subject: [PATCH] Record module type statistics Creates a build_system_stats.txt build artifact that contains statistics on how many BUILD_* modules are defined in a build. Also writes out information about the Soong module types sent from the Soong build. Merged-In: Iaf0c7062f542dc6942b5349854f3d49267cac4a5 Change-Id: Iaf0c7062f542dc6942b5349854f3d49267cac4a5 --- core/Makefile | 9 ++++++ core/base_rules.mk | 3 ++ core/clear_vars.mk | 1 + core/copy_headers.mk | 1 + core/definitions.mk | 42 +++++++++++++++++++++++++ core/droiddoc.mk | 1 + core/executable.mk | 1 + core/fuzz_test.mk | 1 + core/host_dalvik_java_library.mk | 1 + core/host_dalvik_static_java_library.mk | 1 + core/host_executable.mk | 1 + core/host_fuzz_test.mk | 1 + core/host_java_library.mk | 2 ++ core/host_native_test.mk | 1 + core/host_prebuilt.mk | 1 + core/host_shared_library.mk | 1 + core/host_static_library.mk | 1 + core/host_static_test_lib.mk | 1 + core/java_library.mk | 1 + core/multi_prebuilt.mk | 1 + core/native_benchmark.mk | 1 + core/native_test.mk | 1 + core/notice_files.mk | 1 + core/package.mk | 2 ++ core/phony_package.mk | 1 + core/prebuilt.mk | 1 + core/shared_library.mk | 1 + core/static_java_library.mk | 1 + core/static_library.mk | 1 + core/static_test_lib.mk | 1 + 30 files changed, 83 insertions(+) diff --git a/core/Makefile b/core/Makefile index c86c499272..7b521930b8 100644 --- a/core/Makefile +++ b/core/Makefile @@ -399,6 +399,15 @@ ifdef CREATE_MODULE_INFO_FILE "INSTALLED=\"$(strip $(ALL_MODULES.$(m).INSTALLED))\"" >> $(MODULE_INFO_FILE))) endif +# ----------------------------------------------------------------- +# build system stats +BUILD_SYSTEM_STATS := $(PRODUCT_OUT)/build_system_stats.txt +$(BUILD_SYSTEM_STATS): + @rm -f $@ + @$(foreach s,$(STATS.MODULE_TYPE),echo "modules_type_make,$(s),$(words $(STATS.MODULE_TYPE.$(s)))" >>$@;) + @$(foreach s,$(STATS.SOONG_MODULE_TYPE),echo "modules_type_soong,$(s),$(STATS.SOONG_MODULE_TYPE.$(s))" >>$@;) +$(call dist-for-goals,droidcore,$(BUILD_SYSTEM_STATS)) + # ----------------------------------------------------------------- # The dev key is used to sign this package, and as the key required diff --git a/core/base_rules.mk b/core/base_rules.mk index 8a1c5eeab7..39ba8224fc 100644 --- a/core/base_rules.mk +++ b/core/base_rules.mk @@ -14,6 +14,9 @@ # limitations under the License. # +# Catch users that directly include base_rules.mk +$(call record-module-type,base_rules) + # Users can define base-rules-hook in their buildspec.mk to perform # arbitrary operations as each module is included. ifdef base-rules-hook diff --git a/core/clear_vars.mk b/core/clear_vars.mk index 31b337a130..f1a959253e 100644 --- a/core/clear_vars.mk +++ b/core/clear_vars.mk @@ -200,6 +200,7 @@ LOCAL_NOTICE_FILE:= LOCAL_REPLACE_PREBUILT_APK_INSTALLED:= LOCAL_NDK_VERSION:=current LOCAL_LOGTAGS_FILES:= +LOCAL_RECORDED_MODULE_TYPE:= # arch specific variables LOCAL_SRC_FILES_$(TARGET_ARCH):= diff --git a/core/copy_headers.mk b/core/copy_headers.mk index 7d5a5d9922..417a76cc23 100644 --- a/core/copy_headers.mk +++ b/core/copy_headers.mk @@ -1,6 +1,7 @@ ########################################################### ## Copy headers to the install tree ########################################################### +$(call record-module-type,COPY_HEADERS) ifneq ($(strip $(LOCAL_IS_HOST_MODULE)),) my_prefix := HOST_ else diff --git a/core/definitions.mk b/core/definitions.mk index afb4558d25..36d80808c9 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -2840,6 +2840,48 @@ $(strip $(if $(filter $(TARGET_ARCH),$(1)),$(TARGET_ARCH),\ $(if $(filter $(TARGET_2ND_ARCH),$(1)),$(TARGET_2ND_ARCH),$(if $(1),none)))) endef +# ############################################################### +# Set up statistics gathering +# ############################################################### +STATS.MODULE_TYPE := \ + HOST_STATIC_LIBRARY \ + HOST_SHARED_LIBRARY \ + STATIC_LIBRARY \ + SHARED_LIBRARY \ + EXECUTABLE \ + HOST_EXECUTABLE \ + PACKAGE \ + PHONY_PACKAGE \ + HOST_PREBUILT \ + PREBUILT \ + MULTI_PREBUILT \ + JAVA_LIBRARY \ + STATIC_JAVA_LIBRARY \ + HOST_JAVA_LIBRARY \ + DROIDDOC \ + COPY_HEADERS \ + NATIVE_TEST \ + NATIVE_BENCHMARK \ + HOST_NATIVE_TEST \ + FUZZ_TEST \ + HOST_FUZZ_TEST \ + STATIC_TEST_LIBRARY \ + HOST_STATIC_TEST_LIBRARY \ + NOTICE_FILE \ + HOST_DALVIK_JAVA_LIBRARY \ + HOST_DALVIK_STATIC_JAVA_LIBRARY \ + base_rules + +$(foreach $(s),$(STATS.MODULE_TYPE),$(eval STATS.MODULE_TYPE.$(s) :=)) +define record-module-type +$(strip $(if $(LOCAL_RECORDED_MODULE_TYPE),, + $(if $(filter-out $(SOONG_ANDROID_MK),$(LOCAL_MODULE_MAKEFILE)), + $(if $(filter $(1),$(STATS.MODULE_TYPE)), + $(eval LOCAL_RECORDED_MODULE_TYPE := true) + $(eval STATS.MODULE_TYPE.$(1) += 1), + $(error Invalid module type: $(1)))))) +endef + ########################################################### ## Other includes ########################################################### diff --git a/core/droiddoc.mk b/core/droiddoc.mk index 0f18a58a84..06506dbbc7 100644 --- a/core/droiddoc.mk +++ b/core/droiddoc.mk @@ -14,6 +14,7 @@ # limitations under the License. # +$(call record-module-type,DROIDDOC) ## ## ## Common to both droiddoc and javadoc diff --git a/core/executable.mk b/core/executable.mk index 8652077506..f1b2462e46 100644 --- a/core/executable.mk +++ b/core/executable.mk @@ -16,6 +16,7 @@ ifneq ($(filter address,$(SANITIZE_TARGET)),) endif ifneq (true,$(my_skip_this_target)) +$(call record-module-type,EXECUTABLE) ifeq ($(TARGET_TRANSLATE_2ND_ARCH),true) # If a native test explicity specifies to build only for the translation arch, diff --git a/core/fuzz_test.mk b/core/fuzz_test.mk index fc582b3feb..c31e2e7292 100644 --- a/core/fuzz_test.mk +++ b/core/fuzz_test.mk @@ -2,6 +2,7 @@ ## A thin wrapper around BUILD_EXECUTABLE ## Common flags for fuzz tests are added. ########################################### +$(call record-module-type,FUZZ_TEST) ifdef LOCAL_SDK_VERSION $(error $(LOCAL_PATH): $(LOCAL_MODULE): NDK fuzz tests are not supported.) diff --git a/core/host_dalvik_java_library.mk b/core/host_dalvik_java_library.mk index 7fdf249f04..cee3cc49e7 100644 --- a/core/host_dalvik_java_library.mk +++ b/core/host_dalvik_java_library.mk @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +$(call record-module-type,HOST_DALVIK_JAVA_LIBRARY) # # Rules for building a host dalvik java library. These libraries diff --git a/core/host_dalvik_static_java_library.mk b/core/host_dalvik_static_java_library.mk index b79c0ea890..78faf73a56 100644 --- a/core/host_dalvik_static_java_library.mk +++ b/core/host_dalvik_static_java_library.mk @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +$(call record-module-type,HOST_DALVIK_STATIC_JAVA_LIBRARY) # # Rules for building a host dalvik static java library. diff --git a/core/host_executable.mk b/core/host_executable.mk index 0060c3e627..78223eba1b 100644 --- a/core/host_executable.mk +++ b/core/host_executable.mk @@ -1,3 +1,4 @@ +$(call record-module-type,HOST_EXECUTABLE) LOCAL_IS_HOST_MODULE := true my_prefix := HOST_ LOCAL_HOST_PREFIX := diff --git a/core/host_fuzz_test.mk b/core/host_fuzz_test.mk index cc7baada15..1c9eed2c71 100644 --- a/core/host_fuzz_test.mk +++ b/core/host_fuzz_test.mk @@ -2,6 +2,7 @@ ## A thin wrapper around BUILD_HOST_EXECUTABLE ## Common flags for host fuzz tests are added. ################################################ +$(call record-module-type,HOST_FUZZ_TEST) LOCAL_CFLAGS += -fsanitize-coverage=edge,indirect-calls,8bit-counters,trace-cmp LOCAL_STATIC_LIBRARIES += libLLVMFuzzer diff --git a/core/host_java_library.mk b/core/host_java_library.mk index 9aa2a7c33e..0a7dd8a65b 100644 --- a/core/host_java_library.mk +++ b/core/host_java_library.mk @@ -14,6 +14,8 @@ # limitations under the License. # +$(call record-module-type,HOST_JAVA_LIBRARY) + # # Standard rules for building a host java library. # diff --git a/core/host_native_test.mk b/core/host_native_test.mk index 2a6097df37..aa05bb3156 100644 --- a/core/host_native_test.mk +++ b/core/host_native_test.mk @@ -2,6 +2,7 @@ ## A thin wrapper around BUILD_HOST_EXECUTABLE ## Common flags for host native tests are added. ################################################ +$(call record-module-type,HOST_NATIVE_TEST) ifdef LOCAL_MODULE_CLASS ifneq ($(LOCAL_MODULE_CLASS),NATIVE_TESTS) diff --git a/core/host_prebuilt.mk b/core/host_prebuilt.mk index 7baab69950..79f3ffa23f 100644 --- a/core/host_prebuilt.mk +++ b/core/host_prebuilt.mk @@ -14,5 +14,6 @@ # limitations under the License. # +$(call record-module-type,HOST_PREBUILT) LOCAL_IS_HOST_MODULE := true include $(BUILD_MULTI_PREBUILT) diff --git a/core/host_shared_library.mk b/core/host_shared_library.mk index 2e0c9f1ce2..df24b63af3 100644 --- a/core/host_shared_library.mk +++ b/core/host_shared_library.mk @@ -1,3 +1,4 @@ +$(call record-module-type,HOST_SHARED_LIBRARY) LOCAL_IS_HOST_MODULE := true my_prefix := HOST_ LOCAL_HOST_PREFIX := diff --git a/core/host_static_library.mk b/core/host_static_library.mk index 068c702175..61f55697cf 100644 --- a/core/host_static_library.mk +++ b/core/host_static_library.mk @@ -1,3 +1,4 @@ +$(call record-module-type,HOST_STATIC_LIBRARY) LOCAL_IS_HOST_MODULE := true my_prefix := HOST_ LOCAL_HOST_PREFIX := diff --git a/core/host_static_test_lib.mk b/core/host_static_test_lib.mk index 5423dc6e14..a24cd62e6d 100644 --- a/core/host_static_test_lib.mk +++ b/core/host_static_test_lib.mk @@ -2,6 +2,7 @@ ## A thin wrapper around BUILD_HOST_STATIC_LIBRARY ## Common flags for host native tests are added. ################################################## +$(call record-module-type,HOST_STATIC_TEST_LIBRARY) include $(BUILD_SYSTEM)/host_test_internal.mk diff --git a/core/java_library.mk b/core/java_library.mk index 283e9adfef..b132fa68fa 100644 --- a/core/java_library.mk +++ b/core/java_library.mk @@ -2,6 +2,7 @@ ## Standard rules for building a java library. ## ########################################################### +$(call record-module-type,JAVA_LIBRARY) ifdef LOCAL_IS_HOST_MODULE $(error $(LOCAL_PATH): Host java libraries must use BUILD_HOST_JAVA_LIBRARY) diff --git a/core/multi_prebuilt.mk b/core/multi_prebuilt.mk index ed2fed686a..77c57ab4bd 100644 --- a/core/multi_prebuilt.mk +++ b/core/multi_prebuilt.mk @@ -14,6 +14,7 @@ # limitations under the License. # +$(call record-module-type,MULTI_PREBUILT) ifneq ($(LOCAL_MODULE)$(LOCAL_MODULE_CLASS),) $(error $(LOCAL_PATH): LOCAL_MODULE or LOCAL_MODULE_CLASS not needed by \ BUILD_MULTI_PREBUILT, use BUILD_PREBUILT instead!) diff --git a/core/native_benchmark.mk b/core/native_benchmark.mk index fe378b88a8..7b04d87c27 100644 --- a/core/native_benchmark.mk +++ b/core/native_benchmark.mk @@ -2,6 +2,7 @@ ## A thin wrapper around BUILD_EXECUTABLE ## Common flags for native benchmarks are added. ########################################### +$(call record-module-type,NATIVE_BENCHMARK) LOCAL_STATIC_LIBRARIES += libgoogle-benchmark diff --git a/core/native_test.mk b/core/native_test.mk index bb93eb08e1..8b49fbde10 100644 --- a/core/native_test.mk +++ b/core/native_test.mk @@ -2,6 +2,7 @@ ## A thin wrapper around BUILD_EXECUTABLE ## Common flags for native tests are added. ########################################### +$(call record-module-type,NATIVE_TEST) ifdef LOCAL_MODULE_CLASS ifneq ($(LOCAL_MODULE_CLASS),NATIVE_TESTS) diff --git a/core/notice_files.mk b/core/notice_files.mk index e7f89745b7..f0013c2751 100644 --- a/core/notice_files.mk +++ b/core/notice_files.mk @@ -1,6 +1,7 @@ ########################################################### ## Track NOTICE files ########################################################### +$(call record-module-type,NOTICE_FILE) ifneq ($(LOCAL_NOTICE_FILE),) notice_file:=$(strip $(LOCAL_NOTICE_FILE)) diff --git a/core/package.mk b/core/package.mk index 8c2c43502e..4fe058db45 100644 --- a/core/package.mk +++ b/core/package.mk @@ -2,6 +2,8 @@ # TARGET_ARCH and TARGET_2ND_ARCH. # To build it for TARGET_2ND_ARCH in a 64bit product, use "LOCAL_MULTILIB := 32". +$(call record-module-type,PACKAGE) + ifeq ($(TARGET_TRANSLATE_2ND_ARCH),true) LOCAL_MULTILIB := first endif diff --git a/core/phony_package.mk b/core/phony_package.mk index b5343352f7..578d629789 100644 --- a/core/phony_package.mk +++ b/core/phony_package.mk @@ -1,3 +1,4 @@ +$(call record-module-type,PHONY_PACKAGE) ifneq ($(strip $(LOCAL_SRC_FILES)),) $(error LOCAL_SRC_FILES are not allowed for phony packages) endif diff --git a/core/prebuilt.mk b/core/prebuilt.mk index cbe2079daf..5831e2412e 100644 --- a/core/prebuilt.mk +++ b/core/prebuilt.mk @@ -5,6 +5,7 @@ ## None. ## ########################################################### +$(call record-module-type,PREBUILT) ifdef LOCAL_IS_HOST_MODULE my_prefix := HOST_ diff --git a/core/shared_library.mk b/core/shared_library.mk index 2f483414a2..a15b1a6eaa 100644 --- a/core/shared_library.mk +++ b/core/shared_library.mk @@ -1,3 +1,4 @@ +$(call record-module-type,SHARED_LIBRARY) my_prefix := TARGET_ include $(BUILD_SYSTEM)/multilib.mk diff --git a/core/static_java_library.mk b/core/static_java_library.mk index d3324f80bc..d6dd065ac9 100644 --- a/core/static_java_library.mk +++ b/core/static_java_library.mk @@ -19,6 +19,7 @@ # classpaths. They can, however, be included wholesale in # other java modules. +$(call record-module-type,STATIC_JAVA_LIBRARY) LOCAL_UNINSTALLABLE_MODULE := true LOCAL_IS_STATIC_JAVA_LIBRARY := true LOCAL_MODULE_CLASS := JAVA_LIBRARIES diff --git a/core/static_library.mk b/core/static_library.mk index a8ae399b68..25e527964e 100644 --- a/core/static_library.mk +++ b/core/static_library.mk @@ -1,3 +1,4 @@ +$(call record-module-type,STATIC_LIBRARY) my_prefix := TARGET_ include $(BUILD_SYSTEM)/multilib.mk diff --git a/core/static_test_lib.mk b/core/static_test_lib.mk index 9d0bcc8efb..a0e2970698 100644 --- a/core/static_test_lib.mk +++ b/core/static_test_lib.mk @@ -2,6 +2,7 @@ ## A thin wrapper around BUILD_STATIC_LIBRARY ## Common flags for native tests are added. ############################################# +$(call record-module-type,STATIC_TEST_LIBRARY) include $(BUILD_SYSTEM)/target_test_internal.mk