vtkTimerLog.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00045 #ifndef __vtkTimerLog_h
00046 #define __vtkTimerLog_h
00047
00048 #include "vtkObject.h"
00049
00050 #ifdef _WIN32
00051 #ifndef _WIN32_WCE
00052 #include <sys/types.h>
00053 #include <sys/timeb.h>
00054 #endif
00055 #else
00056 #include <time.h>
00057 #include <sys/time.h>
00058 #include <sys/types.h>
00059 #include <sys/times.h>
00060 #endif
00061
00062
00063 #ifndef _WIN32
00064 #include <unistd.h>
00065 #endif
00066
00067
00068 #ifndef NO_FD_SET
00069 # define SELECT_MASK fd_set
00070 #else
00071 # ifndef _AIX
00072 typedef long fd_mask;
00073 # endif
00074 # if defined(_IBMR2)
00075 # define SELECT_MASK void
00076 # else
00077 # define SELECT_MASK int
00078 # endif
00079 #endif
00080
00081
00082 #define VTK_LOG_EVENT_LENGTH 40
00083
00084
00085 typedef struct
00086 {
00087 double WallTime;
00088 int CpuTicks;
00089 char Event[VTK_LOG_EVENT_LENGTH];
00090 unsigned char Indent;
00091 } vtkTimerLogEntry;
00092
00093
00094
00095
00096 #undef GetCurrentTime
00097
00098 class VTK_COMMON_EXPORT vtkTimerLog : public vtkObject
00099 {
00100 public:
00101 static vtkTimerLog *New();
00102
00103 vtkTypeRevisionMacro(vtkTimerLog,vtkObject);
00104 void PrintSelf(ostream& os, vtkIndent indent);
00105
00107
00109 static void SetLogging(int v) {vtkTimerLog::Logging = v;}
00110 static int GetLogging() {return vtkTimerLog::Logging;}
00111 static void LoggingOn() {vtkTimerLog::SetLogging(1);}
00112 static void LoggingOff() {vtkTimerLog::SetLogging(0);}
00114
00116
00117 static void SetMaxEntries(int a);
00118 static int GetMaxEntries();
00120
00121
00124 static void FormatAndMarkEvent(const char *EventString, ...);
00125
00126
00129 static void DumpLog(const char *filename);
00130
00132
00135 static void MarkStartEvent(const char *EventString);
00136 static void MarkEndEvent(const char *EventString);
00138
00139 static void DumpLogWithIndents(ostream *os, double threshold);
00140
00141
00143
00144 static int GetNumberOfEvents();
00145 static int GetEventIndent(int i);
00146 static double GetEventWallTime(int i);
00147 static const char* GetEventString(int i);
00149
00151 static void MarkEvent(const char *EventString);
00152
00155 static void ResetLog();
00156
00158 static void AllocateLog();
00159
00161 static void CleanupLog();
00162
00165 static double GetCurrentTime();
00166
00169 static double GetCPUTime();
00170
00172 void StartTimer();
00173
00175 void StopTimer();
00176
00179 double GetElapsedTime();
00180
00181 protected:
00182 vtkTimerLog() {this->StartTime=0; this->EndTime = 0;};
00183 virtual ~vtkTimerLog() { };
00184
00185 static vtkTimerLogEntry* GetEvent(int i);
00186
00187 static int Logging;
00188 static int Indent;
00189 static int MaxEntries;
00190 static int NextEntry;
00191 static int WrapFlag;
00192 static int TicksPerSecond;
00193 static vtkTimerLogEntry *TimerLog;
00194
00195 #ifdef _WIN32
00196 #ifndef _WIN32_WCE
00197 static timeb FirstWallTime;
00198 static timeb CurrentWallTime;
00199 #else
00200 static FILETIME FirstWallTime;
00201 static FILETIME CurrentWallTime;
00202 #endif
00203 #else
00204 static timeval FirstWallTime;
00205 static timeval CurrentWallTime;
00206 static tms FirstCpuTicks;
00207 static tms CurrentCpuTicks;
00208 #endif
00209
00210
00211
00212 double StartTime;
00213 double EndTime;
00214
00215
00216 static void DumpEntry(ostream& os, int index, double time, double deltatime,
00217 int tick, int deltatick, const char *event);
00218
00219
00220 private:
00221 vtkTimerLog(const vtkTimerLog&);
00222 void operator=(const vtkTimerLog&);
00223 };
00224
00225
00226
00227
00228
00229 #define vtkTimerLogMacro(string) \
00230 { \
00231 vtkTimerLog::FormatAndMarkEvent("Mark: In %s, line %d, class %s: %s", \
00232 __FILE__, __LINE__, this->GetClassName(), string); \
00233 }
00234
00235 #endif