Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a profiler for C (gcc) to profile code lines separately? [closed]

I come from a Matlab background so I am used to a profiler which profiles every single line and not just every function like gprof or callgrind. Is there a profiler for C with a similar feature?

Thanks!

screenshot matlab profiler
(source: jburkardt at people.sc.fsu.edu)

like image 502
Framester Avatar asked Jul 16 '10 09:07

Framester


2 Answers

You can use use the GNU utility GCOV to do line by line profiling. Sample run from GCC Docs .

$ gcc -fprofile-arcs -ftest-coverage tmp.c
$ a.out
$ gcov tmp.c
  90.00% of 10 source lines executed in file tmp.c
  Creating tmp.c.gcov

The file tmp.c.gcov contains output like:

     -:    0:Source:tmp.c
     -:    0:Graph:tmp.gcno
     -:    0:Data:tmp.gcda
     -:    0:Runs:1
     -:    0:Programs:1
     -:    1:#include <stdio.h>
     -:    2:
     -:    3:int main (void)
     1:    4:{
     1:    5:  int i, total;
     -:    6:
     1:    7:  total = 0;
     -:    8:
    11:    9:  for (i = 0; i < 10; i++)
    10:   10:    total += i;
     -:   11:
     1:   12:  if (total != 45)
 #####:   13:    printf ("Failure\n");
     -:   14:  else
     1:   15:    printf ("Success\n");
     1:   16:  return 0;
     -:   17:}
like image 58
mikek3332002 Avatar answered Oct 31 '22 20:10

mikek3332002


I believe callgrind does that. I know it does cycle counts per line, but I'm not sure about 'time.'

like image 44
Tony Stark Avatar answered Oct 31 '22 20:10

Tony Stark