Question
1/ What output I should expect while I would like to do profiling using clang compiler?
2/ How can I do profiling for a C++ project which uses clang as a compilerandCMake` as a build tool?
Regrading profiling what I have used
1/ Firstly, I have used valgrind tool to check the performance of a cpp executable.
2/ Later, I have used g++ compiler and gone through this where I have seen steps to perform profiling with gprof. Stuffs using gprof I have done by command line. From, this source I came to know that gprof can provide a output of text file (mentioned as analysis.txt) where function call number, execution time etc is written.
My goal and approaches I have taken so far
- Now, in my project, I can only use
clangcompiler andCMakebuild tool. I have read clang documentation, mainly this and this. - In first trial, I have put two
cpp filein the same directory (which is obviously not the desired project structure) and followed the following command to see how Instrumentation is done and whatoutcomeis coming
clang++-10 -fprofile-instr-generate -fcoverage-mapping test_gprof.cpp test_gprof_new.cpp -o code_coverage
LLVM_PROFILE_FILE="code_coverage.profraw" ./code_coverage
llvm-profdata merge -sparse code_coverage.profraw -o code_coverage.profdata
llvm-cov show -show-line-counts-or-regions --show-regions=1 --show-expansions ./code_coverage -instr-profile=code_coverage.profdata
llvm-cov report ./code_coverage -instr-profile=code_coverage.profdata
I am really not sure whether I have followed correct steps or not, but I have expected to see some analysis statistics.
- Finally, I can see a
reporton which I have understood nothing. Here, my first question came to mind that what exactly I can expect while I doprofiling? - And, I have no idea how to activate this profiling process in
CMakefor clang compiler. A dummy folder structure is given below which resembles the real one
clang_profile_cmake/
├── CMakeLists.txt
├── example
│ └── main.cpp
├── include
│ ├── test_gprof.h
│ └── test_gprof_new.h
├── README.md
└── src
├── test_gprof.cpp
└── test_gprof_new.cpp
Recent search (Still unable to generate any profiling data by CMake, Clang compiler)
- I have to add LLVM to my project. I have followed this
- The CMakeLists.txt file I am using is available here
- Don't understand how/where/in which step I can enable the profiling flags (
-fprofile-instr-generate -fcoverage-mapping,LLVM_PROFILE_FILE,llvm-profdata merge... etc)