2

I am trying to profile a Qt window application that I am developing and have read up on the methods to profile using gprof. I have successfully configure the project to compile and link with the -pg flags to enable profiling and the gmon.out is output everytime the the application is executed. However when I tried to run gprof to convert the gmon.out file into a readable txt file, I ran into the "gmon.out too short to be a gmon file" error message. I tried googling for an answer to this problem but to no avail. Someone also asked the same question here but no answer was given.

I am using Qt 4.7.4 with Qt Creator 2.3.0 with mingw compiler on Windows 7 for this project.

The flags I have set in the .pro files are:

# Profiler flags
CONFIG += DEBUG
QMAKE_CXXFLAGS_DEBUG += -pg
QMAKE_CXXFLAGS_MT_DBG += -pg
QMAKE_LFLAGS_DEBUG += -pg

This is how I called gprof from command prompt:

C:\QtSDK\mingw\bin>gprof "C:\Qt exe\debug\QtGUI.exe" > profile.txt

And the error message: gmon.out: file too short to be a gmon file

I have also checked the file size for gmon.out; it is around 520 kb each time I ran the debug application. Is this really too short to be a gmon file?

ksming
  • 1,332
  • 1
  • 14
  • 25
  • I could be wrong about this, but to run `gprof` don't you just run `gprof` with no arguments? I think you might be trying to have `gprof` run on your executable rather than on `gmon.out`. – templatetypedef Feb 08 '12 at 04:21
  • What do you mean by "have gprof run on your executable rather than on gmon.out" ? From what I have read in http://www.cs.utah.edu/dept/old/texinfo/as/gprof.html#SEC4 , this is how we should run it unless I am misreading something there. – ksming Feb 08 '12 at 05:08
  • @ksming- Normally when I run `gprof`, I run the program to profile, then just run `gprof` with no other command-line arguments. It by default processes `gmon.out`. Have you given this a try? – templatetypedef Feb 08 '12 at 05:10
  • I have tried that but it looked for a.out by default instead. Must I put gmon.out on the directory as gprof? – ksming Feb 08 '12 at 09:19
  • Hmmm... never mind! I guess I'm mistaken about this. – templatetypedef Feb 08 '12 at 09:30
  • When you get gprof to work, it's going to tell you all the CPU goes into system routines like painting and memory allocation. *[There are better ways.](http://stackoverflow.com/questions/1777556/alternatives-to-gprof/1779343#1779343)* – Mike Dunlavey Feb 09 '12 at 13:25

1 Answers1

0

When running gprof, if you omit the name of the output file, gprof assumes a default name "gmon.out". This file should be in the same folder where you are running gprof.

So, when running the program, check that the output file gmon.out was correctly generated in the folder where you are running. Also pay attention to the directory, as you can read here

The gmon.out' file is written in the program's current working directory at the time it exits. This means that if your program calls chdir, thegmon.out' file will be left in the last directory your program chdir'd to. If you don't have permission to write in this directory, the file is not written.

( from: http://www.cs.utah.edu/dept/old/texinfo/as/gprof.html )

In that case you can specify the output file path as:

C:\QtSDK\mingw\bin>gprof QtGUI.exe path_to_outfile\gmon.out > profile.txt

Hope this helps.

Ciao!

rmbianchi
  • 5,503
  • 4
  • 23
  • 23