Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

dox/Common/vtkTimerLog.h

Go to the documentation of this file.
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: $RCSfile: vtkTimerLog.h,v $ 00005 Language: C++ 00006 00007 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 00008 All rights reserved. 00009 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00010 00011 This software is distributed WITHOUT ANY WARRANTY; without even 00012 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00013 PURPOSE. See the above copyright notice for more information. 00014 00015 =========================================================================*/ 00037 #ifndef __vtkTimerLog_h 00038 #define __vtkTimerLog_h 00039 00040 #include "vtkObject.h" 00041 00042 #ifdef _WIN32 00043 #ifndef _WIN32_WCE 00044 #include <sys/types.h> // Needed for Win32 implementation of timer 00045 #include <sys/timeb.h> // Needed for Win32 implementation of timer 00046 #endif 00047 #else 00048 #include <time.h> // Needed for unix implementation of timer 00049 #include <sys/time.h> // Needed for unix implementation of timer 00050 #include <sys/types.h> // Needed for unix implementation of timer 00051 #include <sys/times.h> // Needed for unix implementation of timer 00052 #endif 00053 00054 // var args 00055 #ifndef _WIN32 00056 #include <unistd.h> // Needed for unix implementation of timer 00057 #endif 00058 00059 // select stuff here is for sleep method 00060 #ifndef NO_FD_SET 00061 # define SELECT_MASK fd_set 00062 #else 00063 # ifndef _AIX 00064 typedef long fd_mask; 00065 # endif 00066 # if defined(_IBMR2) 00067 # define SELECT_MASK void 00068 # else 00069 # define SELECT_MASK int 00070 # endif 00071 #endif 00072 00073 00074 #define VTK_LOG_EVENT_LENGTH 40 00075 00076 //BTX 00077 typedef struct 00078 { 00079 float WallTime; 00080 int CpuTicks; 00081 char Event[VTK_LOG_EVENT_LENGTH]; 00082 unsigned char Indent; 00083 } vtkTimerLogEntry; 00084 //ETX 00085 00086 // The microsoft compiler defines this as a macro, so 00087 // undefine it here 00088 #undef GetCurrentTime 00089 00090 class VTK_COMMON_EXPORT vtkTimerLog : public vtkObject 00091 { 00092 public: 00093 static vtkTimerLog *New(); 00094 00095 vtkTypeRevisionMacro(vtkTimerLog,vtkObject); 00096 void PrintSelf(ostream& os, vtkIndent indent); 00097 00099 00101 static void SetLogging(int v) {vtkTimerLog::Logging = v;} 00102 static int GetLogging() {return vtkTimerLog::Logging;} 00103 static void LoggingOn() {vtkTimerLog::SetLogging(1);} 00104 static void LoggingOff() {vtkTimerLog::SetLogging(0);} 00106 00108 00109 static void SetMaxEntries(int a); 00110 static int GetMaxEntries(); 00112 00113 //BTX 00116 static void FormatAndMarkEvent(const char *EventString, ...); 00117 //ETX 00118 00121 static void DumpLog(const char *filename); 00122 00124 00127 static void MarkStartEvent(const char *EventString); 00128 static void MarkEndEvent(const char *EventString); 00130 //BTX 00131 static void DumpLogWithIndents(ostream *os, float threshold); 00132 //ETX 00133 00135 00136 static int GetNumberOfEvents(); 00137 static int GetEventIndent(int i); 00138 static float GetEventWallTime(int i); 00139 static const char* GetEventString(int i); 00141 00143 static void MarkEvent(const char *EventString); 00144 00147 static void ResetLog(); 00148 00150 static void AllocateLog(); 00151 00154 static double GetCurrentTime(); 00155 00158 static double GetCPUTime(); 00159 00161 void StartTimer(); 00162 00164 void StopTimer(); 00165 00168 double GetElapsedTime(); 00169 00170 protected: 00171 vtkTimerLog() {this->StartTime=0; this->EndTime = 0;}; //insure constructor/destructor protected 00172 ~vtkTimerLog() {}; 00173 00174 static vtkTimerLogEntry* GetEvent(int i); 00175 00176 static int Logging; 00177 static int Indent; 00178 static int MaxEntries; 00179 static int NextEntry; 00180 static int WrapFlag; 00181 static int TicksPerSecond; 00182 static vtkTimerLogEntry *TimerLog; 00183 00184 #ifdef _WIN32 00185 #ifndef _WIN32_WCE 00186 static timeb FirstWallTime; 00187 static timeb CurrentWallTime; 00188 #else 00189 static FILETIME FirstWallTime; 00190 static FILETIME CurrentWallTime; 00191 #endif 00192 #else 00193 static timeval FirstWallTime; 00194 static timeval CurrentWallTime; 00195 static tms FirstCpuTicks; 00196 static tms CurrentCpuTicks; 00197 #endif 00198 00199 // instance variables to support simple timing functionality, 00200 // separate from timer table logging. 00201 double StartTime; 00202 double EndTime; 00203 00204 //BTX 00205 static void DumpEntry(ostream& os, int index, float time, float deltatime, 00206 int tick, int deltatick, const char *event); 00207 //ETX 00208 00209 private: 00210 vtkTimerLog(const vtkTimerLog&); // Not implemented. 00211 void operator=(const vtkTimerLog&); // Not implemented. 00212 }; 00213 00214 00215 // 00216 // Set built-in type. Creates member Set"name"() (e.g., SetVisibility()); 00217 // 00218 #define vtkTimerLogMacro(string) \ 00219 { \ 00220 vtkTimerLog::FormatAndMarkEvent("Mark: In %s, line %d, class %s: %s", \ 00221 __FILE__, __LINE__, this->GetClassName(), string); \ 00222 } 00223 00224 #endif