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