![]() ![]() ![]() ![]() Next: Include Files Up: Using Cactus Timers Previous: Timing Calls Contents How to Insert Timers in your CodeThe function prototypes and structure definitions are contained in the include file cctk_Timers.h, which is included in the standard thorn header file cctk.h. At the moment, the timer calls are only available from C. The following example, which uses a timer to instrument a section of code, illustrates how timers are used by application thorns. A working example is available in the thorn CactusTest/TestTimers. Creating a timer The first action for any timer is to create it, using CCTK_TimerCreate. This can be performed at any time prior to use of the timer:
#include "cctk_Timers.h" index = CCTK_TimerCreate("TimeMyStuff"); Instrumenting a section of code Code sections are instrumented using the Start, Stop and Reset functions. These functions are applied to the chosen timer using all the registered clocks. ierr = CCTK_TimerStart("TimeMyStuff"); do_procedure_to_be_timed(); ierr = CCTK_TimerStop("TimeMyStuff"); Accessing the timer results After calling CCTK_TimerStop, you then get the time value from any of the registered clocks. The procedure is to allocate a cTimerData structure, and read the information from your timer into this structure using CCTK_Timer, then to extract time data of the desired clock from this structure. After using the structure, you should destroy it.
cTimerData *info = CCTK_TimerCreateData(); int ierr = CCTK_Timer("TimeMyStuff",info); /* You can refer to a particular clock by name. */ const cTimerVal *clock = CCTK_GetClockValue( "gettimeofday", info ); if( clock ){ printf ("\t%s: %.3f %s\n", "gettimeofday", CCTK_TimerClockSeconds( clock ), "secs" ); } /* To get results from all available clocks, refer to them by index.*/ nclocks = CCTK_NumTimerClocks( info ); for (i = 0; i < numclocks; i++) { const cTimerVal *clock = CCTK_GetClockValueI( i, info ); printf ("\t%s: %.3f %s\n", CCTK_TimerClockName( clock ), CCTK_TimerClockSeconds( clock ), "secs" ); } CCTK_TimerDestroyData (info);
![]() ![]() ![]() ![]() Next: Include Files Up: Using Cactus Timers Previous: Timing Calls Contents |