From 6f95455b452329c042fcda15df1104527504ff91 Mon Sep 17 00:00:00 2001 From: wangmingrong1 Date: Thu, 7 Nov 2024 15:01:28 +0800 Subject: [PATCH 1/2] gprof: Add necessary dependencies when enable: CONFIG_SCHED_GPROF_ALL: arm-none-eabi-g++: error: -pg and -fomit-frame-pointer are incompatible Signed-off-by: wangmingrong1 --- sched/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/sched/Kconfig b/sched/Kconfig index 24f0a14eeabb5..1f1d6b24e13db 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -1376,6 +1376,7 @@ config SCHED_GPROF config SCHED_GPROF_ALL bool "Enable gprof call graph for all modules" + depends on FRAME_POINTER depends on SCHED_GPROF default n ---help--- From c4b94e10848732a1fd59d8e446e01c5d011cb9a4 Mon Sep 17 00:00:00 2001 From: wangmingrong1 Date: Thu, 7 Nov 2024 20:21:44 +0800 Subject: [PATCH 2/2] gprof: Move gprof to libc 1. Modify the name of the config 2. Since gprof is similar to gdbstub, this implementation is suitable for compilers such as gcc and clang, so it is more appropriate to put it in libc Signed-off-by: wangmingrong1 --- 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 | 2 +- arch/sim/src/cmake/Toolchain.cmake | 2 +- boards/sim/sim/sim/scripts/Make.defs | 2 +- libs/libc/Kconfig | 1 + libs/libc/Makefile | 1 + libs/libc/gprof/CMakeLists.txt | 25 ++++++++++++++ libs/libc/gprof/Kconfig | 29 ++++++++++++++++ libs/libc/gprof/Make.defs | 34 +++++++++++++++++++ .../libc/gprof}/profile_monitor.c | 2 +- libs/libc/machine/arm/CMakeLists.txt | 2 +- libs/libc/machine/arm/Make.defs | 2 +- sched/Kconfig | 22 ------------ sched/instrument/CMakeLists.txt | 4 --- sched/instrument/Make.defs | 4 --- 21 files changed, 104 insertions(+), 44 deletions(-) create mode 100644 libs/libc/gprof/CMakeLists.txt create mode 100644 libs/libc/gprof/Kconfig create mode 100644 libs/libc/gprof/Make.defs rename {sched/instrument => libs/libc/gprof}/profile_monitor.c (99%) diff --git a/arch/arm/src/cmake/armclang.cmake b/arch/arm/src/cmake/armclang.cmake index 6b383f114fc14..456b467c1c6eb 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_LIB_GPROF_ALL) add_compile_options(-pg) endif() diff --git a/arch/arm/src/cmake/clang.cmake b/arch/arm/src/cmake/clang.cmake index f86103649d18b..b84600d439d94 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_LIB_GPROF_ALL) add_compile_options(-pg) endif() diff --git a/arch/arm/src/cmake/gcc.cmake b/arch/arm/src/cmake/gcc.cmake index c0033458577dc..25a013e7f690e 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_LIB_GPROF_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_LIB_GPROF_ALL) add_compile_options(-pg) endif() diff --git a/arch/arm/src/cmake/ghs.cmake b/arch/arm/src/cmake/ghs.cmake index d1636f2e86b63..cb10af01e5332 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_LIB_GPROF_ALL) add_compile_options(-pg) endif() diff --git a/arch/arm/src/common/Toolchain.defs b/arch/arm/src/common/Toolchain.defs index ba571237ade43..c2dc9042c78ea 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_LIB_GPROF_ALL),y) ARCHOPTIMIZATION += -pg endif diff --git a/arch/arm64/src/Toolchain.defs b/arch/arm64/src/Toolchain.defs index aa94a2157260c..40d15b87c783e 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_LIB_GPROF_ALL),y) ARCHOPTIMIZATION += -pg endif diff --git a/arch/arm64/src/cmake/Toolchain.cmake b/arch/arm64/src/cmake/Toolchain.cmake index e3f5ad69c7335..55892d27fdb9d 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_LIB_GPROF_ALL) add_compile_options(-pg) endif() diff --git a/arch/sim/Kconfig b/arch/sim/Kconfig index ec06901214896..a50c01d308972 100644 --- a/arch/sim/Kconfig +++ b/arch/sim/Kconfig @@ -92,7 +92,7 @@ config SIM_UBSAN_DUMMY config SIM_GPROF bool "Enable gprof" - depends on !SCHED_GPROF + depends on !LIB_GPROF default n ---help--- Enable support gprof profiling tool. diff --git a/arch/sim/src/cmake/Toolchain.cmake b/arch/sim/src/cmake/Toolchain.cmake index 4257ea8d31b75..7586d088ad229 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_LIB_GPROF_ALL OR CONFIG_SIM_GPROF) add_compile_options(-pg) endif() diff --git a/boards/sim/sim/sim/scripts/Make.defs b/boards/sim/sim/sim/scripts/Make.defs index 5e80ac6d0c094..91781791ffd84 100644 --- a/boards/sim/sim/sim/scripts/Make.defs +++ b/boards/sim/sim/sim/scripts/Make.defs @@ -76,7 +76,7 @@ ifeq ($(CONFIG_SCHED_GCOV_ALL),y) ARCHOPTIMIZATION += -fprofile-generate -ftest-coverage endif -ifneq ($(CONFIG_SCHED_GPROF_ALL)$(CONFIG_SIM_GPROF),) +ifneq ($(CONFIG_LIB_GPROF_ALL)$(CONFIG_SIM_GPROF),) ARCHOPTIMIZATION += -pg endif diff --git a/libs/libc/Kconfig b/libs/libc/Kconfig index b5d5e02717356..26ae5d1d2b91e 100644 --- a/libs/libc/Kconfig +++ b/libs/libc/Kconfig @@ -15,6 +15,7 @@ source "libs/libc/pthread/Kconfig" source "libs/libc/dlfcn/Kconfig" source "libs/libc/modlib/Kconfig" source "libs/libc/gdbstub/Kconfig" +source "libs/libc/gprof/Kconfig" source "libs/libc/grp/Kconfig" source "libs/libc/pwd/Kconfig" source "libs/libc/locale/Kconfig" diff --git a/libs/libc/Makefile b/libs/libc/Makefile index e07442cbb0492..94bed3a9c1d40 100644 --- a/libs/libc/Makefile +++ b/libs/libc/Makefile @@ -35,6 +35,7 @@ include fixedmath/Make.defs include gdbstub/Make.defs include grp/Make.defs include gnssutils/Make.defs +include gprof/Make.defs include hex2bin/Make.defs include inttypes/Make.defs include libgen/Make.defs diff --git a/libs/libc/gprof/CMakeLists.txt b/libs/libc/gprof/CMakeLists.txt new file mode 100644 index 0000000000000..011aafca7890c --- /dev/null +++ b/libs/libc/gprof/CMakeLists.txt @@ -0,0 +1,25 @@ +# ############################################################################## +# libs/libc/gprof/CMakeLists.txt +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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_LIB_GPROF) + target_sources(c PRIVATE profile_monitor.c) +endif() diff --git a/libs/libc/gprof/Kconfig b/libs/libc/gprof/Kconfig new file mode 100644 index 0000000000000..a3cb7e3fbd6bf --- /dev/null +++ b/libs/libc/gprof/Kconfig @@ -0,0 +1,29 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config LIB_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 LIB_GPROF + +config LIB_GPROF_ALL + bool "Enable gprof call graph for all modules" + depends on FRAME_POINTER + 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. + +endif # LIB_GPROF diff --git a/libs/libc/gprof/Make.defs b/libs/libc/gprof/Make.defs new file mode 100644 index 0000000000000..f46c9837985ab --- /dev/null +++ b/libs/libc/gprof/Make.defs @@ -0,0 +1,34 @@ +############################################################################ +# libs/libc/gprof/Make.defs +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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_LIB_GPROF),y) + +# Add the internal C files to the build + +CSRCS += profile_monitor.c + +# Add the userfs directory to the build + +DEPPATH += --dep-path gprof +VPATH += :gprof + +endif diff --git a/sched/instrument/profile_monitor.c b/libs/libc/gprof/profile_monitor.c similarity index 99% rename from sched/instrument/profile_monitor.c rename to libs/libc/gprof/profile_monitor.c index 2c98c6b81c75b..27a1e0e5da680 100644 --- a/sched/instrument/profile_monitor.c +++ b/libs/libc/gprof/profile_monitor.c @@ -1,5 +1,5 @@ /**************************************************************************** - * sched/instrument/profile_monitor.c + * libs/libc/gprof/profile_monitor.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 387be1d42c655..2193eb735cb15 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_LIB_GPROF) list(APPEND SRCS gnu/mcount.S) endif() diff --git a/libs/libc/machine/arm/Make.defs b/libs/libc/machine/arm/Make.defs index 63a319eb4a391..8ddd7beeafb0f 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_LIB_GPROF),y) ASRCS += mcount.S endif diff --git a/sched/Kconfig b/sched/Kconfig index 1f1d6b24e13db..824147d064b3c 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -1363,28 +1363,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. - -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 581008f90739f..1782ddae2a1bd 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 5f90ba29dc08d..60e087b356433 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