I'm having trouble running gprof
on OS X. The file test.c
is:
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
and my terminal looks like:
$ gcc -pg test.c
$ gcc -pg -o test test.c
$ ./test
Hello, World!
$ gprof test
gprof: file: test is not of the host architecture
Edit: also, it doesn't generate the file gmon.out
.
What's going on here?
The series of events here is supposed to work as follows:
-pg
option-pg
optiongmon.out
filegprof
The problem is that step 4 never happens. There's very little information out about this specific failure. The general consensus over the past few years seems to be that Apple would rather use shark instead, and they've been very lax about fixing bugs and such with
gprof
.In short: Install Xcode,
man shark
It sounds like
test
is built using an architecture thatgprof
doesn't expect. Try the following:The newer MacOS supports running executables from either the IBM PPC and Intel x86 architecture. Some of the tool chain seems to be a bit dense about this. Gprof seems to expect the executable to be in the native architecture. However, if you use the
arch
utility to force the non-native architecture to be executed, then it seems to work properly. There was a discussion about this in another context a little while ago. I included some useful links and some more information there.Unfortunately
gprof
does not work on Mac OS X. You'll probably want to useShark
instead. It is part of the developer tools in/Developer/Applications/Performance Tools/Shark
.Update: It appears as though
gprof
is now working on Mac OS X 10.6 (Snow Leopard), using the latest Developer Tools.