diff --git a/arch/arm/src/cmake/armclang.cmake b/arch/arm/src/cmake/armclang.cmake index 6b383f114f..dc9762e39d 100644 --- a/arch/arm/src/cmake/armclang.cmake +++ b/arch/arm/src/cmake/armclang.cmake @@ -120,7 +120,7 @@ if(CONFIG_SCHED_GCOV) add_compile_options(-fprofile-generate -ftest-coverage) endif() -if(CONFIG_SCHED_GPROF_ALL) +if(CONFIG_PROFILE_ALL) add_compile_options(-pg) endif() diff --git a/arch/arm/src/cmake/clang.cmake b/arch/arm/src/cmake/clang.cmake index f86103649d..fe519d7262 100644 --- a/arch/arm/src/cmake/clang.cmake +++ b/arch/arm/src/cmake/clang.cmake @@ -121,7 +121,7 @@ if(CONFIG_SCHED_GCOV_ALL) add_compile_options(-fprofile-generate -ftest-coverage) endif() -if(CONFIG_SCHED_GPROF_ALL) +if(CONFIG_PROFILE_ALL) add_compile_options(-pg) endif() diff --git a/arch/arm/src/cmake/gcc.cmake b/arch/arm/src/cmake/gcc.cmake index c003345857..7995dbedcc 100644 --- a/arch/arm/src/cmake/gcc.cmake +++ b/arch/arm/src/cmake/gcc.cmake @@ -131,7 +131,7 @@ if(CONFIG_SCHED_GCOV_ALL) add_compile_options(-fprofile-generate -ftest-coverage) endif() -if(CONFIG_SCHED_GPROF_ALL) +if(CONFIG_PROFILE_ALL) add_compile_options(-pg) endif() @@ -165,7 +165,7 @@ if(CONFIG_ARCH_INSTRUMENT_ALL) add_compile_options(-finstrument-functions) endif() -if(CONFIG_SCHED_GPROF_ALL) +if(CONFIG_PROFILE_ALL) add_compile_options(-pg) endif() diff --git a/arch/arm/src/cmake/ghs.cmake b/arch/arm/src/cmake/ghs.cmake index d1636f2e86..16068a2776 100644 --- a/arch/arm/src/cmake/ghs.cmake +++ b/arch/arm/src/cmake/ghs.cmake @@ -92,7 +92,7 @@ if(CONFIG_SCHED_GCOV_ALL) add_compile_options(-fprofile-generate -ftest-coverage) endif() -if(CONFIG_SCHED_GPROF_ALL) +if(CONFIG_PROFILE_ALL) add_compile_options(-pg) endif() diff --git a/arch/arm/src/common/Toolchain.defs b/arch/arm/src/common/Toolchain.defs index ba571237ad..883ab9b35c 100644 --- a/arch/arm/src/common/Toolchain.defs +++ b/arch/arm/src/common/Toolchain.defs @@ -72,7 +72,7 @@ ifneq ($(CONFIG_STACK_USAGE_WARNING),0) ARCHOPTIMIZATION += -Wstack-usage=$(CONFIG_STACK_USAGE_WARNING) endif -ifeq ($(CONFIG_SCHED_GPROF_ALL),y) +ifeq ($(CONFIG_PROFILE_ALL),y) ARCHOPTIMIZATION += -pg endif diff --git a/arch/arm64/src/Toolchain.defs b/arch/arm64/src/Toolchain.defs index aa94a21572..155d688b03 100644 --- a/arch/arm64/src/Toolchain.defs +++ b/arch/arm64/src/Toolchain.defs @@ -96,7 +96,7 @@ ifeq ($(CONFIG_ARCH_INSTRUMENT_ALL),y) ARCHOPTIMIZATION += -finstrument-functions endif -ifeq ($(CONFIG_SCHED_GPROF_ALL),y) +ifeq ($(CONFIG_PROFILE_ALL),y) ARCHOPTIMIZATION += -pg endif diff --git a/arch/arm64/src/cmake/Toolchain.cmake b/arch/arm64/src/cmake/Toolchain.cmake index e3f5ad69c7..e0783be82f 100644 --- a/arch/arm64/src/cmake/Toolchain.cmake +++ b/arch/arm64/src/cmake/Toolchain.cmake @@ -135,7 +135,7 @@ if(CONFIG_ARCH_INSTRUMENT_ALL) add_compile_options(-finstrument-functions) endif() -if(CONFIG_SCHED_GPROF_ALL) +if(CONFIG_PROFILE_ALL) add_compile_options(-pg) endif() diff --git a/arch/sim/Kconfig b/arch/sim/Kconfig index ec06901214..bedca62e9f 100644 --- a/arch/sim/Kconfig +++ b/arch/sim/Kconfig @@ -90,9 +90,9 @@ config SIM_UBSAN_DUMMY ---help--- Keep SIM_UBSAN compile time but disable runtime actions. -config SIM_GPROF +config SIM_PROFILE bool "Enable gprof" - depends on !SCHED_GPROF + depends on PROFILE_NONE default n ---help--- Enable support gprof profiling tool. diff --git a/arch/sim/src/Makefile b/arch/sim/src/Makefile index b7f552d6f2..1ebdf70057 100644 --- a/arch/sim/src/Makefile +++ b/arch/sim/src/Makefile @@ -144,7 +144,7 @@ ifeq ($(CONFIG_SCHED_GCOV),y) STDLIBS += -lgcov endif -ifeq ($(CONFIG_SIM_GPROF),y) +ifneq ($(CONFIG_SIM_PROFILE)$(CONFIG_PROFILE_ALL),) HOSTCFLAGS += -pg endif diff --git a/arch/sim/src/cmake/Toolchain.cmake b/arch/sim/src/cmake/Toolchain.cmake index 4257ea8d31..8cb388b4fb 100644 --- a/arch/sim/src/cmake/Toolchain.cmake +++ b/arch/sim/src/cmake/Toolchain.cmake @@ -90,7 +90,7 @@ if(CONFIG_SCHED_GCOV_ALL) add_compile_options(-fprofile-generate -ftest-coverage) endif() -if(CONFIG_SCHED_GPROF_ALL OR CONFIG_SIM_GPROF) +if(CONFIG_PROFILE_ALL OR CONFIG_SIM_PROFILE) add_compile_options(-pg) endif() diff --git a/boards/sim/sim/sim/scripts/Make.defs b/boards/sim/sim/sim/scripts/Make.defs index 314f4fcab2..ca617edab1 100644 --- a/boards/sim/sim/sim/scripts/Make.defs +++ b/boards/sim/sim/sim/scripts/Make.defs @@ -78,7 +78,7 @@ ifeq ($(CONFIG_SCHED_GCOV_ALL),y) ARCHOPTIMIZATION += -fprofile-generate -ftest-coverage endif -ifneq ($(CONFIG_SCHED_GPROF_ALL)$(CONFIG_SIM_GPROF),) +ifneq ($(CONFIG_PROFILE_ALL)$(CONFIG_SIM_PROFILE),) ARCHOPTIMIZATION += -pg endif diff --git a/libs/libbuiltin/Kconfig b/libs/libbuiltin/Kconfig index df12bd3697..fa92c8ee8f 100644 --- a/libs/libbuiltin/Kconfig +++ b/libs/libbuiltin/Kconfig @@ -35,6 +35,39 @@ config COVERAGE_COMPILER_RT select LIB_COMPILER_RT default n +choice + prompt "Builtin profile support" + default PROFILE_NONE + ---help--- + Select the profile library + +config PROFILE_MINI + bool "Enable mini gprof profiling" + select LIB_BUILTIN + ---help--- + Enable gprof profiling support. This will cause the compiler to + generate additional code to support profiling. This will also + cause the linker to include the gmon.out file in the final + executable. + Add the "-pg" parameter to the Makefile when compiling to obtain + the function call graph of the specified module. If you do this, + please enable "CONFIG_FRAME_POINTER" + +config PROFILE_NONE + bool "None profile support" + +endchoice + +config PROFILE_ALL + bool "Enable gprof call graph for all modules" + depends on FRAME_POINTER && !PROFILE_NONE + default n + ---help--- + Enable gprof profiling for all code, it will instrument + all code, which will cause a large performance penalty for the code. + You can add the '-pg' parameter to the specified module in the + makefile to only analyze the content of the module. + config LIB_COMPILER_RT_VERSION string "Select LLVM Compiler-rt version" depends on LIB_COMPILER_RT diff --git a/libs/libbuiltin/Makefile b/libs/libbuiltin/Makefile index 97202f437b..de3fb04984 100644 --- a/libs/libbuiltin/Makefile +++ b/libs/libbuiltin/Makefile @@ -30,6 +30,8 @@ ifeq ($(CONFIG_LIB_COMPILER_RT),y) include compiler-rt/Make.defs endif +include libgcc/Make.defs + AOBJS = $(addprefix $(BINDIR)$(DELIM), $(ASRCS:.S=$(OBJEXT))) COBJS = $(addprefix $(BINDIR)$(DELIM), $(CSRCS:.c=$(OBJEXT))) CXXOBJS = $(addprefix $(BINDIR)$(DELIM), $(CXXSRCS:.cxx=$(OBJEXT))) diff --git a/libs/libbuiltin/libgcc/CMakeLists.txt b/libs/libbuiltin/libgcc/CMakeLists.txt new file mode 100644 index 0000000000..ad5624c4f4 --- /dev/null +++ b/libs/libbuiltin/libgcc/CMakeLists.txt @@ -0,0 +1,24 @@ +# ############################################################################## +# libs/libbuiltin/libgcc/CMakeLists.txt +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with this work for +# additional information regarding copyright ownership. The ASF licenses this +# file to you under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +# ############################################################################## + +if(CONFIG_PROFILE_MINI) + nuttx_add_system_library(libgprof) + target_sources(libgprof PRIVATE profile.c) +endif() diff --git a/libs/libbuiltin/libgcc/Make.defs b/libs/libbuiltin/libgcc/Make.defs new file mode 100644 index 0000000000..6d1a926083 --- /dev/null +++ b/libs/libbuiltin/libgcc/Make.defs @@ -0,0 +1,28 @@ +############################################################################ +# libs/libbuiltin/libgcc/Make.defs +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +ifeq ($(CONFIG_PROFILE_MINI),y) + +CSRCS += profile.c + +DEPPATH += --dep-path libgcc +VPATH += :libgcc + +endif diff --git a/sched/instrument/profile_monitor.c b/libs/libbuiltin/libgcc/profile.c similarity index 99% rename from sched/instrument/profile_monitor.c rename to libs/libbuiltin/libgcc/profile.c index 2c98c6b81c..5d2e82750c 100644 --- a/sched/instrument/profile_monitor.c +++ b/libs/libbuiltin/libgcc/profile.c @@ -1,5 +1,5 @@ /**************************************************************************** - * sched/instrument/profile_monitor.c + * libs/libbuiltin/libgcc/profile.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/libs/libc/machine/arm/CMakeLists.txt b/libs/libc/machine/arm/CMakeLists.txt index 387be1d42c..560c77d4c9 100644 --- a/libs/libc/machine/arm/CMakeLists.txt +++ b/libs/libc/machine/arm/CMakeLists.txt @@ -62,7 +62,7 @@ if(CONFIG_ARCH_SETJMP_H) endif() endif() -if(CONFIG_SCHED_GPROF) +if(CONFIG_PROFILE_MINI) list(APPEND SRCS gnu/mcount.S) endif() diff --git a/libs/libc/machine/arm/Make.defs b/libs/libc/machine/arm/Make.defs index 63a319eb4a..c17428d1c2 100644 --- a/libs/libc/machine/arm/Make.defs +++ b/libs/libc/machine/arm/Make.defs @@ -60,7 +60,7 @@ ASRCS += arch_setjmp.S endif endif -ifeq ($(CONFIG_SCHED_GPROF),y) +ifeq ($(CONFIG_PROFILE_MINI),y) ASRCS += mcount.S endif diff --git a/sched/Kconfig b/sched/Kconfig index 84339d6d19..a5613dac56 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -1368,29 +1368,6 @@ config SCHED_GCOV_ALL Enable gcov profiling for all code, it will instrument all code, which will cause a large performance penalty for the code. -config SCHED_GPROF - bool "Enable gprof profiling" - default n - ---help--- - Enable gprof profiling support. This will cause the compiler to - generate additional code to support profiling. This will also - cause the linker to include the gmon.out file in the final - executable. - Add the "-pg" parameter to the Makefile when compiling to obtain - the function call graph of the specified module. If you do this, - please enable "CONFIG_FRAME_POINTER" - -config SCHED_GPROF_ALL - bool "Enable gprof call graph for all modules" - depends on FRAME_POINTER - depends on SCHED_GPROF - default n - ---help--- - Enable gprof profiling for all code, it will instrument - all code, which will cause a large performance penalty for the code. - You can add the '-pg' parameter to the specified module in the - makefile to only analyze the content of the module. - endmenu menu "Files and I/O" diff --git a/sched/instrument/CMakeLists.txt b/sched/instrument/CMakeLists.txt index 581008f907..1782ddae2a 100644 --- a/sched/instrument/CMakeLists.txt +++ b/sched/instrument/CMakeLists.txt @@ -26,8 +26,4 @@ if(NOT "${CONFIG_SCHED_STACK_RECORD}" STREQUAL "0") list(APPEND SRCS stack_monitor.c) endif() -if(CONFIG_SCHED_GPROF) - list(APPEND SRCS profile_monitor.c) -endif() - target_sources(sched PRIVATE ${SRCS}) diff --git a/sched/instrument/Make.defs b/sched/instrument/Make.defs index 5f90ba29dc..60e087b356 100644 --- a/sched/instrument/Make.defs +++ b/sched/instrument/Make.defs @@ -26,10 +26,6 @@ ifneq ($(CONFIG_SCHED_STACK_RECORD),0) CSRCS += stack_monitor.c endif -ifeq ($(CONFIG_SCHED_GPROF),y) -CSRCS += profile_monitor.c -endif - # Include instrument build support DEPPATH += --dep-path instrument