10 #include "implem/Proto_ClockTicks.H" 167 #ifndef PR_TURN_OFF_TIMERS 168 inline double TimerGetTimeStampWC()
173 gettimeofday(&tv, &tz);
174 return((
double)tv.tv_sec + 0.000001 * (
double)tv.tv_usec);
183 for(
unsigned int i=0; i<m_children.size(); ++i)
185 delete m_children[i];
191 m_filename = string(
"/dev/null");
193 inline void start(
char* mutex);
194 inline unsigned long long int stop(
char* mutex);
195 inline void report(
bool a_closeAfter=
false);
199 inline void leafStart();
200 inline void leafStop();
202 unsigned long long int time()
const 204 return m_accumulated_WCtime;
211 long long int count()
const 217 bool isPruned()
const {
return m_pruned;}
224 std::vector<TraceTimer*>* troots = getRootTimerPtr();
225 (*troots)[0]->m_filename = a_filename;
228 inline TraceTimer* getTimer(
const char* name);
229 inline const std::vector<TraceTimer*>& children()
const ;
231 inline void PruneTimersParentChildPercent(
double percent);
232 inline void sampleMemUsage() ;
234 inline void addFlops(
long long int flops) {m_flops+=flops;}
241 long long int m_flops;
242 long long int m_count;
245 static std::vector<TraceTimer*>* getRootTimerPtr()
247 static std::vector<TraceTimer*>* retval =
new std::vector<TraceTimer*>();
248 static bool initialized =
false;
251 std::vector<TraceTimer*>* current = getCurrentTimerPtr();
253 const char* rootName =
"root";
255 rootTimer->m_thread_id = 0;
259 (*retval)[0] = rootTimer;
261 (*current).resize(1);
262 (*current)[0]=rootTimer;
264 (*retval)[0]->tid = 0;
265 rootTimer->start(&mutex);
266 rootTimer->zeroTime = TimerGetTimeStampWC();
267 rootTimer->zeroTicks = PR_ticks();
274 static std::vector<TraceTimer*>* getCurrentTimerPtr()
276 static std::vector<TraceTimer*>* retval =
new std::vector<TraceTimer*>(1);
282 static void staticReport()
284 std::vector<TraceTimer*>* vecptr = getRootTimerPtr();
285 if(vecptr->size() > 0)
287 (*vecptr)[0]->report();
292 static void staticReset()
294 std::vector<TraceTimer*>* vecptr = getRootTimerPtr();
295 if(vecptr->size() > 0)
297 (*vecptr)[0]->reset();
302 static void staticPruneTimersParentChildPercent(
double percent)
304 std::vector<TraceTimer*>* vecptr = getRootTimerPtr();
305 if(vecptr->size() > 0)
307 (*vecptr)[0]->PruneTimersParentChildPercent(percent);
312 static void staticSetTimerFileName(
string a_filename)
314 std::vector<TraceTimer*>* vecptr = getRootTimerPtr();
315 if(vecptr->size() > 0)
317 (*vecptr)[0]->setTimerFileName(a_filename);
325 std::vector<TraceTimer*>* vecptr = getRootTimerPtr();
326 if(vecptr->size() > 0)
328 retval = (*vecptr)[0]->tid;
334 static TraceTimer* staticGetTimer(
const char* name)
337 std::vector<TraceTimer*>* vecptr = getRootTimerPtr();
338 if(vecptr->size() > 0)
340 retval = (*vecptr)[0]->getTimer(name);
357 m_accumulated_WCtime = 0;
358 m_last_WCtime_stamp = 0;
359 m_thread_id = thread_id;
367 std::vector<TraceTimer*> m_children;
369 unsigned long long int m_accumulated_WCtime;
370 unsigned long long int m_last_WCtime_stamp;
373 unsigned long long int zeroTicks = 0;
377 void reportTree(FILE* out,
const TraceTimer& node,
int depth);
381 inline void macroTest();
382 inline void macroTest2();
384 inline void currentize()
const ;
386 inline void reportFullTree(FILE* out,
const TraceTimer& timer,
387 unsigned long long int totalTime,
int depth,
double secondspertick);
388 inline void reportOneTree(FILE* out,
const TraceTimer& timer,
double secondspertick);
392 inline void PruneTimersParentChildPercent(
double threshold,
TraceTimer* parent);
411 :m_mutex(mutex), m_childMutex(childMutex),m_timer(a_timer)
412 {
if(a_timer)a_timer->start(mutex);}
414 :m_mutex(mutex), m_childMutex((
char*)(getOKPtr()) ),m_timer(a_timer)
416 if(a_timer)a_timer->start(mutex);
421 static char* getOKPtr()
423 static bool init =
false;
424 static char* retval =
new char[1024];
427 sprintf(retval,
"0");
435 static const char ok = 0;
440 AutoStart::~AutoStart()
443 if(*m_childMutex == 1)
445 std::cerr<<
" stop called in timer unexpectedly";
449 if(m_timer)m_timer->stop(m_mutex);
453 inline void TraceTimer::leafStart()
457 m_last_WCtime_stamp = PR_ticks();
460 inline void TraceTimer::leafStop()
463 m_accumulated_WCtime += PR_ticks() - m_last_WCtime_stamp;
464 m_last_WCtime_stamp=0;
468 #ifdef PR_TURN_OFF_TIMERS 470 #define PR_TIMER(name, tpointer) 471 #define PR_TIME(name) 472 #define PR_FLOPS(flops) 473 #define PR_TIMELEAF(name) 474 #define PR_TIMERS(name) 475 #define PR_START(tpointer) 476 #define PR_STOP(tpointer) 477 #define PR_TIMER_REPORT() 478 #define PR_TIMER_RESET() 479 #define PR_TIMER_PRUNE(threshold) 480 #define PR_TIMER_SETFILE(filename) 484 #define PR_TIMER(name, tpointer) \ 485 const char* TimerTag_##tpointer = name ; \ 486 ::Proto::TraceTimer* tpointer = NULL ; \ 487 if(::Proto::TraceTimer::getTID()==0) \ 489 tpointer = ::Proto::TraceTimer::staticGetTimer(TimerTag_##tpointer) ; \ 492 #define PR_TIME(name) \ 493 const char* TimerTagA = name ; \ 494 char PR_TimermutexA = 0; \ 495 ::Proto::TraceTimer* PR_tpointer = NULL; \ 496 if(::Proto::TraceTimer::getTID()==0) \ 498 PR_tpointer = ::Proto::TraceTimer::staticGetTimer(TimerTagA); \ 500 ::Proto::AutoStart autostart(PR_tpointer, &PR_TimermutexA) 502 #define PR_FLOPS(flops) \ 503 if(PR_tpointer)PR_tpointer->addFlops(flops); 505 #define PR_TIMELEAF(name) \ 506 const char* TimerTagA = name ; \ 507 ::Proto::TraceTimer* PR_tpointer = NULL; \ 508 if(::Proto::TraceTimer::getTID()==0) \ 510 PR_tpointer = ::Proto::TraceTimer::staticGetTimer(TimerTagA); \ 512 ::Proto::AutoStartLeaf autostart(PR_tpointer) 514 #define PR_TIMERS(name) \ 515 const char* TimerTagA = name ; \ 516 char PR_TimermutexA = 0; \ 517 char PR_Timermutex = 0; \ 518 ::Proto::TraceTimer* PR_tpointer = NULL; \ 519 if(::Proto::TraceTimer::getTID()==0) \ 521 PR_tpointer = ::Proto::TraceTimer::staticGetTimer(TimerTagA); \ 523 ::Proto::AutoStart autostart(PR_tpointer, &PR_TimermutexA, &PR_Timermutex) 526 #define PR_START(tpointer) \ 527 if(::Proto::TraceTimer::getTID()==0) \ 529 tpointer->start(&PR_Timermutex); \ 532 #define PR_STOP(tpointer) \ 533 if(::Proto::TraceTimer::getTID()==0) \ 535 tpointer->stop(&PR_Timermutex); \ 539 #define PR_TIMER_REPORT() ::Proto::TraceTimer::staticReport() 541 #define PR_TIMER_RESET() ::Proto::TraceTimer::staticReset() 543 #define PR_TIMER_PRUNE(threshold) ::Proto::TraceTimer::staticPruneTimersParentChildPercent(threshold) 545 #define PR_TIMER_SETFILE(filename) ::Proto::TraceTimer::staticSetTimerFileName(filename); 549 #include "implem/Proto_TimerImplem.H" Definition: Proto_Timer.H:397
Definition: Proto_Timer.H:407
void setTimerFileName(string a_filename)
need to set the filename so it is not /dev/null
Definition: Proto_Timer.H:221
Definition: Proto_Box.H:11
Definition: Proto_Timer.H:178