From 399a0b4b318e432c9512aa29ce89590a462cf8aa Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Thu, 21 Apr 2022 10:38:32 -0400 Subject: [PATCH] debug: generate call graph profile data using gprof This will generate profile data that can be analyzed using gprof. When you build the application (currently for native_posix only), after running the application you will get a file "gmon.out" with the call graph which can be processed with gprof: gprof build/zephyr/zephyr.exe gmon.out > analysis.txt Signed-off-by: Anas Nashif --- arch/posix/CMakeLists.txt | 4 ++++ cmake/compiler/gcc/compiler_flags.cmake | 2 ++ cmake/linker/ld/gcc/linker_flags.cmake | 3 ++- subsys/debug/Kconfig | 7 +++++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/arch/posix/CMakeLists.txt b/arch/posix/CMakeLists.txt index ddae0a787dc..4dfcb9a2824 100644 --- a/arch/posix/CMakeLists.txt +++ b/arch/posix/CMakeLists.txt @@ -24,6 +24,10 @@ zephyr_compile_options($) zephyr_include_directories(${BOARD_DIR}) +if (CONFIG_GPROF) + zephyr_compile_options($) + zephyr_link_libraries($) +endif() if (CONFIG_ASAN) zephyr_compile_options($) zephyr_link_libraries($) diff --git a/cmake/compiler/gcc/compiler_flags.cmake b/cmake/compiler/gcc/compiler_flags.cmake index df242be4240..7c3284eb47d 100644 --- a/cmake/compiler/gcc/compiler_flags.cmake +++ b/cmake/compiler/gcc/compiler_flags.cmake @@ -177,6 +177,8 @@ set_compiler_property(PROPERTY imacros -imacros) # GCC compiler flags for sanitizing. set_compiler_property(PROPERTY sanitize_address -fsanitize=address) +set_compiler_property(PROPERTY gprof -pg) + set_compiler_property(PROPERTY sanitize_undefined -fsanitize=undefined) # GCC compiler flag for turning off thread-safe initialization of local statics diff --git a/cmake/linker/ld/gcc/linker_flags.cmake b/cmake/linker/ld/gcc/linker_flags.cmake index bd5d1d25298..7a2ffdf4c0c 100644 --- a/cmake/linker/ld/gcc/linker_flags.cmake +++ b/cmake/linker/ld/gcc/linker_flags.cmake @@ -10,5 +10,6 @@ endif() # ld/gcc linker flags for sanitizing. check_set_linker_property(TARGET linker APPEND PROPERTY sanitize_address -lasan) check_set_linker_property(TARGET linker APPEND PROPERTY sanitize_address -fsanitize=address) - check_set_linker_property(TARGET linker APPEND PROPERTY sanitize_undefined -fsanitize=undefined) + +check_set_linker_property(TARGET linker APPEND PROPERTY gprof -pg) diff --git a/subsys/debug/Kconfig b/subsys/debug/Kconfig index 550c3a7eac4..b9cea2fb456 100644 --- a/subsys/debug/Kconfig +++ b/subsys/debug/Kconfig @@ -99,6 +99,13 @@ config DEBUG only disables optimization, more debugging variants can be selected from here to allow more debugging. +config GPROF + bool "Generate profiling information" + depends on ARCH_POSIX + help + Generate call graph profile data for the application that can be + analyzed with gprof + config ASAN bool "Build with address sanitizer" depends on ARCH_POSIX