Mobile API Reference  MicroStrategy 2019
Timer.h
Go to the documentation of this file.
1 //==============================================================================================
2 // FILENAME : Timer.h
3 // AUTHOR : vovechkin
4 // CREATION : 2004-06-14
5 // Copyright (C) MicroStrategy Incorporated 2004
6 // All Rights Reserved
7 //==============================================================================================
8 #ifndef MBase_Timer_h
9 #define MBase_Timer_h
10 
11 #include "Base.h"
12 #include "ReturnString.h"
13 
14 #include "../Defines/BasicTypes.h"
15 
16 namespace MBase
17 {
33  {
34  public:
35 
36  Timer();
37 
38  //akini 08-17-2006
39  void ResetTimer();
40 
41  unsigned Int64 GetAgeInMicroseconds() const;
42 
43  inline unsigned Int64 GetAgeInMilliseconds() const
44  {
45  return GetAgeInMicroseconds() / 1000;
46  }
47 
48  inline unsigned Int64 GetAgeInSeconds() const
49  {
50  return GetAgeInMicroseconds() / 1000000;
51  }
52 
53  private:
54 
55 #ifdef WIN32
56  unsigned Int64 mStartTimeInPerformanceCounterUnits;
57 #else
58  unsigned Int64 mStartTimeInMicroseconds;
59 #endif
60  };
61 
92  {
93  public:
94 
99  {
100  public:
101 
102  Timer(TotalTimer& irTotalTimer);
103 
104  ~Timer() throw()
105  {
106  if (mpTotalTimer != NULL)
107  {
108  Stop();
109  }
110  }
111 
112  void Stop() throw();
113 
114  private:
115 
116  TotalTimer* mpTotalTimer;
117 #ifdef WIN32
118  unsigned Int64 mStartTimeInPerformanceCounterUnits;
119 #else
120  unsigned Int64 mStartTimeInMicroseconds;
121 #endif
122  };
123 
128  {
129  public:
130 
131  Timer2(TotalTimer& irTotalTimer1, TotalTimer& irTotalTimer2);
132  ~Timer2() throw()
133  {
134  if (mpTotalTimer1 != NULL)
135  {
136  Stop();
137  }
138  }
139 
140  void Stop() throw();
141 
142  private:
143 
144  TotalTimer* mpTotalTimer1;
145  TotalTimer* mpTotalTimer2;
146 #ifdef WIN32
147  unsigned Int64 mStartTimeInPerformanceCounterUnits;
148 #else
149  unsigned Int64 mStartTimeInMicroseconds;
150 #endif
151  };
152 
157  {
158  public:
159 
160  Timer3(TotalTimer& irTotalTimer1, TotalTimer& irTotalTimer2, TotalTimer& irTotalTimer3);
161  ~Timer3() throw()
162  {
163  if (mpTotalTimer1 != NULL)
164  {
165  Stop();
166  }
167  }
168 
169  void Stop() throw();
170 
171  private:
172 
173  TotalTimer* mpTotalTimer1;
174  TotalTimer* mpTotalTimer2;
175  TotalTimer* mpTotalTimer3;
176 #ifdef WIN32
177  unsigned Int64 mStartTimeInPerformanceCounterUnits;
178 #else
179  unsigned Int64 mStartTimeInMicroseconds;
180 #endif
181  };
182 
183  public:
184 
186 #ifdef WIN32
187  mTotalTimeInPerformanceCounterUnits(0),
188 #else
189  mTotalTimeInMicroseconds(0),
190 #endif
191  mIncrementCount(0)
192  {
193  }
194 
198  unsigned Int64 GetTotalInMicroseconds() const;
199 
200  inline unsigned Int64 GetTotalInMilliseconds() const
201  {
202  return GetTotalInMicroseconds() / 1000;
203  }
204 
205  inline unsigned Int64 GetTotalInSeconds() const
206  {
207  return GetTotalInMicroseconds() / 1000000;
208  }
209 
213  inline unsigned Int64 GetAverageInMicroseconds() const
214  {
215  return (mIncrementCount > 0) ? GetTotalInMicroseconds() / mIncrementCount : 0;
216  }
217 
218  inline unsigned Int64 GetAverageInMilliseconds() const
219  {
220  return GetAverageInMicroseconds() / 1000;
221  }
222 
223  inline unsigned Int64 GetAverageInSeconds() const
224  {
225  return GetAverageInMicroseconds() / 1000000;
226  }
227 
231  inline unsigned Int64 GetIncrementCount() const
232  {
233  return mIncrementCount;
234  }
235 
236  private:
237 
238  friend class Timer;
239  friend class Timer2;
240  friend class Timer3;
241 
242 #ifdef WIN32
243  unsigned Int64 mTotalTimeInPerformanceCounterUnits;
244 #else
245  unsigned Int64 mTotalTimeInMicroseconds;
246 #endif
247  unsigned Int64 mIncrementCount;
248  };
249 }
250 
251 #endif // MBase_Timer_h
Definition: Timer.h:156
Definition: Timer.h:91
~Timer2()
Definition: Timer.h:132
Definition: Timer.h:32
#define Int64
Definition: BasicTypes.h:36
unsigned Int64 GetAverageInMicroseconds() const
Definition: Timer.h:213
unsigned Int64 GetAgeInSeconds() const
Definition: Timer.h:48
~Timer()
Definition: Timer.h:104
#define DLL_BASE_EXIM
Definition: Base.h:20
TotalTimer()
Definition: Timer.h:185
Definition: Timer.h:98
Definition: Timer.h:127
Definition: Allocator.h:47
unsigned Int64 GetIncrementCount() const
Definition: Timer.h:231
unsigned Int64 GetAverageInMilliseconds() const
Definition: Timer.h:218
~Timer3()
Definition: Timer.h:161
unsigned Int64 GetAverageInSeconds() const
Definition: Timer.h:223
unsigned Int64 GetTotalInSeconds() const
Definition: Timer.h:205
unsigned Int64 GetTotalInMilliseconds() const
Definition: Timer.h:200
#define NULL
Definition: Null.h:10
unsigned Int64 GetAgeInMilliseconds() const
Definition: Timer.h:43