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