1 /*========================== begin_copyright_notice ============================
2 
3 Copyright (C) 2017-2021 Intel Corporation
4 
5 SPDX-License-Identifier: MIT
6 
7 ============================= end_copyright_notice ===========================*/
8 
9 #ifndef _TIMER_H_
10 #define _TIMER_H_
11 // Enable this macro by default but comment out calls that print out timer info.
12 // Requirement by 3d team.
13 #if (defined(_DEBUG) || defined(_INTERNAL) || !defined(DLL_MODE)) && !defined(MEASURE_COMPILATION_TIME)
14 #define MEASURE_COMPILATION_TIME
15 #endif
16 
17 #include "VISADefines.h"
18 
19 // Timer library for the compiler
20 // To collect compile time information, do the following:
21 //
22 // initTimer()  // should be called once before creating any timers
23 // ...
24 // Update enum TIMERS,
25 // Update timerNames array
26 //
27 // startTimer/stopTimer can be called multiple times
28 //
29 // To read time, either invoke dumpAllTimers()
30 // or invoke other extern functions in Timer.cpp
31 // to get individual timer name, ticks, time count.
32 //
33 #define DEF_TIMER(ENUM, DESCR) ENUM,
34 enum class TimerID
35 {
36 #include "TimerDefs.h"
37     NUM_TIMERS
38 };
39 
40 int createNewTimer(const char *timerName);
41 void initTimer();
42 void startTimer(TimerID timer);
43 void stopTimer(TimerID timer);
44 void dumpAllTimers(const char *asmFileName, bool outputTime = false);
45 void dumpEncoderStats(Options *opt, std::string &asmName);
46 void resetPerKernel();
47 // double getTimerUS(unsigned idx);
48 
49 
50 struct TimerScope {
51     const TimerID timerId;
TimerScopeTimerScope52     TimerScope(const TimerID _timerId) : timerId(_timerId) {startTimer(timerId);}
~TimerScopeTimerScope53     ~TimerScope() {stopTimer(timerId);}
54 };
55 
56 #if defined(MEASURE_COMPILATION_TIME)
57 #define  TIME_SCOPE(TIMER_ID) TimerScope __timerScope(TimerID::TIMER_ID);
58 #else
59 #define  TIME_SCOPE(TIMER_ID)
60 #endif
61 
62 #undef DEF_TIMER
63 
64 #endif
65 
66