performance - Change C code to run fully (including all sections of if) -


note: realise question not clear. have modified now, , apologise making mistake in first place.

i have large c project run on embedded system. use arm compiler. code spread across multiple sub-folders, , consists of .c , .h files.

i wish take stock of function called how many times, can identify dead code , speed used functions. arm compiler has few options removing unreachable code, fails when function pointers come play so, i'd go through every branch of code , keep count of number of calls function.

for example (this very simple program demonstrate looking for, not original code):

void foo1(void) {     printf("number divisible 5"); } void foo2(void) {     printf("number divisible 10"); } void foo3(void) {     printf("number divisible neither 10 nor 5"); } void foo4(void) {     printf("foo4 called"); }   int main (void) {     int x;      x = rand (11);      if (! x%10)     {         foo2();         foo1();     }     else if (! x%5)       foo1();     else             foo3();      return 0; } 

i'd run through entire code access sections of if branch (i.e foo1, foo2, , foo3). me identify function called how many times. in above example foo1() called more foo2(), , foo4() never called. make sense identify , remove foo4() , optimise foo1().

any ideas/tools run entire code ?

one of ways thought modify main function so:

int main (void) {     int x ;      x = rand (11);      //*************************************************     //starting modification     int = 1; //added me     if_1: //added me     if (a == 1)     {         foo1(); //original code         foo2(); //original code          a=2; //added me         goto if_1; //added me     }      else if (a==2)     {         foo2(); //original code         a=3; //added me         goto if_1: //added me     }     else             foo3(); //original code     //end of modification     //********************************************************              return 0; } 

this way runs through original code. idea how type of modification?

int main (void) {     int x = 5; #ifdef debug     int debug_i, debug_data[] = { 5, 10, 20 };     for(debug_i = 0;debug_i<sizeof debug_data / sizeof *debug_data;++debug_i){         x = debug_data[debug_i]; #endif     if (x==5)        foo1();     else if (x==10)  foo2();     else             foo3(); #ifdef debug     } #endif      return 0; } 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -