Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: Dice on January 14, 2016, 02:54:39 am

Title: I have enabled "Profile code when executed [-pg]" but can't get Gprof to work.
Post by: Dice on January 14, 2016, 02:54:39 am
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.
Title: Re: I have enabled "Profile code when executed [-pg]" but can't get Gprof to work.
Post by: oBFusCATed on January 14, 2016, 09:32:24 am
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.
Title: Re: I have enabled "Profile code when executed [-pg]" but can't get Gprof to work.
Post by: Dice on January 14, 2016, 11:13:42 am
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.
Title: Re: I have enabled "Profile code when executed [-pg]" but can't get Gprof to work.
Post by: stahta01 on January 14, 2016, 02:39:57 pm
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.
Title: Re: I have enabled "Profile code when executed [-pg]" but can't get Gprof to work.
Post by: oBFusCATed on January 14, 2016, 08:43:14 pm
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.
Title: Re: I have enabled "Profile code when executed [-pg]" but can't get Gprof to work.
Post by: Dice on January 15, 2016, 05:32:24 am
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.
Title: Re: I have enabled "Profile code when executed [-pg]" but can't get Gprof to work.
Post by: Alpha on January 15, 2016, 05:56:05 am
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.
Title: Re: I have enabled "Profile code when executed [-pg]" but can't get Gprof to work.
Post by: Dice on January 15, 2016, 06:22:17 am
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!
Title: Re: I have enabled "Profile code when executed [-pg]" but can't get Gprof to work.
Post by: oBFusCATed on January 15, 2016, 09:44:54 am
Read the docs, please. They'll make lots of thing clear what gprof can and cannot do.
Title: Re: I have enabled "Profile code when executed [-pg]" but can't get Gprof to work.
Post by: Dice on January 15, 2016, 10:11:19 am
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/
Title: Re: I have enabled "Profile code when executed [-pg]" but can't get Gprof to work.
Post by: oBFusCATed on January 15, 2016, 08:45:25 pm
Seems like it is.