0

I have a big C++ program in VS code under Ubuntu 18.4, I am using CMake. I need to Know what areas are spending more time and memory space. I am a beginner in coding in Linux and using CMakeLists.txt files. I tried to use gprof, I added

if(MSVC AND MT)
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
    set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
    set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
    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")
endif() 

to my CMakeLists.txt file. Then I complied the program using cmake .. and then make, after that I run the program with an example, and when using the command gprof ./myexe I get gmon.out: No such file or directory

user108724
  • 67
  • 9
  • Search the internet for "C++ benchmark" or "C++ profile". Always search the internet first. – Thomas Matthews Jun 05 '21 at 15:54
  • Recommend adding which tool chain you are using to narrow down the question. – user4581301 Jun 05 '21 at 15:54
  • @user4581301 I added `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")` to my `CMakeLists.txt` file. Then I complied the program using `cmake ..` and then `make`, after that I run the program with an example, and when using the command `gprof ./myexe` I get `gmon.out: No such file or directory` – user108724 Jun 05 '21 at 16:07
  • 2
    That should be in the question. It answers my question, the tool is `gprof`, and will make the question more meaningful. Also change the title to highlight that you are using `gprof` and getting an error; It's more specific and more likely to attract the attention of a `gprof` expert. JUst as important, it'll make the question easier to find for future askers. But before you go too much further, have you done a websearch for `gmon.out: No such file or directory`? Five bucks says you're not the first or last person to struggle with this. – user4581301 Jun 05 '21 at 16:20
  • @user4581301 I did not specify gprof in my question because I wanted suggestions for suitable profilers in VS code, but I will edit my questions to at least start profiling. – user108724 Jun 05 '21 at 16:24
  • 1
    See if valgrind's callgrind tool is of use to you. Google has (or at least had) a profiler but I can't remember the name exactly. perftool should be close, but it's from google so there'll be a g in the name somewhere. – user4581301 Jun 05 '21 at 16:29
  • 1
    See also [softwarerecs.se]. – Thomas Matthews Jun 05 '21 at 16:48
  • 1
    [*Don't*](https://stackoverflow.com/a/378024/23771) – Mike Dunlavey Jun 05 '21 at 22:43

0 Answers0