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 =========================================================================*/
28 #ifndef vtkTimerLog_h
29 #define vtkTimerLog_h
30 
31 #include "vtkCommonSystemModule.h" // For export macro
32 #include "vtkObject.h"
33 
34 #include <string> // STL Header
35 #include <vector> // STL Header
36 
37 #ifdef _WIN32
38 #include <sys/types.h> // Needed for Win32 implementation of timer
39 #include <sys/timeb.h> // Needed for Win32 implementation of timer
40 #else
41 #include <time.h> // Needed for unix implementation of timer
42 #include <sys/time.h> // Needed for unix implementation of timer
43 #include <sys/types.h> // Needed for unix implementation of timer
44 #include <sys/times.h> // Needed for unix implementation of timer
45 #endif
46 
47 // var args
48 #ifndef _WIN32
49 #include <unistd.h> // Needed for unix implementation of timer
50 #endif
51 
52 // select stuff here is for sleep method
53 #ifndef NO_FD_SET
54 # define SELECT_MASK fd_set
55 #else
56 # ifndef _AIX
57  typedef long fd_mask;
58 # endif
59 # if defined(_IBMR2)
60 # define SELECT_MASK void
61 # else
62 # define SELECT_MASK int
63 # endif
64 #endif
65 
67 {
69  {
70  INVALID = -1,
71  STANDALONE, // an individual, marked event
72  START, // start of a timed event
73  END, // end of a timed event
74  INSERTED // externally timed value
75  };
76  double WallTime;
77  int CpuTicks;
80  unsigned char Indent;
81  vtkTimerLogEntry() : WallTime(0), CpuTicks(0), Type(INVALID), Indent(0)
82  {}
83 };
84 
85 class VTKCOMMONSYSTEM_EXPORT vtkTimerLog : public vtkObject
86 {
87 public:
88  static vtkTimerLog *New();
89 
90  vtkTypeMacro(vtkTimerLog,vtkObject);
91  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
92 
97  static void SetLogging(int v) {vtkTimerLog::Logging = v;}
98  static int GetLogging() {return vtkTimerLog::Logging;}
99  static void LoggingOn() {vtkTimerLog::SetLogging(1);}
101 
103 
106  static void SetMaxEntries(int a);
107  static int GetMaxEntries();
109 
114  static void FormatAndMarkEvent(const char *EventString, ...);
115 
117 
121  static void DumpLog(const char *filename);
123 
125 
130  static void MarkStartEvent(const char *EventString);
131  static void MarkEndEvent(const char *EventString);
133 
135 
139  static void InsertTimedEvent(
140  const char *EventString, double time, int cpuTicks);
142 
143  static void DumpLogWithIndents(ostream *os, double threshold);
144  static void DumpLogWithIndentsAndPercentages(ostream *os);
145 
147 
150  static int GetNumberOfEvents();
151  static int GetEventIndent(int i);
152  static double GetEventWallTime(int i);
153  static const char* GetEventString(int i);
154  static vtkTimerLogEntry::LogEntryType GetEventType(int i);
156 
160  static void MarkEvent(const char *EventString);
161 
166  static void ResetLog();
167 
169 
173  static void AllocateLog();
175 
179  static void CleanupLog();
180 
185  static double GetUniversalTime();
186 
191  static double GetCPUTime();
192 
196  void StartTimer();
197 
201  void StopTimer();
202 
207  double GetElapsedTime();
208 
209 protected:
210  vtkTimerLog() {this->StartTime=0; this->EndTime = 0;}; //insure constructor/destructor protected
211  ~vtkTimerLog() VTK_OVERRIDE { };
212 
213  static int Logging;
214  static int Indent;
215  static int MaxEntries;
216  static int NextEntry;
217  static int WrapFlag;
218  static int TicksPerSecond;
219  static std::vector<vtkTimerLogEntry> TimerLog;
220 
221 #ifdef _WIN32
222 #ifndef _WIN32_WCE
223  static timeb FirstWallTime;
224  static timeb CurrentWallTime;
225 #else
226  static FILETIME FirstWallTime;
227  static FILETIME CurrentWallTime;
228 #endif
229 #else
230  static timeval FirstWallTime;
231  static timeval CurrentWallTime;
232  static tms FirstCpuTicks;
233  static tms CurrentCpuTicks;
234 #endif
235 
239  static void MarkEventInternal(
240  const char *EventString, vtkTimerLogEntry::LogEntryType type,
241  vtkTimerLogEntry* entry = nullptr);
242 
243  // instance variables to support simple timing functionality,
244  // separate from timer table logging.
245  double StartTime;
246  double EndTime;
247 
248  static vtkTimerLogEntry* GetEvent(int i);
249 
250  static void DumpEntry(ostream& os, int index, double time, double deltatime,
251  int tick, int deltatick, const char *event);
252 
253 private:
254  vtkTimerLog(const vtkTimerLog&) VTK_DELETE_FUNCTION;
255  void operator=(const vtkTimerLog&) VTK_DELETE_FUNCTION;
256 };
257 
258 
259 //
260 // Set built-in type. Creates member Set"name"() (e.g., SetVisibility());
261 //
262 #define vtkTimerLogMacro(string) \
263  { \
264  vtkTimerLog::FormatAndMarkEvent("Mark: In %s, line %d, class %s: %s", \
265  __FILE__, __LINE__, this->GetClassName(), string); \
266  }
267 
268 #endif
static int Indent
Definition: vtkTimerLog.h:214
abstract base class for most VTK objects
Definition: vtkObject.h:53
static std::vector< vtkTimerLogEntry > TimerLog
Definition: vtkTimerLog.h:219
static void LoggingOn()
Definition: vtkTimerLog.h:99
~vtkTimerLog() override
Definition: vtkTimerLog.h:211
double StartTime
Definition: vtkTimerLog.h:245
std::string Event
Definition: vtkTimerLog.h:78
Timer support and logging.
Definition: vtkTimerLog.h:85
static tms FirstCpuTicks
Definition: vtkTimerLog.h:232
static int WrapFlag
Definition: vtkTimerLog.h:217
a simple class to control print indentation
Definition: vtkIndent.h:33
static int NextEntry
Definition: vtkTimerLog.h:216
static timeval CurrentWallTime
Definition: vtkTimerLog.h:231
static void LoggingOff()
Definition: vtkTimerLog.h:100
static int Logging
Definition: vtkTimerLog.h:211
unsigned char Indent
Definition: vtkTimerLog.h:80
static void SetLogging(int v)
This flag will turn logging of events off or on.
Definition: vtkTimerLog.h:97
LogEntryType Type
Definition: vtkTimerLog.h:79
static int MaxEntries
Definition: vtkTimerLog.h:215
static int GetLogging()
Definition: vtkTimerLog.h:98
static int TicksPerSecond
Definition: vtkTimerLog.h:218
static timeval FirstWallTime
Definition: vtkTimerLog.h:230
static tms CurrentCpuTicks
Definition: vtkTimerLog.h:233
double EndTime
Definition: vtkTimerLog.h:246