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
vtkTimerLog::GetLogging
static int GetLogging()
Definition: vtkTimerLog.h:93
vtkTimerLog::LoggingOn
static void LoggingOn()
Definition: vtkTimerLog.h:94
vtkTimerLog::GetCPUTime
static double GetCPUTime()
Returns the CPU time for this process On Win32 platforms this actually returns wall time.
vtkTimerLog::GetEventIndent
static int GetEventIndent(int i)
vtkTimerLog::FormatAndMarkEvent
static void FormatAndMarkEvent(const char *EventString,...)
Record a timing event.
VTK_LOG_EVENT_LENGTH
#define VTK_LOG_EVENT_LENGTH
Definition: vtkTimerLog.h:70
vtkTimerLog::StopTimer
void StopTimer()
Sets EndTime to the current time.
vtkTimerLog::Indent
static int Indent
Definition: vtkTimerLog.h:196
vtkTimerLogEntry
Definition: vtkTimerLog.h:73
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:60
vtkTimerLog::StartTimer
void StartTimer()
Set the StartTime to the current time.
vtkTimerLog::vtkTimerLog
vtkTimerLog()
Definition: vtkTimerLog.h:190
vtkTimerLog::DumpLog
static void DumpLog(const char *filename)
Write the timing table out to a file.
vtkX3D::time
@ time
Definition: vtkX3D.h:497
vtkTimerLog::GetEventWallTime
static double GetEventWallTime(int i)
vtkTimerLog::~vtkTimerLog
~vtkTimerLog() override
Definition: vtkTimerLog.h:191
vtkTimerLog::StartTime
double StartTime
Definition: vtkTimerLog.h:220
vtkTimerLog::New
static vtkTimerLog * New()
vtkTimerLog::AllocateLog
static void AllocateLog()
Allocate timing table with MaxEntries elements.
vtkTimerLog::FirstCpuTicks
static tms FirstCpuTicks
Definition: vtkTimerLog.h:214
vtkTimerLog::GetUniversalTime
static double GetUniversalTime()
Returns the elapsed number of seconds since January 1, 1970.
vtkTimerLog::MarkStartEvent
static void MarkStartEvent(const char *EventString)
I want to time events, so I am creating this interface to mark events that have a start and an end.
vtkTimerLog::NextEntry
static int NextEntry
Definition: vtkTimerLog.h:198
vtkTimerLog::DumpLogWithIndents
static void DumpLogWithIndents(ostream *os, double threshold)
vtkTimerLog::GetEvent
static vtkTimerLogEntry * GetEvent(int i)
vtkTimerLog::Logging
static int Logging
Definition: vtkTimerLog.h:195
vtkTimerLog::WrapFlag
static int WrapFlag
Definition: vtkTimerLog.h:199
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:40
vtkTimerLog::CleanupLog
static void CleanupLog()
Remove timer log.
vtkTimerLog::GetEventString
static const char * GetEventString(int i)
vtkTimerLog::LoggingOff
static void LoggingOff()
Definition: vtkTimerLog.h:95
vtkTimerLog::CurrentWallTime
static timeval CurrentWallTime
Definition: vtkTimerLog.h:213
vtkTimerLogEntry::WallTime
double WallTime
Definition: vtkTimerLog.h:74
vtkTimerLogEntry::Indent
unsigned char Indent
Definition: vtkTimerLog.h:77
vtkTimerLog::DumpLogWithIndentsAndPercentages
static void DumpLogWithIndentsAndPercentages(ostream *os)
vtkObject.h
vtkTimerLog::MarkEvent
static void MarkEvent(const char *EventString)
Record a timing event and capture wall time and cpu ticks.
vtkTimerLog::GetMaxEntries
static int GetMaxEntries()
vtkTimerLog::SetLogging
static void SetLogging(int v)
This flag will turn loging of events off or on.
Definition: vtkTimerLog.h:92
vtkTimerLog
Timer support and logging.
Definition: vtkTimerLog.h:81
vtkTimerLog::TicksPerSecond
static int TicksPerSecond
Definition: vtkTimerLog.h:200
vtkTimerLog::FirstWallTime
static timeval FirstWallTime
Definition: vtkTimerLog.h:212
vtkTimerLog::GetElapsedTime
double GetElapsedTime()
Returns the difference between StartTime and EndTime as a doubleing point value indicating the elapse...
vtkTimerLog::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkTimerLog::MarkEndEvent
static void MarkEndEvent(const char *EventString)
vtkTimerLog::GetNumberOfEvents
static int GetNumberOfEvents()
Programatic access to events.
vtkTimerLog::SetMaxEntries
static void SetMaxEntries(int a)
Set/Get the maximum number of entries allowed in the timer log.
vtkTimerLogEntry::CpuTicks
int CpuTicks
Definition: vtkTimerLog.h:75
vtkTimerLog::EndTime
double EndTime
Definition: vtkTimerLog.h:221
vtkTimerLog::TimerLog
static vtkTimerLogEntry * TimerLog
Definition: vtkTimerLog.h:201
vtkTimerLog::CurrentCpuTicks
static tms CurrentCpuTicks
Definition: vtkTimerLog.h:215
vtkTimerLog::MaxEntries
static int MaxEntries
Definition: vtkTimerLog.h:197
vtkX3D::index
@ index
Definition: vtkX3D.h:246
vtkTimerLog::DumpEntry
static void DumpEntry(ostream &os, int index, double time, double deltatime, int tick, int deltatick, const char *event)
vtkTimerLog::ResetLog
static void ResetLog()
Clear the timing table.