Command of the Day: gprof

May 12, 2007

gprof displays profile data for an object file. To use gprof I first needed to add “-g -pg” to my g++ options – i.e.

$ g++ -g -pg main.cpp

Then I simply needed to run the output executable (./a.out) which produced a file named gmon.out in the current directory.

Executing gprof is now enough to get some basic profiling information – e.g.:

% cumulative self self total
time seconds seconds calls s/call s/call name
100.52 9.73 9.73 5 1.95 1.95 run()
0.00 9.73 0.00 1 0.00 0.00 init()

The app ran for almost 10 seconds, made 5 calls to run which ran, on average, about 2 seconds per call.

Pretty simple high-level profiling.

The sample app was nothing more than a busy-wait (I wanted to busy wait otherwise all of the samples ended up in the call to sleep).

It’s code is:


void init() {

void run() {
int limit = rand();

for(int i = 0; i

Some interesting command line options include:

-i Prints out some basic summary info (record counts)
-p Print basic call graph info
-z Display unused functions
-p Print basic call graph info
-A Print annotated source code

I intend to look more into gcov in the next few days to see what it has to offer.

While I'm on the topic of programming tools - what's available in the way of static analysis (i.e. lint) tools?

2 Responses to “Command of the Day: gprof”

  1. Walker Says:

    Have you thought about pumping your desktop?
    Could you show us the screenshot of your desktop?
    Is it default yet?

  2. makingtheswitch Says:

    I’m still using the default desktop. I’ve spent a little time looking at some of the options to make little changes here-and-there but nothing interesting. Once I get a little further along I’ll probably spend more time on the desktop.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s