7 #define PP_CAT(a, b) PP_CAT_I(a, b)
8 #define PP_CAT_I(a, b) PP_CAT_II(~, a##b)
9 #define PP_CAT_II(p, res) res
11 #define PP_UNIQUE_NAME(base) PP_CAT(base, __COUNTER__)
13 #define PROFILECLEAR \
15 Base::Timer::clearAll(); \
17 #define PROFILEENABLE(a) \
19 Base::Timer::enable(a); \
21 #define PROFILESTART(a) \
23 Base::Timer::profileStart(a); \
25 #define PROFILESTOP(a) \
27 Base::Timer::profileStop(a); \
29 #define PROFILESCOPED(a) Base::scopedProfile PP_UNIQUE_NAME(scopedProfile__)(a);
34 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
36 class LX_BASE_EXPORT timerIFace
39 virtual void resetTotal() = 0;
40 virtual void reset() = 0;
41 virtual double elapsedMS() = 0;
42 virtual double elapsed()
const = 0;
43 virtual double start() = 0;
44 virtual void restart() = 0;
45 virtual double stop() = 0;
46 virtual double totalSeconds() = 0;
47 virtual double totalMS() = 0;
48 virtual long count() = 0;
49 virtual std::string getName() = 0;
50 virtual timerIFace* getParent() = 0;
51 virtual void setParent(timerIFace*) = 0;
52 virtual void addChild(timerIFace*) = 0;
53 virtual std::set<timerIFace*> getChildren() = 0;
56 class LX_BASE_EXPORT timer_dummy :
public timerIFace
62 double elapsedMS() {
return 0.0; };
63 double elapsed()
const {
return 0.0; };
64 double start() {
return 0.0; };
66 double stop() {
return 0.0; };
67 double totalSeconds() {
return 0.0; };
68 double totalMS() {
return 0.0; };
69 long count() {
return 0; };
70 std::string getName() {
return std::string(); };
71 timerIFace* getParent() {
return 0; };
72 void setParent(timerIFace*){};
73 void addChild(timerIFace*){};
74 std::set<timerIFace*> getChildren() {
return std::set<timerIFace*>(); };
79 class LX_BASE_EXPORT Timer :
public timerIFace
88 double elapsed()
const;
92 double totalSeconds();
96 std::string getName() {
return _name; };
97 void setParent(timerIFace*);
98 timerIFace* getParent();
101 void addChild(timerIFace* c) { _children.insert(c); };
102 std::set<timerIFace*> getChildren() {
return _children; };
104 static timerIFace* getTimer(std::string name);
105 static void stopTimer(std::string name);
106 static std::map<std::string, timerIFace*> getTimerMap();
107 static void setCurrent(timerIFace* p);
108 static timerIFace* getCurrent();
110 static void clearAll();
111 double startTiming();
112 static std::map<void*, double> TimeStorage;
114 static void enable(
bool v);
115 static bool isEnabled();
118 static void profileStart(
const char* a);
119 static void profileStop(
const char* a);
121 static void printTimer(
const char* header);
127 double _totalseconds;
130 timerIFace* _parentTimer = 0;
131 std::set<timerIFace*> _children;
132 static timerIFace* _currentTimer;
133 static bool _enabled;
134 static std::map<std::string, timerIFace*> _timerMap;
137 static Base::timer_dummy my_timer_dummy;
138 static Base::timer_dummy* my_timer_dummy_ptr = &my_timer_dummy;
149 double elapsed()
const {
return double(clock() - _start_time) / CLOCKS_PER_SEC; }