| 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.
|















Legitcode.com : All Rights Reserved