Visits

[+/-]
Today:
Yesterday:
Day before yesterday:
494
715
587

+128
This week:
Last week:
Week before last week:
1796
4156
3775

+381

Last month:
Month before last month:
4779
14827
11323

+3504

Visitor Data

IP ADDRESS
38.107.191.85
-
Location
United States
-
Browser
Unknown Browser
-
Operating System
Unknown Operating System

Most Downloaded


No Documents
Add to: JBookmarks Add to: Bookmarks.cc Add to: Digg Add to: Reddit Add to: Upchuckr Add to: StumbleUpon Add to: Slashdot Add to: Blogmarks Add to: Technorati Add to: Newsvine Add to: Blinkbits Add to: Smarking Add to: Spurl Add to: Google Information

27

Aug

Profiling C applications
Profiling C Applications - Assume you have the following program p1.c:

/* Program p1.c */
#include
#include

t1(int i)
{
printf("t1:%d\n", i);
}

t2(int j)
{
printf("t2:%d\n", j);
}

int main(void)
{
int i, j;

for (i = 0; i < 5; ++i) {
t1(i);
for (j = 0; j < 2; ++j) {
t2(j);
}
}
}

Compile the program as follows:

$ gcc -pg -g -o p1 p1.c
$ ./p1
t1:0
t2:0
t2:1
t1:1
t2:0
t2:1
t1:2
t2:0
t2:1
t1:3
t2:0
t2:1
t1:4
t2:0
t2:1

Next, to get the profile graph.

$ gprof -p -b p1
Flat profile:

Each sample counts as 0.01 seconds.
no time accumulated

% cumulative self self total
time seconds seconds calls Ts/call Ts/call name
0.00 0.00 0.00 10 0.00 0.00 t2
0.00 0.00 0.00 5 0.00 0.00 t1


Above note the 10 calls to t2 and 5 calls to t1.