Profiling using GCC internal GCOV
root@ALOPRASA-EAN6Q: # cat hello.c
#include
int main()
{
int i;
for (i = 0;i<100;i++)
{
if(i<5)
printf("hello\n");
}
return 0;
}
root@ALOPRASA-EAN6Q: # gcc -fprofile-arcs -ftest-coverage hello.c
root@ALOPRASA-EAN6Q: # ls
a.out hello.c hello.gcno
root@ALOPRASA-EAN6Q: # ./a.out
hello
hello
hello
hello
hello
root@ALOPRASA-EAN6Q: # gcov hello.c
File 'hello.c'
Lines executed:100.00% of 5
Creating 'hello.c.gcov'
root@ALOPRASA-EAN6Q: # cat hello.c.gcov
-: 0:Source:hello.c
-: 0:Graph:hello.gcno
-: 0:Data:hello.gcda
-: 0:Runs:1
-: 0:Programs:1
-: 1:#include
1: 2:int main()
-: 3:{
-: 4: int i;
101: 5: for (i = 0;i<100;i++)
-: 6: {
100: 7: if(i<5)
5: 8: printf("hello\n");
-: 9: }
-: 10:
1: 11:return 0;
-: 12:}
For timing Analysis internal tool is Gprof.
ReplyDeletehttps://codeyarns.com/2013/06/24/how-to-profile-c-or-c-code-using-gprof/