Profiling example code with gprof

Hello everyone,
I am trying to profile the examples provided in the openFHE repository, using the gprof progiler. I am adding in the CMakeList.txt file the following:
set( CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} -pg”)

set( CMAKE_EXE_LINKER_FLAGS “${CMAKE_EXE_LINKER_FLAGS} -pg”)

set( CMAKE_SHARED_LINKER_FLAGS “${CMAKE_SHARED_LINKER_FLAGS} -pg”)’

Then, the process I would follow would be:

  1. Create a build directory and cd build
  2. cmake …
  3. make -j 8
  4. run an example as ./bin/examples/pke/simple-integers
  5. gprof ./bin/examples/pke/simple-integers

However, at step 3, I am getting the following errors (output of terminal provided):

– demoData folder already exists
[ 0%] Built target third-party
[ 7%] Built target benchmark
[ 25%] Built target coreobj
[ 25%] Linking CXX shared library …/…/lib/libOPENFHEcore.so
clang: error: argument unused during compilation: ‘-pg’ [-Werror,-Wunused-command-line-argument]
clang: error: argument unused during compilation: ‘-pg’ [-Werror,-Wunused-command-line-argument]
make[2]: *** [src/core/CMakeFiles/OPENFHEcore.dir/build.make:179: lib/libOPENFHEcore.so.1.0.2] Error 1
make[1]: *** [CMakeFiles/Makefile2:634: src/core/CMakeFiles/OPENFHEcore.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

Could anyone help me with that?
The goal of this would be to get a better understanding of the call graph for high level FHE functions such as EvalAdd, EvalMult, MakePackedPlaintext etc.

Thank you in advance :slight_smile:

I have just tried it with gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
I placed the following lines at line 216 in the CMakeLists.txt here and it worked for me.

set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pg")
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg")

Make sure you build OpenFHE with:
cmake -DCMAKE_BUILD_TYPE=Debug ..

Caesar, thank you for replying!

Indeed, with gcc it works! With clang-11, I keep getting the same error message, due to the -Werror flag (line 177-178) in the CMakeLists.txt file you linked, because it converts the clang warning for -pg into an error.

Would there be another way to profile functions (other than gprof) of the library, like EvalMult, EvalAdd for each scheme (BGV,BFV,CKKS)? What I want to see is the computationally expensive part (in terms of time) of each function for each scheme.

Regards,
George

The best way to understand the schemes and their computational overhead is to first grasp the theoretical foundations they are built on top of. Then, you can augment your understanding with experiments and profiling.