Have you thought of modifying each and every ISR routine to store (and accumulate) the time spent serving interrupts? This accumulated value should then be subtracted from the running time of the code snippet.
I suggest that you directly read the counter registers in the ISRs (vs. calling LocalTime.get(), which may have additional overhead). The counter registers should not overflow more than once while the interrupt handler is running. This gets a little tricky, though, if there are nested interrupts. AFAIK it's only the ADC subsystem that uses nested interrupts on the AVR platforms. If your application doesn't use the ADC, the above simple solution would suffice. Janos On Tue, Aug 9, 2011 at 10:27 PM, Xiaohui Liu <[email protected]> wrote: > Hi everyone, > How can I measure the time for a snippet of code (e.g., a function call > foo), either synchronous or asynchronous, to execute? > A straight forward way can be: > start_time = Call LocalTime.get(); > foo(); > end_time = call LocalTime.get(); > (end_time - start_time) is regarded as the execution time of function call > foo(). However, asynchronous code can preempt foo() during its execution, > thus (end_time - start_time) may be overestimation of foo()'s actual > execution time. > An alternative can be something like the following: > disable interrupt; > start_time = Call LocalTime.get(); > foo(); > end_time = call LocalTime.get(); > enable interrupt; > However, this can be problematic also if some critical interrupts (e.g., > packet reception) occur when the interrupt is disabled. Can anyone have some > idea on how execution time can be measured without the above issues? Any > help is appreciated. > -- > -Xiaohui Liu > > _______________________________________________ > Tinyos-help mailing list > [email protected] > https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help > _______________________________________________ Tinyos-help mailing list [email protected] https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
