ccmakeprofilingprofilergprof

Empty profile with -p on gcc


I have 2 projects in c. They both are configured with CMake using similar CMakeLists.txt. The first generates gmon.out file normally. It can be seen with gprof. The second generates barely empty gmon.out with ?seconds in the beginning. I compile them both in the same docker Dev Container (from vscode) with GCC 12.2.0 aarch-64-linux-gnu. here is the first (normal) CMakeLists:

cmake_minimum_required(VERSION 3.10)
project(PSF C)

set(CMAKE_C_STANDARD 23)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

include_directories(src libs)

add_subdirectory(libs/My_list)

set(SANITIZERS -p -fno-omit-frame-pointer -fsanitize=address,leak)

add_compile_options(-Wall -Wextra ${SANITIZERS})

set(SOURCES 
    src/main.c
    src/expr/expr_parsing.c
    src/expr/expr_processing.c
    src/expr/expr.h
    src/PSF/psf.c
    src/PSF/psf.h)

set(DEPS
    My_list)
    
add_executable(${PROJECT_NAME} ${SOURCES})

target_link_libraries(${PROJECT_NAME} PRIVATE ${SANITIZERS} ${DEPS})

and the one that produces empty gmon.out

cmake_minimum_required(VERSION 3.10)
project(lab4a C)

set(CMAKE_C_STANDARD 23)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

include_directories(src libs)

add_subdirectory(libs/My_list)
add_subdirectory(libs/My_string)
add_subdirectory(libs/BST)

set(SANITIZERS -p -fno-omit-frame-pointer -fsanitize=address,leak)

add_compile_options(-Wall -Wextra ${SANITIZERS})

set(SOURCES 
    src/main.c)

set(DEPS
    BST)
    
add_executable(${PROJECT_NAME} ${SOURCES})

target_link_libraries(${PROJECT_NAME} PRIVATE ${SANITIZERS} ${DEPS})

My_list and My_string are the dependencies of BST so i link only BST here. I work on Mac, so container is necessary here. -fno-pie option does not fix anything. nm call says that the both have debug symbols, but using gprof on the first one i can see

Flat profile:

Each sample counts as 0.01 seconds.
 no time accumulated

  %   cumulative   self              self     total           
 time   seconds   seconds    calls  Ts/call  Ts/call  name    
  0.00      0.00     0.00        8     0.00     0.00  PSF_dtor
  0.00      0.00     0.00        8     0.00     0.00  _PSF_compare
  0.00      0.00     0.00        8     0.00     0.00  _PSF_copy
  0.00      0.00     0.00        8     0.00     0.00  _PSF_free
  0.00      0.00     0.00        4     0.00     0.00  PSF_ctor
  0.00      0.00     0.00        4     0.00     0.00  PSF_empty_ctor
  0.00      0.00     0.00        4     0.00     0.00  PSF_mul
  0.00      0.00     0.00        4     0.00     0.00  _Term_cmp
  0.00      0.00     0.00        3     0.00     0.00  Expr_ctor
  0.00      0.00     0.00        3     0.00     0.00  Expr_dtor
  0.00      0.00     0.00        3     0.00     0.00  Expr_simplify
  0.00      0.00     0.00        2     0.00     0.00  read_line
  0.00      0.00     0.00        1     0.00     0.00  Expr_mul
  0.00      0.00     0.00        1     0.00     0.00  Expr_print

while on the second:

Flat profile:

Each sample counts as 0.01 seconds.
 no time accumulated

  %   cumulative   self              self     total           
 time   seconds   seconds    calls  Ts/call  Ts/call  name    

 %         the percentage of the total running time of the

and nothing else.

My_string and My_list are static libraries that i build myself.

.
├── CMakeLists.txt
├── libs
│   ├── BST
│   │   ├── CMakeLists.txt
│   │   ├── lib_BST.h
│   │   ├── src
│   │   │   ├── BST.c
│   │   │   ├── BST_dump.c
│   │   │   ├── BST_files.c
│   │   │   ├── BST.h
│   │   │   ├── BST_validation.c
│   │   │   └── Node
│   │   │       ├── node.c
│   │   │       └── node.h
│   │   └── utils
│   │       ├── utils.c
│   │       └── utils.h
│   ├── My_list
│   │   ├── CMakeLists.txt
│   │   ├── lib_My_list.h
│   │   └── src
│   │       ├── List.c
│   │       ├── List.h
│   │       ├── List_node
│   │       │   ├── List_node.c
│   │       │   └── List_node.h
│   │       └── List_verify.c
│   └── My_string
│       ├── CMakeLists.txt
│       ├── lib_My_string.h
│       └── src
│           ├── My_string.c
│           └── My_string.h
├── readme.md
├── src
│   └── main.c
├── test.py
└── tree_tests.txt

here is the project structure for the project. My_string is the dependency of My_list and BST, and My_list is the dependency of BST.


Solution

  • While doing minimal reproducible example, i was using different machine. I reconfigured everything one more time and this time everything worked. The problem was that i really didn't provide proper compile flags to my dependent libraries (-p) and only did it for my main executable. After doing this from scratch profile is being created properly now.