Author Topic: I have enabled "Profile code when executed [-pg]" but can't get Gprof to work.  (Read 8035 times)

Offline Dice

  • Multiple posting newcomer
  • *
  • Posts: 14
I'm using Code::Blocks 13.12 with MinGW -w64 (TDM-GCC suite) compiler on Windows 7.  I have went to --> Settings --> Compiler--> Compiler Settings and checked the box next to "Profile code when executed [-pg]".  Next I build and ran my program in "Debug" mode.  Then I went to --> Plugins --> Code Profiler and selected "Debug" and then pressed "OK".  I then get a pop-up message that says "Cannot find gmon.out.  No profile data found!  Be sure to enable "Profile Code when executed" for the current target.  The target must have been run at least one time after that.  Do you want to search for the profile data file?"

I checked the /bin folder where my compiler is stored and I found gprof.exe so I'm pretty sure I have Gprof.  Is there something else I need to do in order to profile my code?  Am I doing something completely wrong?  Thanks for your time.  This is my first time using a profiler.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
The profile data is stored in a gmon.out file.
Do you have one created after you run your exe?
Have you checked the build log after you've enabled the option?

p.s. If you don't have a project probably it is a good idea to create one.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Dice

  • Multiple posting newcomer
  • *
  • Posts: 14
The profile data is stored in a gmon.out file.
Do you have one created after you run your exe?
Have you checked the build log after you've enabled the option?

p.s. If you don't have a project probably it is a good idea to create one.

Thanks for the reply.  Yes I have created a project and I've checked the project folder but don't see gmon.out in there.  I've also checked the "bin" and "obj" sub-folders but don't see gmon.out.  The project is just a simple printf("Hello World!\n");.  In the build log there is nothing unusual or mention of Gprof.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Remember the "-pg" option needs to be with both the compiler and the linker.

Edit:
My build and run logs; the gmon.out was created in the project folder. If you still have problems post the build log.
Code
-------------- Build: Debug in profile_test (compiler: GNU GCC Compiler)---------------

x86_64-w64-mingw32-g++.exe -Wall -pg -fexceptions -g -Wmissing-include-dirs -DHAVE_TR1_TYPE_TRAITS -DGIT_BUILD  -c C:\SourceCode\test\profile_test\main.cpp -o obj\Debug\main.o
x86_64-w64-mingw32-g++.exe  -o bin\Debug\profile_test.exe obj\Debug\main.o  -pg -lgmon -pg 
Output file is bin\Debug\profile_test.exe with size 164.69 KB
Process terminated with status 0 (0 minute(s), 12 second(s))
0 error(s), 0 warning(s) (0 minute(s), 12 second(s))
 

-------------- Run: Debug in profile_test (compiler: GNU GCC Compiler)---------------

Checking for existence: C:\SourceCode\test\profile_test\bin\Debug\profile_test.exe
Executing: "C:\Program Files (x86)\CodeBlocks_13_12/cb_console_runner.exe" "C:\SourceCode\test\profile_test\bin\Debug\profile_test.exe"  (in C:\SourceCode\test\profile_test\.)
Process terminated with status 0 (0 minute(s), 2 second(s))

Tim S.
« Last Edit: January 14, 2016, 02:55:56 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Thanks for the reply.  Yes I have created a project and I've checked the project folder but don't see gmon.out in there.  I've also checked the "bin" and "obj" sub-folders but don't see gmon.out.  The project is just a simple printf("Hello World!\n");.  In the build log there is nothing unusual or mention of Gprof.
Have you read the docs for gprof? If not take a look at them. It will enlighten you what gprof is capable and what it isn't.
Probably you're app is running for too short time. Try doing some work for 10-20 seconds and report back it still doesn't work.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Dice

  • Multiple posting newcomer
  • *
  • Posts: 14
Thanks stahta01 and oBFusCATed for your help.  I was able to get it working but adding an extra printf("Test\n"); after my Hello World.  I'm not sure why it works now and it didn't before.  I do have one other question for you if you don't mind.  On "Gprof's Output" under the tabs "Flat Profile" and "Call Graph" there doesn't seem to be any data.  Is this because my program is too short like oBFusCATed suggested?  Do I need to do something else in order to populate this with data?  Thanks for your time.

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
If you are essentially running a "hello world" program that finishes in a fraction of a second, there simply is not any profiling data for gprof to collect, so nothing can be output.

Offline Dice

  • Multiple posting newcomer
  • *
  • Posts: 14
If you are essentially running a "hello world" program that finishes in a fraction of a second, there simply is not any profiling data for gprof to collect, so nothing can be output.

Thanks.  I added a getchar() and was able to pause the program long enough to get an output to gmon.  Thanks everyone for your help!

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Read the docs, please. They'll make lots of thing clear what gprof can and cannot do.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Dice

  • Multiple posting newcomer
  • *
  • Posts: 14
Read the docs, please. They'll make lots of thing clear what gprof can and cannot do.

Will do, thanks for all the help.  Just for clarity, is this the doc you're talking about? https://sourceware.org/binutils/docs/gprof/

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Seems like it is.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]