HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_StopWatch.h
Go to the documentation of this file.
1 #ifndef _UT_StopWatch_h_
2 #define _UT_StopWatch_h_
3 
4 #include "UT_API.h"
5 #include <time.h>
6 #include <stdlib.h>
7 #include <SYS/SYS_Time.h>
8 #include <SYS/SYS_Types.h>
9 
11 
12 //
13 // a simple stopwatch class. It implements functions much like
14 // a regular stopwatch:
15 // start(): resets stopwatch to zero, and starts it.
16 // lap(): returns the elapsed time.
17 // stop(); stop the stopwatch
18 // resume(); resumes the stopwatch
19 // getTime(); returns elapsed time, may be used when stopped.
20 // operator-: difference in start time between two watches
21 //
22 
24 {
25 public:
26  UT_StopWatch();
27 
28  void clear();
29  void start();
30  fpreal64 lap() const;
31  fpreal64 stop();
32  void resume();
33 
34  fpreal64 getTime() const;
35  bool isRunning() const;
36 
37  fpreal64 operator-( const UT_StopWatch & );
38  UT_TIMERVAL getStartTime() const;
39 
40  static fpreal64 _timeDiff(const UT_TIMERVAL &later, const UT_TIMERVAL &sooner);
41 
42 protected:
43  bool _running; // the watch is running
45 
47 };
48 
49 // this class replaces the old timeStamp function, and can be used to more
50 // easily take timing measurements
51 //
52 // you still have the old timeStamp function that works in the same way, but
53 // also, you can use begin and end event functions which will output a duration
54 // along with the timestamps. another benefit is that it becomes easy to see
55 // the contained duration of a function.
56 //
57 // you can additionally use the indent function to give you the right
58 // indentation when inserting your own printfs
59 //
60 //
61 // so, to add timestamps, do this:
62 // UT_Timer ts( "block 1" );
63 // ts.end(); // no need if scope ends, otherwise it displays
64 //
65 // don't mismatch your begins and ends or else everything will break
66 // if you want running totals send in the pointer to total
68 {
69 public:
70  UT_Timer();
71  explicit UT_Timer(const char *block_name);
72 
73  ~UT_Timer();
74 
75  static void indent();
76 
77  static void timeStamp(const char *msg1, const char *msg2=0);
78 
79  void clear();
80 
81  void begin( const char *block_name = NULL );
82  int lap() { myCount++; return myCount; }
83  void end();
84 
85  bool isRunning() const { return myBegun; }
86 
87  fpreal64 getBlockDuration();
88  fpreal64 getTotalDuration();
89  fpreal64 getAverageDuration();
90 
91  void setDisplay( bool d ) { myDisplay = d; }
92  bool willDisplay() const { return myDisplay; }
93 
94  void displayBlockDuration( const char *block_name = NULL );
95  void displayTotalDuration( const char *block_name = NULL );
96  void displayAverageDuration( const char *block_name = NULL );
97 
98  static UT_Timer *getTimer(int id);
99 
100 private:
101  bool myBegun;
102  bool myDisplay;
103  UT_StopWatch myBlockTimer;
104  UT_StopWatch mySavedBlockTimer;
105  fpreal64 myTotal;
106  int myCount;
107 
108  static int theIndentation;
109  static UT_StopWatch theLastBlockTimer;
110 };
111 
112 // For use with UT_TimerAuto to keep track of total time
114 {
115 public:
116  UT_TimerDisplayTotal(const char* block_name)
117  : myBlockName(block_name)
118  {
119  }
121  {
122  displayAverageDuration(myBlockName);
123  displayTotalDuration(myBlockName);
124  }
125 private:
126  const char* myBlockName;
127 };
128 
129 // Used to accumulate time into a UT_Timer/UT_TimerDisplayTotal
131 {
132 public:
133  UT_TimerAuto(UT_Timer &ts, const char *name): myTimeStamp( ts )
134  {
135  myTimeStamp.begin( name );
136  }
137 
138  UT_TimerAuto(UT_Timer &ts): myTimeStamp( ts )
139  {
140  myTimeStamp.begin();
141  }
142 
144  {
145  myTimeStamp.end();
146  }
147 
149 };
150 
151 #endif // _UT_StopWatch_h_
struct timeval SYS_TimeVal
Definition: SYS_Time.h:28
UT_TimerDisplayTotal(const char *block_name)
Definition: UT_StopWatch.h:116
int lap()
Definition: UT_StopWatch.h:82
GLuint start
Definition: glcorearb.h:475
IMATH_HOSTDEVICE constexpr Plane3< T > operator-(const Plane3< T > &plane) IMATH_NOEXCEPT
Reflect the pla.
Definition: ImathPlane.h:253
#define UT_API
Definition: UT_API.h:14
GLuint const GLchar * name
Definition: glcorearb.h:786
fpreal64 _elapsedTime
Definition: UT_StopWatch.h:44
UT_TimerAuto(UT_Timer &ts)
Definition: UT_StopWatch.h:138
double fpreal64
Definition: SYS_Types.h:201
GLuint GLuint end
Definition: glcorearb.h:475
UT_TimerAuto(UT_Timer &ts, const char *name)
Definition: UT_StopWatch.h:133
UT_TIMERVAL _startTime
Definition: UT_StopWatch.h:46
SYS_TimeVal UT_TIMERVAL
Definition: UT_StopWatch.h:10
void displayAverageDuration(const char *block_name=NULL)
bool isRunning() const
Definition: UT_StopWatch.h:85
void displayTotalDuration(const char *block_name=NULL)
UT_Timer & myTimeStamp
Definition: UT_StopWatch.h:148
void setDisplay(bool d)
Definition: UT_StopWatch.h:91
bool willDisplay() const
Definition: UT_StopWatch.h:92
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.
Definition: node.h:450