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