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 "vtkObject.h" 00037 00038 #ifdef _WIN32 00039 #ifndef _WIN32_WCE 00040 #include <sys/types.h> // Needed for Win32 implementation of timer 00041 #include <sys/timeb.h> // Needed for Win32 implementation of timer 00042 #endif 00043 #else 00044 #include <time.h> // Needed for unix implementation of timer 00045 #include <sys/time.h> // Needed for unix implementation of timer 00046 #include <sys/types.h> // Needed for unix implementation of timer 00047 #include <sys/times.h> // Needed for unix implementation of timer 00048 #endif 00049 00050 // var args 00051 #ifndef _WIN32 00052 #include <unistd.h> // Needed for unix implementation of timer 00053 #endif 00054 00055 // select stuff here is for sleep method 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 //BTX 00073 typedef struct 00074 { 00075 double WallTime; 00076 int CpuTicks; 00077 char Event[VTK_LOG_EVENT_LENGTH]; 00078 unsigned char Indent; 00079 } vtkTimerLogEntry; 00080 //ETX 00081 00082 class VTK_COMMON_EXPORT vtkTimerLog : public vtkObject 00083 { 00084 public: 00085 static vtkTimerLog *New(); 00086 00087 vtkTypeMacro(vtkTimerLog,vtkObject); 00088 void PrintSelf(ostream& os, vtkIndent indent); 00089 00091 00093 static void SetLogging(int v) {vtkTimerLog::Logging = v;} 00094 static int GetLogging() {return vtkTimerLog::Logging;} 00095 static void LoggingOn() {vtkTimerLog::SetLogging(1);} 00096 static void LoggingOff() {vtkTimerLog::SetLogging(0);} 00098 00100 00101 static void SetMaxEntries(int a); 00102 static int GetMaxEntries(); 00104 00105 //BTX 00107 00109 static void FormatAndMarkEvent(const char *EventString, ...); 00110 //ETX 00112 00115 static void DumpLog(const char *filename); 00116 00118 00121 static void MarkStartEvent(const char *EventString); 00122 static void MarkEndEvent(const char *EventString); 00123 //BTX 00124 static void DumpLogWithIndents(ostream *os, double threshold); 00125 //ETX 00127 00129 00130 static int GetNumberOfEvents(); 00131 static int GetEventIndent(int i); 00132 static double GetEventWallTime(int i); 00133 static const char* GetEventString(int i); 00135 00137 static void MarkEvent(const char *EventString); 00138 00141 static void ResetLog(); 00142 00144 static void AllocateLog(); 00145 00147 static void CleanupLog(); 00148 00151 static double GetUniversalTime(); 00152 00155 static double GetCPUTime(); 00156 00158 void StartTimer(); 00159 00161 void StopTimer(); 00162 00165 double GetElapsedTime(); 00166 00167 #ifdef VTK_WORKAROUND_WINDOWS_MANGLE 00168 # define GetTickCount GetCurrentTime 00169 #endif 00170 00173 VTK_LEGACY(static double GetCurrentTime()); 00174 00175 #ifdef VTK_WORKAROUND_WINDOWS_MANGLE 00176 # undef GetTickCount 00177 //BTX 00178 VTK_LEGACY(static double GetTickCount()); 00179 //ETX 00180 #endif 00181 00182 protected: 00183 vtkTimerLog() {this->StartTime=0; this->EndTime = 0;}; //insure constructor/destructor protected 00184 virtual ~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 // instance variables to support simple timing functionality, 00212 // separate from timer table logging. 00213 double StartTime; 00214 double EndTime; 00215 00216 //BTX 00217 static void DumpEntry(ostream& os, int index, double time, double deltatime, 00218 int tick, int deltatick, const char *event); 00219 //ETX 00220 00221 private: 00222 vtkTimerLog(const vtkTimerLog&); // Not implemented. 00223 void operator=(const vtkTimerLog&); // Not implemented. 00224 }; 00225 00226 00227 // 00228 // Set built-in type. Creates member Set"name"() (e.g., SetVisibility()); 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