PDA

View Full Version : Profiling problems



Tindor
21st December 2006, 21:55
Hi,
I've just written my small app, but want to profile it in order to optimize it.
I tried adding -pg flags in the CFLAGS, CXXFLAGS, LIBS and in the make targets, but no gmon.out is created. I googled the problem, but found no answer :(.

wysota
21st December 2006, 22:43
You should add the flag in your project file to the variable called QMAKE_CXXFLAGS_DEBUG.

Tindor
22nd December 2006, 15:55
Well, I added it, but it stil does not create gmon.out.
I also noticed this in the Makefile:

DEFINES = -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED

And when I remove it and try "make" it's put in there again, maybe that's the problem.

jpn
22nd December 2006, 16:09
Looks like you are compiling a release version. Also, you must compile and link it with the corresponding profiling flags.



QMAKE_CXXFLAGS_DEBUG *= -pg
QMAKE_LFLAGS_DEBUG *= -pg



$ qmake -config debug
$ make

Tindor
23rd December 2006, 22:26
Well, now I can debug the program with gdb , but still no gmon.out is created :(

wysota
24th December 2006, 00:16
Does the compilation run with -pg compiler flags? Did you recreate the Makefile after modyfiing the project file?

Tindor
24th December 2006, 00:35
It does, here's the code:

g++ -c -pipe -g -pg -pg -Wall -W -D_REENTRANT -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4 -I. -I/usr/include -I. -I. -o main.o main.cpp

Also, the makefile is supposed to be regenerated afer running qmake, am I wrong?

jacek
24th December 2006, 01:26
How do you start that application? gmon.out will be generated in the current directory and only if your application exits cleanly.

Check if you can generate gmon.out for this small example:

#include <QApplication>
#include <QPushButton>

int main( int argc, char **argv )
{
QApplication app( argc, argv );

QPushButton b( "Close" );
QObject::connect( &b, SIGNAL( clicked() ), &b, SLOT( close() ) );
b.show();

return app.exec();
}


################################################## ####################
# Automatically generated by qmake (2.00a) nie gru 24 01:16:45 2006
################################################## ####################

TEMPLATE = app
TARGET +=
DEPENDPATH += .
INCLUDEPATH += .

CONFIG += debug
QMAKE_CXXFLAGS_DEBUG *= -pg
QMAKE_LFLAGS_DEBUG *= -pg

# Input
SOURCES += main.cpp


$ ls
main.cpp prof.pro
$ qmake
$ make
...
$ ls
main.cpp main.o Makefile prof prof.pro
$ ./prof
$ ls
gmon.out main.cpp main.o Makefile prof prof.pro

Tindor
24th December 2006, 14:43
Oops, I'm sorry I made you write the code. I've forgotten that I had to run the app in order to get a gmon.out.
Thank you very much ! :)

abbapatris
14th April 2009, 18:54
I am having a similar issue. My program is a very large program and I created my own shared libraries, but when I try to compile them with the -pg flag set in QMAKE_CXXFLAGS_DEBUG and in QMAKE_LFLAGS_DEBUG and then run it I don't get the gmon.out.

It is exiting normally and I have it set so that all the shared libraries are building with the flags. Any ideas?

wysota
14th April 2009, 22:58
This is a known issue with gprof. Please google around for using gprof with shared object files or use a different profiler such as Valgrind's callgrind tool.

abbapatris
15th April 2009, 01:12
gprof is the reason I don't get the gmon.out file? I thought that was part of the gcc

wysota
15th April 2009, 08:45
It's part of gcc but it's made for gprof. You'll find solutions much quicker if you google for "gprof and shared object files" than for "gcc and shared object files". And the file should be generated. It might be meaningless but it should get generated. Are you sure you linked with the -pg flag as well?

abbapatris
15th April 2009, 16:51
Yes it is in the linker string as well...I am trying to get it to work with shared libraries, but I can't get it to work with just a single executable either.

wysota
15th April 2009, 17:08
Check the actual compilation line (not what's inside qmake project file) if -pg is there for both compiling and linking phase. Also be sure to compile with -g (debug).

abbapatris
15th April 2009, 19:53
I think I found the issue, I just don't know how to fix it. gcc -pg main.c works fine but g++ -pg main.cpp compiles but doesn't output a gmon.out file. For some reason a C file will give us a profile but a C++ file wont.

abbapatris
16th April 2009, 14:06
Since this no longer seems to be a Qt issue I have posted the question in the google groups gnu.g++.help section. Thanks for the help

jpn
16th April 2009, 14:14
It must not be that simple. It works just fine for me. Try Jacek's example.

abbapatris
16th April 2009, 14:47
I tried his example...word for word and it doesn't produce a gmon.out file. the last line of the make output says....
Warning: consider linking with '-static' as system libraries with profiling support are only provided in archive format.

Currently Qt is built dynamically because the project I am on can't be built statically.

wysota
17th April 2009, 10:09
I tried his example...word for word and it doesn't produce a gmon.out file. the last line of the make output says....
Warning: consider linking with '-static' as system libraries with profiling support are only provided in archive format.
This only means you won't get profiling information from libraries such as libc which is good for you. Run the resulting application and you should get a gmon.out file.

abbapatris
17th April 2009, 12:19
Nope I only get the gmon.out file if I do -static when linking. I have tried running the application several times.

abbapatris
17th April 2009, 15:59
I think i found the issue...the server uses gcrt0.o rather then gcrt1.o and from what I have found from searching is that gcrt1.o is what I should be using for C++.

Can anyone confirm this for me?? I know this isn't a Qt issue

wysota
17th April 2009, 18:09
Eeeem... what server? :)

abbapatris
20th April 2009, 13:24
my company's server. Just the system we login to to build it. I have done some tests and have solved the issue, thanks for the help