2

I am new to gprof, this is my program,

 #include<stdio.h>
int somefunc(int n)
{
 int i,j;
for(i=1;i<=n;i++){
for(j=1;j<=i;j++){
  printf("%d\t",j);
}
printf("\n");
}
}
int somefunc1(int n)
{
  int i,j;
  for(i=n;i>=1;i--){
  for(j=i;j>=1;j--){
  printf("%d\t",j);
 }
 printf("\n");
}

}

int main()
{
  printf("Hello\n");
  int n;
  printf("enter n value\n");
 scanf("%d",&n);
 somefunc(n);
 printf("another\n\n");
 somefunc1(n);
printf("another\n") ;
}

and i tried this,

gcc -pg program.c
./a.out
gprof a.out gmon.out

and it is not diaplaying time, i e it is displaying 0.0% time even if it is taking more than 20 min? output is like this,

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        1     0.00     0.00  somefunc
 0.00      0.00     0.00        1     0.00     0.00  somefunc1
no1
  • 717
  • 2
  • 8
  • 21
  • What is your OS? GCC version? Can you do an strace of the `./a.out` and search for ALRM or `alarm()` in strace output? – osgx Sep 23 '13 at 09:39
  • Did the program ended with `return` or `exit()`? Gmon.out is written only at normal program exit, and not written if the program was stopped using Ctrl-C. – osgx Sep 23 '13 at 09:41
  • gcc version 4.1.2 20080704 (Red Hat 4.1.2-51) – no1 Sep 23 '13 at 10:49
  • program ends with exit() only.. – no1 Sep 23 '13 at 10:50
  • What about `-g` option and strace with search for ALRM? – osgx Sep 23 '13 at 11:30
  • How much SIGALRM there were in the strace output? Try to replace printf with something CPU-intensive, for example, `cos(sin(i))`. – osgx Sep 24 '13 at 17:59

1 Answers1

2

gprof does not sample during I/O or other non-process time.

Since your program does practically nothing besides I/O, gprof is showing you practically nothing.

See this.

Community
  • 1
  • 1
Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135