00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00030 #ifndef __vtkTimerLog_h
00031 #define __vtkTimerLog_h
00032
00033 #include "vtkObject.h"
00034
00035 #ifdef _WIN32
00036 #ifndef _WIN32_WCE
00037 #include <sys/types.h>
00038 #include <sys/timeb.h>
00039 #endif
00040 #else
00041 #include <time.h>
00042 #include <sys/time.h>
00043 #include <sys/types.h>
00044 #include <sys/times.h>
00045 #endif
00046
00047
00048 #ifndef _WIN32
00049 #include <unistd.h>
00050 #endif
00051
00052
00053 #ifndef NO_FD_SET
00054 # define SELECT_MASK fd_set
00055 #else
00056 # ifndef _AIX
00057 typedef long fd_mask;
00058 # endif
00059 # if defined(_IBMR2)
00060 # define SELECT_MASK void
00061 # else
00062 # define SELECT_MASK int
00063 # endif
00064 #endif
00065
00066
00067 #define VTK_LOG_EVENT_LENGTH 40
00068
00069
00070 typedef struct
00071 {
00072 double WallTime;
00073 int CpuTicks;
00074 char Event[VTK_LOG_EVENT_LENGTH];
00075 unsigned char Indent;
00076 } vtkTimerLogEntry;
00077
00078
00079 class VTK_COMMON_EXPORT vtkTimerLog : public vtkObject
00080 {
00081 public:
00082 static vtkTimerLog *New();
00083
00084 vtkTypeMacro(vtkTimerLog,vtkObject);
00085 void PrintSelf(ostream& os, vtkIndent indent);
00086
00088
00090 static void SetLogging(int v) {vtkTimerLog::Logging = v;}
00091 static int GetLogging() {return vtkTimerLog::Logging;}
00092 static void LoggingOn() {vtkTimerLog::SetLogging(1);}
00093 static void LoggingOff() {vtkTimerLog::SetLogging(0);}
00095
00097
00098 static void SetMaxEntries(int a);
00099 static int GetMaxEntries();
00101
00102
00105 static void FormatAndMarkEvent(const char *EventString, ...);
00106
00107
00110 static void DumpLog(const char *filename);
00111
00113
00116 static void MarkStartEvent(const char *EventString);
00117 static void MarkEndEvent(const char *EventString);
00119
00120 static void DumpLogWithIndents(ostream *os, double threshold);
00121
00122
00124
00125 static int GetNumberOfEvents();
00126 static int GetEventIndent(int i);
00127 static double GetEventWallTime(int i);
00128 static const char* GetEventString(int i);
00130
00132 static void MarkEvent(const char *EventString);
00133
00136 static void ResetLog();
00137
00139 static void AllocateLog();
00140
00142 static void CleanupLog();
00143
00146 static double GetUniversalTime();
00147
00150 static double GetCPUTime();
00151
00153 void StartTimer();
00154
00156 void StopTimer();
00157
00160 double GetElapsedTime();
00161
00162 #ifdef VTK_WORKAROUND_WINDOWS_MANGLE
00163 # define GetTickCount GetCurrentTime
00164 #endif
00165
00168 VTK_LEGACY(static double GetCurrentTime());
00169
00170 #ifdef VTK_WORKAROUND_WINDOWS_MANGLE
00171 # undef GetTickCount
00172
00173 VTK_LEGACY(static double GetTickCount());
00174
00175 #endif
00176
00177 protected:
00178 vtkTimerLog() {this->StartTime=0; this->EndTime = 0;};
00179 virtual ~vtkTimerLog() { };
00180
00181 static vtkTimerLogEntry* GetEvent(int i);
00182
00183 static int Logging;
00184 static int Indent;
00185 static int MaxEntries;
00186 static int NextEntry;
00187 static int WrapFlag;
00188 static int TicksPerSecond;
00189 static vtkTimerLogEntry *TimerLog;
00190
00191 #ifdef _WIN32
00192 #ifndef _WIN32_WCE
00193 static timeb FirstWallTime;
00194 static timeb CurrentWallTime;
00195 #else
00196 static FILETIME FirstWallTime;
00197 static FILETIME CurrentWallTime;
00198 #endif
00199 #else
00200 static timeval FirstWallTime;
00201 static timeval CurrentWallTime;
00202 static tms FirstCpuTicks;
00203 static tms CurrentCpuTicks;
00204 #endif
00205
00206
00207
00208 double StartTime;
00209 double EndTime;
00210
00211
00212 static void DumpEntry(ostream& os, int index, double time, double deltatime,
00213 int tick, int deltatick, const char *event);
00214
00215
00216 private:
00217 vtkTimerLog(const vtkTimerLog&);
00218 void operator=(const vtkTimerLog&);
00219 };
00220
00221
00222
00223
00224
00225 #define vtkTimerLogMacro(string) \
00226 { \
00227 vtkTimerLog::FormatAndMarkEvent("Mark: In %s, line %d, class %s: %s", \
00228 __FILE__, __LINE__, this->GetClassName(), string); \
00229 }
00230
00231 #endif