Hi all,

This might be bit of a silly question, but it's stumped me now for over a day and I've scourged the net for info but haven't found anything to sort out what I should be doing.

I am currently using Qt Creator 1.3.1 (Based on Qt 4.6.2 (32 bit)) to develop my code. I have a fully functioning program that I would now like to profile.

After searching the net I discovered that gprof is quite handy in providing a table indicating the runtime taken for various parts of the program.

My understanding is that in order to use gprof, I have to generate a gmon.out file, and that in turn this is generated by compiling and running my program with the "-pg" option.

So I discovered that I have to add a number of flags to my project file in Qt Creator to enable this option. My project file looks as follows:

SOURCES += accretion.cpp \
environment.cpp \
particle.cpp \
random.cpp \
simulation.cpp
HEADERS += environment.h \
particle.h \
random.h \
simulation.h \
ran.h
OTHER_FILES += tempfile.txt

CONFIG(release, debug|release):
QMAKE_CFLAGS+=-pg
QMAKE_CXXFLAGS+=-pg
QMAKE_LFLAGS+=-pg

I then compile and run the program, but no gmon.out file is generated as far as I can see.

I've tried looking up other flag info and it seems that the flags I'm using should work.

The start of the Makefile generated is as follows:

#############################################################################
# Makefile for building: MSPS.app/Contents/MacOS/MSPS
# Generated by qmake (2.01a) (Qt 4.6.2) on: Tue Mar 23 10:28:50 2010
# Project: MSPS.pro
# Template: app
# Command: /usr/bin/qmake -spec /usr/local/Qt4.6/mkspecs/macx-g++ -macx -o Makefile MSPS.pro
#############################################################################

####### Compiler, tools and options

CC = gcc
CXX = g++
DEFINES = -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED
CFLAGS = -pipe -pg -g -gdwarf-2 -arch i386 -Wall -W $(DEFINES)
CXXFLAGS = -pipe -pg -g -gdwarf-2 -arch i386 -Wall -W $(DEFINES)
INCPATH = -I/usr/local/Qt4.6/mkspecs/macx-g++ -I. -I/Library/Frameworks/QtCore.framework/Versions/4/Headers -I/usr/include/QtCore -I/Library/Frameworks/QtGui.framework/Versions/4/Headers -I/usr/include/QtGui -I/usr/include -I. -F/Library/Frameworks
LINK = g++
LFLAGS = -headerpad_max_install_names -pg -arch i386
LIBS = $(SUBLIBS) -F/Library/Frameworks -L/Library/Frameworks -framework QtGui -framework QtCore
AR = ar cq
RANLIB = ranlib -s
QMAKE = /usr/bin/qmake
TAR = tar -cf
COMPRESS = gzip -9f
COPY = cp -f
SED = sed
COPY_FILE = cp -f
COPY_DIR = cp -f -R
STRIP =
INSTALL_FILE = $(COPY_FILE)
INSTALL_DIR = $(COPY_DIR)
INSTALL_PROGRAM = $(COPY_FILE)
DEL_FILE = rm -f
SYMLINK = ln -f -s
DEL_DIR = rmdir
MOVE = mv -f
CHK_DIR_EXISTS= test -d
MKDIR = mkdir -p
export MACOSX_DEPLOYMENT_TARGET = 10.4

It seems to me that the "-pg" option is correctly added to the necessary flags.

If anyone can help me sort out why there is no gmon.out file generated, I would be very grateful.

Thanks in advance,

Kartik

How does your program exit?

One of the requirements for getting a gmon.out file is performing a "normal exit", which basically means dropping off the end of main() in the usual manner.

If your program just drops dead, then you're not going to get a profile.

Practice with some simple examples first.

How does your program exit?

One of the requirements for getting a gmon.out file is performing a "normal exit", which basically means dropping off the end of main() in the usual manner.

If your program just drops dead, then you're not going to get a profile.

Practice with some simple examples first.

My program exits normally through reaching the end of the main function. I will try and set up a simple example to play with as well, but I think the issue lies somewhere else in the setup of my profiling flags, or some other such option.

Thanks,

Kartik

Just to be on a safe side: after you added the flags, did the project files actually recompile?

Just to be on a safe side: after you added the flags, did the project files actually recompile?

Yes they do recompile fine.

I decided to go ahead and try setting up a simple exam. I make a simple "Hello World!" program in Qt Creator and ran it with the aforementioned flags, and the result is still no gmon.out.

I then decided to search the next for some simple examples that I can run straight from command line, so that I can check if the program lies with using Qt Creator.

I came across this example: http://www.network-theory.co.uk/docs/gccintro/gccintro_80.html.

I have done exactly what is said on that webpage, using the same code, and the same gcc commands, but the result is that there is still no gmon.out file generated.

Then I thought maybe the file is there, but just hidden, so I exposed the hidden files and couldn't find it either.

Then I thought maybe the file is just invisible, so I tried to run gprof as given on that website, and the result is the following:

gprof: file: a.out is not of the host architecture

So now I'm thinking that there's maybe just some compiler setting that's wrong. If that's not the case, then I'm totally stumped.

Just to add some info, I am running Mac OS X 10.5.8 (Leopard) with gcc 4.0.1.

I really hope someone can help me out as I need to sort this out asap to be able to continue with my simulation work (there's a bottleneck somewhere in the code but I just don't know where, and since I'm running large-scale simulations, I have to remove this bottleneck before I can continue with the full simulation).

Thanks a lot inadvance,

Kartik

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.