VTK
vtkTimerLog.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkTimerLog.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
33 #ifndef vtkTimerLog_h
34 #define vtkTimerLog_h
35 
36 #include "vtkCommonSystemModule.h" // For export macro
37 #include "vtkObject.h"
38 
39 #ifdef _WIN32
40 #include <sys/types.h> // Needed for Win32 implementation of timer
41 #include <sys/timeb.h> // Needed for Win32 implementation of timer
42 #else
43 #include <time.h> // Needed for unix implementation of timer
44 #include <sys/time.h> // Needed for unix implementation of timer
45 #include <sys/types.h> // Needed for unix implementation of timer
46 #include <sys/times.h> // Needed for unix implementation of timer
47 #endif
48 
49 // var args
50 #ifndef _WIN32
51 #include <unistd.h> // Needed for unix implementation of timer
52 #endif
53 
54 // select stuff here is for sleep method
55 #ifndef NO_FD_SET
56 # define SELECT_MASK fd_set
57 #else
58 # ifndef _AIX
59  typedef long fd_mask;
60 # endif
61 # if defined(_IBMR2)
62 # define SELECT_MASK void
63 # else
64 # define SELECT_MASK int
65 # endif
66 #endif
67 
68 
69 #define VTK_LOG_EVENT_LENGTH 40
70 
71 //BTX
72 typedef struct
73 {
74  double WallTime;
75  int CpuTicks;
76  char Event[VTK_LOG_EVENT_LENGTH];
77  unsigned char Indent;
79 //ETX
80 
82 {
83 public:
84  static vtkTimerLog *New();
85 
86  vtkTypeMacro(vtkTimerLog,vtkObject);
87  void PrintSelf(ostream& os, vtkIndent indent);
88 
90 
92  static void SetLogging(int v) {vtkTimerLog::Logging = v;}
93  static int GetLogging() {return vtkTimerLog::Logging;}
94  static void LoggingOn() {vtkTimerLog::SetLogging(1);}
95  static void LoggingOff() {vtkTimerLog::SetLogging(0);}
97 
99 
100  static void SetMaxEntries(int a);
101  static int GetMaxEntries();
103 
104 //BTX
106 
108  static void FormatAndMarkEvent(const char *EventString, ...);
109 //ETX
111 
114  static void DumpLog(const char *filename);
115 
117 
120  static void MarkStartEvent(const char *EventString);
121  static void MarkEndEvent(const char *EventString);
122 //BTX
123  static void DumpLogWithIndents(ostream *os, double threshold);
124 //ETX
126 
128 
129  static int GetNumberOfEvents();
130  static int GetEventIndent(int i);
131  static double GetEventWallTime(int i);
132  static const char* GetEventString(int i);
134 
136  static void MarkEvent(const char *EventString);
137 
140  static void ResetLog();
141 
143  static void AllocateLog();
144 
146  static void CleanupLog();
147 
150  static double GetUniversalTime();
151 
154  static double GetCPUTime();
155 
157  void StartTimer();
158 
160  void StopTimer();
161 
164  double GetElapsedTime();
165 
166 protected:
167  vtkTimerLog() {this->StartTime=0; this->EndTime = 0;}; //insure constructor/destructor protected
168  virtual ~vtkTimerLog() { };
169 
170  static vtkTimerLogEntry* GetEvent(int i);
171 
172  static int Logging;
173  static int Indent;
174  static int MaxEntries;
175  static int NextEntry;
176  static int WrapFlag;
177  static int TicksPerSecond;
179 
180 #ifdef _WIN32
181 #ifndef _WIN32_WCE
182  static timeb FirstWallTime;
183  static timeb CurrentWallTime;
184 #else
185  static FILETIME FirstWallTime;
186  static FILETIME CurrentWallTime;
187 #endif
188 #else
189  static timeval FirstWallTime;
190  static timeval CurrentWallTime;
191  static tms FirstCpuTicks;
192  static tms CurrentCpuTicks;
193 #endif
194 
195  // instance variables to support simple timing functionality,
196  // separate from timer table logging.
197  double StartTime;
198  double EndTime;
199 
200  //BTX
201  static void DumpEntry(ostream& os, int index, double time, double deltatime,
202  int tick, int deltatick, const char *event);
203  //ETX
204 
205 private:
206  vtkTimerLog(const vtkTimerLog&); // Not implemented.
207  void operator=(const vtkTimerLog&); // Not implemented.
208 };
209 
210 
211 //
212 // Set built-in type. Creates member Set"name"() (e.g., SetVisibility());
213 //
214 #define vtkTimerLogMacro(string) \
215  { \
216  vtkTimerLog::FormatAndMarkEvent("Mark: In %s, line %d, class %s: %s", \
217  __FILE__, __LINE__, this->GetClassName(), string); \
218  }
219 
220 #endif
static int Indent
Definition: vtkTimerLog.h:173
abstract base class for most VTK objects
Definition: vtkObject.h:61
static void LoggingOn()
Definition: vtkTimerLog.h:94
#define VTK_LOG_EVENT_LENGTH
Definition: vtkTimerLog.h:69
double StartTime
Definition: vtkTimerLog.h:197
Timer support and logging.
Definition: vtkTimerLog.h:81
#define VTKCOMMONSYSTEM_EXPORT
static tms FirstCpuTicks
Definition: vtkTimerLog.h:191
virtual void PrintSelf(ostream &os, vtkIndent indent)
static int WrapFlag
Definition: vtkTimerLog.h:176
a simple class to control print indentation
Definition: vtkIndent.h:38
static int NextEntry
Definition: vtkTimerLog.h:175
static timeval CurrentWallTime
Definition: vtkTimerLog.h:190
static void LoggingOff()
Definition: vtkTimerLog.h:95
static int Logging
Definition: vtkTimerLog.h:172
unsigned char Indent
Definition: vtkTimerLog.h:77
static void SetLogging(int v)
Definition: vtkTimerLog.h:92
static int MaxEntries
Definition: vtkTimerLog.h:174
static int GetLogging()
Definition: vtkTimerLog.h:93
static vtkObject * New()
static int TicksPerSecond
Definition: vtkTimerLog.h:177
static timeval FirstWallTime
Definition: vtkTimerLog.h:189
static vtkTimerLogEntry * TimerLog
Definition: vtkTimerLog.h:178
static tms CurrentCpuTicks
Definition: vtkTimerLog.h:192
virtual ~vtkTimerLog()
Definition: vtkTimerLog.h:168
double EndTime
Definition: vtkTimerLog.h:198