Monday, June 11, 2012

Calculate execution time of code in TinyOS

Here i have used the interface "LocalTime" and component "LocalTimeMilliC" for calculating the execution time.

This is the Configuration for calculating the execution time. Here i have given a sample code and it is not complete in sense of a complete application.
configuration TMP102AppC {
}
implementation {
  components LocalTimeMilliC, TMP102C as App;
  App.LocalTime -> LocalTimeMilliC; 

 ---Other Configurations---
}

This is the module for the application.
#include "printf.h"

module TMP102C {
   uses interface LocalTime <tmilli>;
     ---Other Interfaces---
}

implementation {
uint32_t start_time;
uint32_t stop_time;

 ---Other Code---

start_time = call LocalTime.get();  // Put this line where you want to start count.
   
---Other Code---

 stop_time = call LocalTime.get();  // Put this line where you want to stop count.
 printf("Execution Time = %d\n",(stop_time-start_time));  //Print the execution time.
    
}