profiling of C++ code

Hi,

I am trying to find a good profiling tool for my C++ code, I tried gprof, but it does not do what I want. Maybe I didn't use gprof properly or there may be other profiling tool (such as "shark") I can download. I tried this code:

struct A {
int pro funcone() { return 2; }
int pro functwo() { return 3; }
};

int main ( ) {
A a; int j;
for(unsigned int i=0;i<1000;++i) {
j+= a.pro funcone();
j+= a.pro functwo();
}
}

g++ -O0 -fno-default-inline -pg gprof.C
./a.out
gprof a.out > pro_results.dat
tail -8 pro_results.dat
% cumulative self self total
time seconds seconds calls ms/call ms/call name
0.0 0.00 0.00 2000 0.00 0.00 past end of text [1]
0.0 0.00 0.00 1 0.00 0.00 _main [33]
Index by function name

[33] _main [1] past end of text

As you can see, there are a total of 2000 function calls, but gprof does not differentiate between pro funcone and pro functwo, it does not even list the function names.

I saw some posting on Nov 2005 saying Shark is a better profiling tool. Where can I download it? I tried google and as well as searching apple.com downloads without sucess. Will appreciate if someone can give me some pointers where to get Shark or solve my gprof problem. Thank you.

Sincerely,
Hwee Kuan

iMac mini, Mac OS X (10.4.3)

Posted on Jan 8, 2006 1:02 AM

Reply
4 replies

Jan 8, 2006 7:01 AM in response to Hwee Kuan Lee

hi,

Thanks for the help. I started x-code and looked for Shark. In the "Debug -> Launch using performance tools" menu, I can see "Shark", "Sampler", "MallocDebug" and "ObjectAlloc", I am able to invoke all except "Shark" which is being greyed out. I looked into /Developer/Applications/Performance Tools directory and I don't see Shark. I seems that Shark is not in my system. Hence I tried download it from apple.com but could not find where to download it. (My X-code is version 2.2).

The next issue is regarding Sampler. Failing to use Shark, I tried sampler. I loaded and ran a program (shown below), but there is no output. I used "Watch for: Timed Samples" with sample rate 1 msecs. Then I clicked "Launch & Record" and waited for the program to finish, there is no output in Browser, outline and Trace.

Any help will be much appreciated. Thank you.


struct A {
int pro funcone() {
int j=0;
for(unsigned int i=0;i<100000000;++i) { j+=i; }
return j;
}
int pro functwo() {
int j=0;
for(unsigned int i=0;i<10000000;++i) { j+=i; }
return j;
}
};

int main ( ) {
A a; int j;
for(unsigned int i=0;i<10;++i) {
j+= a.pro funcone();
j+= a.pro functwo();
}
}

g++ -O0 -fno-default-inline gprof.cpp

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

profiling of C++ code

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.