Skip to content

Commit

Permalink
gprof: move gprof function from sched to libbuiltin/libgcc
Browse files Browse the repository at this point in the history
1. Enable interrupt gprof please config CONFIG_GPROF_PROFILING
2. Enable instuction gprof please add compile opt "-pg" or config CONFIG_GPROF_ALL

Signed-off-by: wangmingrong1 <[email protected]>
  • Loading branch information
W-M-R committed Nov 12, 2024
1 parent 0c9203b commit 7b95b22
Show file tree
Hide file tree
Showing 20 changed files with 675 additions and 44 deletions.
2 changes: 1 addition & 1 deletion arch/arm/src/cmake/armclang.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ if(CONFIG_SCHED_GCOV)
add_compile_options(-fprofile-generate -ftest-coverage)
endif()

if(CONFIG_SCHED_GPROF_ALL)
if(CONFIG_GPROF_ALL)
add_compile_options(-pg)
endif()

Expand Down
2 changes: 1 addition & 1 deletion arch/arm/src/cmake/clang.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ if(CONFIG_SCHED_GCOV_ALL)
add_compile_options(-fprofile-generate -ftest-coverage)
endif()

if(CONFIG_SCHED_GPROF_ALL)
if(CONFIG_GPROF_ALL)
add_compile_options(-pg)
endif()

Expand Down
4 changes: 2 additions & 2 deletions arch/arm/src/cmake/gcc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ if(CONFIG_SCHED_GCOV_ALL)
add_compile_options(-fprofile-generate -ftest-coverage)
endif()

if(CONFIG_SCHED_GPROF_ALL)
if(CONFIG_GPROF_ALL)
add_compile_options(-pg)
endif()

Expand Down Expand Up @@ -165,7 +165,7 @@ if(CONFIG_ARCH_INSTRUMENT_ALL)
add_compile_options(-finstrument-functions)
endif()

if(CONFIG_SCHED_GPROF_ALL)
if(CONFIG_GPROF_ALL)
add_compile_options(-pg)
endif()

Expand Down
2 changes: 1 addition & 1 deletion arch/arm/src/cmake/ghs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ if(CONFIG_SCHED_GCOV_ALL)
add_compile_options(-fprofile-generate -ftest-coverage)
endif()

if(CONFIG_SCHED_GPROF_ALL)
if(CONFIG_GPROF_ALL)
add_compile_options(-pg)
endif()

Expand Down
2 changes: 1 addition & 1 deletion arch/arm/src/common/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -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_GPROF_ALL),y)
ARCHOPTIMIZATION += -pg
endif

Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/src/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ ifeq ($(CONFIG_ARCH_INSTRUMENT_ALL),y)
ARCHOPTIMIZATION += -finstrument-functions
endif

ifeq ($(CONFIG_SCHED_GPROF_ALL),y)
ifeq ($(CONFIG_GPROF_ALL),y)
ARCHOPTIMIZATION += -pg
endif

Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/src/cmake/Toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ if(CONFIG_ARCH_INSTRUMENT_ALL)
add_compile_options(-finstrument-functions)
endif()

if(CONFIG_SCHED_GPROF_ALL)
if(CONFIG_GPROF_ALL)
add_compile_options(-pg)
endif()

Expand Down
2 changes: 1 addition & 1 deletion arch/sim/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ config SIM_UBSAN_DUMMY

config SIM_GPROF
bool "Enable gprof"
depends on !SCHED_GPROF
depends on !GPROF_PROFILING
default n
---help---
Enable support gprof profiling tool.
Expand Down
2 changes: 1 addition & 1 deletion arch/sim/src/cmake/Toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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_GPROF_ALL OR CONFIG_SIM_GPROF)
add_compile_options(-pg)
endif()

Expand Down
2 changes: 1 addition & 1 deletion boards/sim/sim/sim/scripts/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -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_GPROF_ALL)$(CONFIG_SIM_GPROF),)
ARCHOPTIMIZATION += -pg
endif

Expand Down
24 changes: 24 additions & 0 deletions libs/libbuiltin/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,30 @@ config COVERAGE_COMPILER_RT
select LIB_COMPILER_RT
default n

config GPROF_PROFILING
bool "Enable gprof profiling"
select LIB_BUILTIN
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 GPROF_ALL
bool "Enable gprof call graph for all modules"
depends on FRAME_POINTER
depends on GPROF_PROFILING
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
Expand Down
2 changes: 2 additions & 0 deletions libs/libbuiltin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
24 changes: 24 additions & 0 deletions libs/libbuiltin/libgcc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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_GPROF_PROFILING)
nuttx_add_system_library(libgprof)
target_sources(libgprof PRIVATE gprof/profile_monitor.c)
endif()
28 changes: 28 additions & 0 deletions libs/libbuiltin/libgcc/Make.defs
Original file line number Diff line number Diff line change
@@ -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_GPROF_PROFILING),y)

CSRCS += profile_monitor.c

DEPPATH += --dep-path libgcc/gprof
VPATH += :libgcc/gprof

endif
Loading

0 comments on commit 7b95b22

Please sign in to comment.