This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new bf93c7840a gprof: move gprof function from sched to libbuiltin/libgcc
bf93c7840a is described below

commit bf93c7840ab13fc6ca2e53bb2e92a9b396bc59b1
Author: wangmingrong1 <[email protected]>
AuthorDate: Tue Nov 12 17:56:40 2024 +0800

    gprof: move gprof function from sched to libbuiltin/libgcc
    
    1. Enable interrupt gprof please config CONFIG_PROFILE_MINI
    2. Enable instuction gprof please add compile opt "-pg" or config 
CONFIG_PROFILE_ALL
    
    Signed-off-by: wangmingrong1 <[email protected]>
---
 arch/arm/src/cmake/armclang.cmake                  |  2 +-
 arch/arm/src/cmake/clang.cmake                     |  2 +-
 arch/arm/src/cmake/gcc.cmake                       |  4 +--
 arch/arm/src/cmake/ghs.cmake                       |  2 +-
 arch/arm/src/common/Toolchain.defs                 |  2 +-
 arch/arm64/src/Toolchain.defs                      |  2 +-
 arch/arm64/src/cmake/Toolchain.cmake               |  2 +-
 arch/sim/Kconfig                                   |  4 +--
 arch/sim/src/Makefile                              |  2 +-
 arch/sim/src/cmake/Toolchain.cmake                 |  2 +-
 boards/sim/sim/sim/scripts/Make.defs               |  2 +-
 libs/libbuiltin/Kconfig                            | 33 ++++++++++++++++++++++
 libs/libbuiltin/Makefile                           |  2 ++
 .../libbuiltin/libgcc}/CMakeLists.txt              | 17 +++--------
 .../libbuiltin/libgcc}/Make.defs                   | 20 ++++---------
 .../libbuiltin/libgcc/profile.c                    |  2 +-
 libs/libc/machine/arm/CMakeLists.txt               |  2 +-
 libs/libc/machine/arm/Make.defs                    |  2 +-
 sched/Kconfig                                      | 23 ---------------
 sched/instrument/CMakeLists.txt                    |  4 ---
 sched/instrument/Make.defs                         |  4 ---
 21 files changed, 61 insertions(+), 74 deletions(-)

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/sched/instrument/CMakeLists.txt 
b/libs/libbuiltin/libgcc/CMakeLists.txt
similarity index 76%
copy from sched/instrument/CMakeLists.txt
copy to libs/libbuiltin/libgcc/CMakeLists.txt
index 581008f907..ad5624c4f4 100644
--- a/sched/instrument/CMakeLists.txt
+++ b/libs/libbuiltin/libgcc/CMakeLists.txt
@@ -1,7 +1,5 @@
 # 
##############################################################################
-# sched/instrument/CMakeLists.txt
-#
-# SPDX-License-Identifier: Apache-2.0
+# 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
@@ -20,14 +18,7 @@
 #
 # 
##############################################################################
 
-set(SRCS instrument.c)
-
-if(NOT "${CONFIG_SCHED_STACK_RECORD}" STREQUAL "0")
-  list(APPEND SRCS stack_monitor.c)
+if(CONFIG_PROFILE_MINI)
+  nuttx_add_system_library(libgprof)
+  target_sources(libgprof PRIVATE profile.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/libs/libbuiltin/libgcc/Make.defs
similarity index 75%
copy from sched/instrument/Make.defs
copy to libs/libbuiltin/libgcc/Make.defs
index 5f90ba29dc..6d1a926083 100644
--- a/sched/instrument/Make.defs
+++ b/libs/libbuiltin/libgcc/Make.defs
@@ -1,7 +1,5 @@
 ############################################################################
-# sched/instrument/Make.defs
-#
-# SPDX-License-Identifier: Apache-2.0
+# 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
@@ -20,17 +18,11 @@
 #
 ############################################################################
 
-CSRCS += instrument.c
+ifeq ($(CONFIG_PROFILE_MINI),y)
 
-ifneq ($(CONFIG_SCHED_STACK_RECORD),0)
-CSRCS += stack_monitor.c
-endif
+CSRCS += profile.c
 
-ifeq ($(CONFIG_SCHED_GPROF),y)
-CSRCS += profile_monitor.c
-endif
+DEPPATH += --dep-path libgcc
+VPATH += :libgcc
 
-# Include instrument build support
-
-DEPPATH += --dep-path instrument
-VPATH += :instrument
+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

Reply via email to