00001 #ifndef CMK_THRESHOLD_TIMER 00002 #define CMK_THRESHOLD_TIMER 00003 00028 class CkThresholdTimer { 00029 double threshold; // Print any times that exceed this (s). 00030 double lastStart; // Last activity started at this time (s). 00031 const char *lastWhat; // Last activity has this name. 00032 00033 void start_(const char *what) { 00034 lastStart=CmiWallTimer(); 00035 lastWhat=what; 00036 } 00037 void done_(void) { 00038 double elapsed=CmiWallTimer()-lastStart; 00039 if (elapsed>threshold) { 00040 CmiPrintf("%s took %.2f s\n",lastWhat,elapsed); 00041 } 00042 } 00043 public: 00044 CkThresholdTimer(const char *what,double thresh=0.001) 00045 :threshold(thresh) { start_(what); } 00046 void start(const char *what) { done_(); start_(what); } 00047 ~CkThresholdTimer() {done_();} 00048 }; 00049 00050 #endif