Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Profiling g++ app on MacOSX?

Tags:

macos

g++

shark

My standard Linux way of profiling app is:

1) compile with g++ -pg
2) run prog
3) gprof

Apparently gprof is broek on MacOSX 10.5, and I am supposed to use Shark. All the tutorials I've found aby Shark involves XCode (whereas my build is done with Makefiels and g++).

Can someone post step by step instructions for using shark on an app built with g++? Say something like:

int main() { while(1); }

g++ blah.cpp -o blah; do I need to give it more command line arguments?

how do I use shark here?
like image 985
anon Avatar asked Feb 16 '10 12:02

anon


1 Answers

Instrumented profiling such as gprof is not particularly useful unless you really just want to know about call graphs and the number of times that functions are called. Much more useful for performance analysis is a sampling profiler, and for this Apple's Shark tool (part of CHUD) is one of the best.

You really don't need to use Xcode to build an app for profiling under Shark - I have command line tools built with Makefiles that I profile with Shark all the time. You can either trigger Shark automatically from within your code (there are a couple of different APIs for this) or you can use the "chudRemoteCtrl" command line tool (man chudRemoteCtrl) or you can just configure the Launch options in Shark to set the executable path, working directory, command line arguments, etc, and away you go. Make sure you build your app with -g so that Shark can display source code rather than disassembled object code.

Shark configuration for command line tool http://www.freeimagehosting.net/uploads/386737a1fa.jpg

like image 75
Paul R Avatar answered Oct 18 '22 19:10

Paul R