How to use gprof with cmake

寵の児 提交于 2019-12-23 07:38:36

问题


I have looked at dozens of tutorials for profiling with gprof. I'm trying to work with code for the SMT solver dReal. To build the program, I first installed g++-4.8, Bison, Flex, and Cmake. Then to build dReal, the instructions said to execute the following:

git clone git@github.com:soonhokong/dReal.git dreal  
cd dreal  
mkdir -p build/release  
cd build/release  
cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_COMPILER=g++-4.8 -DCMAKE_C_COMPILER=gcc-4.8 ../../src  
make

Where in here am I supposed to add the -pg? I'm new to programming, so reasoning as opposed to an answer would be much appreciated. I know you're supposed to add the -pg to the compilation stage but all the tutorials say to put it after g++ or gcc. I can't find how to modify the code for cmake. I did try changing the build type to PROFILE but that didn't help.


回答1:


In order to use gprof, you need to both compile and link with the -pg option.

CMakeLists.txt should have a setup like Ami Tavory mentioned, where command line options are combined with hardcoded options, so a good way to do this with a well built cmake project is:

cmake -DCMAKE_CXX_FLAGS=-pg -DCMAKE_EXE_LINKER_FLAGS=-pg -DCMAKE_SHARED_LINKER_FLAGS=-pg <SOURCE_DIR>



回答2:


I'm Soonho Kong, one of the maintainers of dReal. It would be easier for us to answer questions regarding dReal, if you put the "dreal" tag on the question.

  1. In general, you can pass compiler flags such as -pg to cmake by running:

    cmake -DCMAKE_CXX_FLAGS=-pg

  2. For the profiling, I normally use valgrind + callgrind.

  3. To measure the code coverage, we are using gcov and lcov tools. You may want to take a look at how we set up the compiler flags for that, which can help you set up your own compiler flags for gprof.



来源:https://stackoverflow.com/questions/26491948/how-to-use-gprof-with-cmake

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!