c - issue in gprof(always accounting as zero) -


i having following program

#include<stdio.h> #include<stdlib.h> typedef struct struct_node {         int data;         struct struct_node *next; }node; typedef node* list; list st=null; list prev; list insert(list); list delete(list); void display(list); int n; main() {     int ch;     while(1)     {         printf("menu\n");         printf("----\n");         printf("1.insert\n");         printf("2.delete\n");         printf("3.print\n");         printf("4.exit\n");         printf("enter choice:");         scanf("%d",&ch);         switch(ch)         {             case 1:                 st=insert(st);                 printf("new node inserted successfully\n");                 break;             case 2:                 st=delete(st);                 printf("\ndeletion successful.contents are:\n");                 display(st);                 break;             case 3:                 display(st);                 break;             case 4:                 exit(0);             default:                 printf("it invalid choice\n");                 exit(0);         }     } }    void display(list temp) {      sleep(100);     printf("the linked list\n");     printf("---------------\n");     while(temp)     {         printf("%d\n",temp->data);         temp=temp->next;     }  } list insert(list temp) {     list new;     int i=0;     int first=0;     int ch;     list prev,current;     printf("enter data insert:");     scanf("%d",&n);     printf("menu\n");     printf("----\n");     printf("1.insert @ first\n");     printf("2.insert @ last \n");     printf("3.insert @ middle\n");     printf("enter choice:");     scanf("%d",&ch);     switch(ch)     {             case 1:             new=(list)malloc(sizeof(list));             new->data=n;                 new->next=temp;             st=new;             return st;             break;         case 2:             st=temp;             while(temp->next!=null)                 temp=temp->next;             new=(list)malloc(sizeof(list));             temp->next=new;             new->data=n;             new->next=null;             return st;             break;         case 3:             new=(list)malloc(sizeof(list));                 new->data=n;             st=temp;             while(temp->next!=null)             {                 ++i;                 prev=temp;                 if(prev->data < n)                 {                     ++first;                     current=prev->next;                     if(current->data > n)                     {                         new->next=current;                         prev->next=new;                         return st;                     }                 }                 temp=temp->next;             }             if(i==0)             {                 if(temp->data < n)                 {                     temp->next=new;                     new->data=n;                     new->next=null;                 }                 else                 {                     new->next=temp;                     temp->next=null;                     st=new;                 }             }             else             {                 if(first==0)                 {                     new->next=temp;                     new->data=n;                     return st;                 }                 temp->next=new;                 new->data=n;                 new->next=null;             }                                    return st;             break;             default:                 printf("invalid choice\n");                 break;                 }                            } list delete(list temp) {     int ch;     int val;     display(st);     printf("menu\n");     printf("1.delete first\n");     printf("2.delete last node\n");     printf("3.delete middle\n");     printf("enter option:");     scanf("%d",&ch);     switch(ch)     {         case 1:             temp=temp->next;             st=temp;             return st;             break;         case 2:             st=temp;             prev=st;             while(temp->next!=null)             {                 prev=temp;                 temp=temp->next;             }             prev->next=null;             return st;             break;         case 3:             st=temp;             prev=st;                     printf("enter data removed\n");             scanf("%d",&val);             while(temp->data!=val)             {                 prev=temp;                 temp=temp->next;             }             prev->next=temp->next;             return st;             break;         default:             printf("invalid choice\n");             exit(0);     }  } 

i tried profile above program.

i have compiled program follows

cc -pg linklistadv.c

then ran program follows

./a.out  menu ---- 1.insert 2.delete 3.print 4.exit enter choice:1 enter data insert:1 menu ---- 1.insert @ first 2.insert @ last  3.insert @ middle enter choice:1 new node inserted menu ---- 1.insert 2.delete 3.print 4.exit enter choice:3 linked list --------------- 1 menu ---- 1.insert 2.delete 3.print 4.exit enter choice:4 

now used gprof command follows gprof -p a.out gmon.out

but showing output follows

flat profile:  each sample counts 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  display   0.00      0.00     0.00        1     0.00     0.00  insert   %         percentage of total running time of time       program used function.  cumulative running sum of number of seconds accounted  seconds   function , listed above it.   self      number of seconds accounted seconds    function alone.  major sort            listing.  calls      number of times function invoked, if            function profiled, else blank.   self      average number of milliseconds spent in ms/call    function per call, if function profiled,        else blank.   total     average number of milliseconds spent in ms/call    function , descendents per call, if         function profiled, else blank.  name       name of function.  minor sort            listing. index shows location of        function in gprof listing. if index        in parenthesis shows appear in        gprof listing if printed. 

what problem? why showing 0.00 time accounted? display function run 100 seconds. showing time 0.00 only. please guide me.

thanks in advance!

sleep(100) not use 100 seconds of cpu time. instead, os's kernel suspends program execution. gprof measures used cpu time, not time program suspended. might want search explanations of "cpu time" , "wallclock time".


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -