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