Modify Source Code

Replace the source code of the main.cpp file of your project with the source code shown in the listing below. To open the main.cpp file:

  1. Expand the Sources node of your project in the CodeWarrior Projects view.
  2. Double-click main.cpp to open its contents in the editor area.

You need to modify the source code such that it uses the profiler API to do profiling. This source code uses:

The source files that make calls to the profiler API must include the appropriate header file for your target. The header file that the ColdFire V4e target uses for profiling is:


  #include <Profiler.h>

Listing: Sample source code used for profiling
#include <stdio.h>

#include <Profiler.h>



/*---------------Loop constant definition--------------------*/



# define LOOP_1  0x0001FFFF



# define LOOP_2  0x0002FFFF



# define LOOP_3  0x0003FFFF



# define LOOP_4  0x0001FFFF



# define LOOP_5  0x0002FFFF



# define LOOP_6  0x0003FFFF



# define LOOP_7  0x0001FFFF



# define LOOP_8  0x0002FFFF



# define LOOP_9  0x0003FFFF



# define LOOP_10 0x0001FFFF



/*----------------------Global function Declaration-------------*/



void fn1(int loop);



void fn2(int loop);



void fn3(int loop);



void fn4(int loop);



void fn5(int loop);



void fn6(int loop);



volatile int fn7( int a );



/*-----------------Class One Definition-----------------------*/



class One



{



public:



       void one_fn1(int loop);



};



/*---------------Class One's function Definition--------------*/



void One::one_fn1(int loop)



{



   unsigned int i,j;



   printf("In function : One::one_fn1 \n\r");



   for( i = 0 ; i < loop ; i++)



   {



      for( j = 0; j < 0x12 ; j++ )



      {}



   }



}



/*----------------Class Two Defination-------------------------*/



class Two



{



private:



        One test;



public:



        void two_fn1(int loop);



        void two_fn2(int loop);



};



/*---------------Class Two's function Defination----------------*/



void Two::two_fn1(int loop)



{



    unsigned int i,j;



    printf("In function : Two::two_fn1 \n\r");



    for( i = 0 ; i < loop ; i++)



    {



       for( j = 0; j < 0x12 ; j++ )



       {}



    }



    two_fn2(LOOP_9);



}



void Two::two_fn2(int loop)



{



      unsigned int i,j;



      printf("In function : Two::two_fn2 \n\r");



      for( i = 0 ; i < loop ; i++)



      {



          for( j = 0; j < 0x12 ; j++ )



          {}



      }



      test.one_fn1(LOOP_10);



}



/*----------------Global function Defination--------------------*/



volatile int fn7( int a )



{



  int i;



  printf("In function : fn7 \n\r");



  if( a == 1 )



  {



    for( i = 0; i < 240000; i ++ );



    return 1;



  }



  else



    return a * fn7( a - 1 );



}



void fn6(int loop)



{



    unsigned int i,j;



    printf("In function : fn6 \n\r");



    for( i = 0 ; i < loop ; i++)



    {



        for( j = 0; j < 0x12 ; j++ )



        {}



    }



}



void fn5(int loop)



{



     unsigned int i,j;



     printf("In function : fn5 \n\r");



     for( i = 0 ; i < loop ; i++)



     {



        for( j = 0; j < 0x12 ; j++ )



        {}



     }



}



void fn4(int loop)



{



     unsigned int i,j;



     printf("In function : fn4 \n\r");



    for( i = 0 ; i < loop ; i++)



    {



       for( j = 0; j < 0x12 ; j++ )



       {}



    }



}



void fn3(int loop)



{



    unsigned int i,j;



    printf("In function : fn3 \n\r");



    for( i = 0 ; i < loop ; i++)



    {



       for( j = 0; j < 0x12 ; j++ )



       {}



    }



}



void fn2(int loop)



{



    unsigned int i,j;



    printf("In function : fn2 \n\r");



    for( i = 0 ; i < loop ; i++)



    {



       for( j = 0; j < 0x12 ; j++ )



       {}



    }



    fn3(LOOP_3);



}



void fn1(int loop)



{



    unsigned int i,j;



    printf("In function : fn1 \n\r");



    for( i = 0 ; i < loop ; i++)



    {



       for( j = 0; j < 0x12 ; j++ )



       {}



    }



    fn2(LOOP_2);



}



/*---------------main function Definition----------------------*/



int main()



{



   One a;



   Two b;



   printf("Profiler yet to start C\n\r");



// Following section of code initialises the profiler



   ProfilerInit(collectDetailed, bestTimeBase, 5,20);     



   ProfilerClear();



   ProfilerSetStatus(1);



   printf("Profiler has just started \n\r");



// Code to be profiled



   fn1(LOOP_1);     



   fn4(LOOP_4);



   fn5(LOOP_5);



   fn6(LOOP_6);



   fn7(4);



   a.one_fn1(LOOP_7);



   b.two_fn1(LOOP_8);



   printf("Profiling is just to end \n\r");



// Following section of code terminates the profiler



   ProfilerSetStatus(0);       



   ProfilerDump("profiledump");



   ProfilerTerm();



   printf("I have all the Profile Data \n\r");



   return 0;



}