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 =========================================================================*/
34 #ifndef vtkTimerLog_h
35 #define vtkTimerLog_h
36 
37 #include "vtkCommonSystemModule.h" // For export macro
38 #include "vtkObject.h"
39 
40 #ifdef _WIN32
41 #include <sys/types.h> // Needed for Win32 implementation of timer
42 #include <sys/timeb.h> // Needed for Win32 implementation of timer
43 #else
44 #include <time.h> // Needed for unix implementation of timer
45 #include <sys/time.h> // Needed for unix implementation of timer
46 #include <sys/types.h> // Needed for unix implementation of timer
47 #include <sys/times.h> // Needed for unix implementation of timer
48 #endif
49 
50 // var args
51 #ifndef _WIN32
52 #include <unistd.h> // Needed for unix implementation of timer
53 #endif
54 
55 // select stuff here is for sleep method
56 #ifndef NO_FD_SET
57 # define SELECT_MASK fd_set
58 #else
59 # ifndef _AIX
60  typedef long fd_mask;
61 # endif
62 # if defined(_IBMR2)
63 # define SELECT_MASK void
64 # else
65 # define SELECT_MASK int
66 # endif
67 #endif
68 
69 
70 #define VTK_LOG_EVENT_LENGTH 40
71 
72 typedef struct
73 {
74  double WallTime;
75  int CpuTicks;
76  char Event[VTK_LOG_EVENT_LENGTH];
77  unsigned char Indent;
79 
80 class VTKCOMMONSYSTEM_EXPORT vtkTimerLog : public vtkObject
81 {
82 public:
83  static vtkTimerLog *New();
84 
85  vtkTypeMacro(vtkTimerLog,vtkObject);
86  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
87 
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);}
96 
98 
101  static void SetMaxEntries(int a);
102  static int GetMaxEntries();
104 
109  static void FormatAndMarkEvent(const char *EventString, ...);
110 
115  static void DumpLog(const char *filename);
116 
118 
123  static void MarkStartEvent(const char *EventString);
124  static void MarkEndEvent(const char *EventString);
126 
127  static void DumpLogWithIndents(ostream *os, double threshold);
128  static void DumpLogWithIndentsAndPercentages(ostream *os);
129 
131 
134  static int GetNumberOfEvents();
135  static int GetEventIndent(int i);
136  static double GetEventWallTime(int i);
137  static const char* GetEventString(int i);
139 
143  static void MarkEvent(const char *EventString);
144 
149  static void ResetLog();
150 
154  static void AllocateLog();
155 
159  static void CleanupLog();
160 
165  static double GetUniversalTime();
166 
171  static double GetCPUTime();
172 
176  void StartTimer();
177 
181  void StopTimer();
182 
187  double GetElapsedTime();
188 
189 protected:
190  vtkTimerLog() {this->StartTime=0; this->EndTime = 0;}; //insure constructor/destructor protected
191  ~vtkTimerLog() VTK_OVERRIDE { };
192 
193  static vtkTimerLogEntry* GetEvent(int i);
194 
195  static int Logging;
196  static int Indent;
197  static int MaxEntries;
198  static int NextEntry;
199  static int WrapFlag;
200  static int TicksPerSecond;
202 
203 #ifdef _WIN32
204 #ifndef _WIN32_WCE
205  static timeb FirstWallTime;
206  static timeb CurrentWallTime;
207 #else
208  static FILETIME FirstWallTime;
209  static FILETIME CurrentWallTime;
210 #endif
211 #else
212  static timeval FirstWallTime;
213  static timeval CurrentWallTime;
214  static tms FirstCpuTicks;
215  static tms CurrentCpuTicks;
216 #endif
217 
218  // instance variables to support simple timing functionality,
219  // separate from timer table logging.
220  double StartTime;
221  double EndTime;
222 
223  static void DumpEntry(ostream& os, int index, double time, double deltatime,
224  int tick, int deltatick, const char *event);
225 
226 private:
227  vtkTimerLog(const vtkTimerLog&) VTK_DELETE_FUNCTION;
228  void operator=(const vtkTimerLog&) VTK_DELETE_FUNCTION;
229 };
230 
231 
232 //
233 // Set built-in type. Creates member Set"name"() (e.g., SetVisibility());
234 //
235 #define vtkTimerLogMacro(string) \
236  { \
237  vtkTimerLog::FormatAndMarkEvent("Mark: In %s, line %d, class %s: %s", \
238  __FILE__, __LINE__, this->GetClassName(), string); \
239  }
240 
241 #endif
static int Indent
Definition: vtkTimerLog.h:196
abstract base class for most VTK objects
Definition: vtkObject.h:59
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static void LoggingOn()
Definition: vtkTimerLog.h:94
#define VTK_LOG_EVENT_LENGTH
Definition: vtkTimerLog.h:70
~vtkTimerLog() override
Definition: vtkTimerLog.h:191
double StartTime
Definition: vtkTimerLog.h:220
Timer support and logging.
Definition: vtkTimerLog.h:80
static tms FirstCpuTicks
Definition: vtkTimerLog.h:214
static int WrapFlag
Definition: vtkTimerLog.h:199
a simple class to control print indentation
Definition: vtkIndent.h:39
static int NextEntry
Definition: vtkTimerLog.h:198
static timeval CurrentWallTime
Definition: vtkTimerLog.h:213
static void LoggingOff()
Definition: vtkTimerLog.h:95
static int Logging
Definition: vtkTimerLog.h:195
unsigned char Indent
Definition: vtkTimerLog.h:77
static void SetLogging(int v)
This flag will turn loging of events off or on.
Definition: vtkTimerLog.h:92
static int MaxEntries
Definition: vtkTimerLog.h:197
static int GetLogging()
Definition: vtkTimerLog.h:93
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
static int TicksPerSecond
Definition: vtkTimerLog.h:200
static timeval FirstWallTime
Definition: vtkTimerLog.h:212
static vtkTimerLogEntry * TimerLog
Definition: vtkTimerLog.h:201
static tms CurrentCpuTicks
Definition: vtkTimerLog.h:215
double EndTime
Definition: vtkTimerLog.h:221