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

vtkTimerLog.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkTimerLog.h,v $
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 =========================================================================*/
00030 #ifndef __vtkTimerLog_h
00031 #define __vtkTimerLog_h
00032 
00033 #include "vtkObject.h"
00034 
00035 #ifdef _WIN32
00036 #ifndef _WIN32_WCE
00037 #include <sys/types.h> // Needed for Win32 implementation of timer
00038 #include <sys/timeb.h> // Needed for Win32 implementation of timer
00039 #endif
00040 #else
00041 #include <time.h>      // Needed for unix implementation of timer
00042 #include <sys/time.h>  // Needed for unix implementation of timer
00043 #include <sys/types.h> // Needed for unix implementation of timer
00044 #include <sys/times.h> // Needed for unix implementation of timer
00045 #endif
00046 
00047 // var args
00048 #ifndef _WIN32
00049 #include <unistd.h>    // Needed for unix implementation of timer
00050 #endif
00051 
00052 // select stuff here is for sleep method
00053 #ifndef NO_FD_SET
00054 #   define SELECT_MASK fd_set
00055 #else
00056 #   ifndef _AIX
00057         typedef long fd_mask;
00058 #   endif
00059 #   if defined(_IBMR2)
00060 #       define SELECT_MASK void
00061 #   else
00062 #       define SELECT_MASK int
00063 #   endif
00064 #endif
00065 
00066 
00067 #define VTK_LOG_EVENT_LENGTH 40
00068 
00069 //BTX
00070 typedef struct
00071 {
00072   double WallTime;
00073   int CpuTicks;
00074   char Event[VTK_LOG_EVENT_LENGTH];
00075   unsigned char Indent;
00076 } vtkTimerLogEntry;
00077 //ETX
00078 
00079 class VTK_COMMON_EXPORT vtkTimerLog : public vtkObject 
00080 {
00081 public:
00082   static vtkTimerLog *New();
00083 
00084   vtkTypeRevisionMacro(vtkTimerLog,vtkObject);
00085   void PrintSelf(ostream& os, vtkIndent indent);
00086 
00088 
00090   static void SetLogging(int v) {vtkTimerLog::Logging = v;}
00091   static int GetLogging() {return vtkTimerLog::Logging;}
00092   static void LoggingOn() {vtkTimerLog::SetLogging(1);}
00093   static void LoggingOff() {vtkTimerLog::SetLogging(0);}
00095 
00097 
00098   static void SetMaxEntries(int a);
00099   static int  GetMaxEntries();
00101 
00102 //BTX
00105   static void FormatAndMarkEvent(const char *EventString, ...);
00106 //ETX
00107   
00110   static void DumpLog(const char *filename);
00111 
00113 
00116   static void MarkStartEvent(const char *EventString);
00117   static void MarkEndEvent(const char *EventString);
00119 //BTX
00120   static void DumpLogWithIndents(ostream *os, double threshold);
00121 //ETX
00122 
00124 
00125   static int GetNumberOfEvents();
00126   static int GetEventIndent(int i);
00127   static double GetEventWallTime(int i);
00128   static const char* GetEventString(int i);
00130 
00132   static void MarkEvent(const char *EventString);
00133 
00136   static void ResetLog();
00137 
00139   static void AllocateLog();
00140 
00142   static void CleanupLog();
00143 
00146   static double GetUniversalTime();
00147 
00150   static double GetCPUTime();
00151 
00153   void StartTimer();
00154 
00156   void StopTimer();
00157 
00160   double GetElapsedTime();
00161 
00162 #ifdef VTK_WORKAROUND_WINDOWS_MANGLE
00163 # define GetTickCount GetCurrentTime
00164 #endif
00165 
00168   VTK_LEGACY(static double GetCurrentTime());
00169 
00170 #ifdef VTK_WORKAROUND_WINDOWS_MANGLE
00171 # undef GetTickCount
00172   //BTX
00173   VTK_LEGACY(static double GetTickCount());
00174   //ETX
00175 #endif
00176 
00177 protected:
00178   vtkTimerLog() {this->StartTime=0; this->EndTime = 0;}; //insure constructor/destructor protected
00179   virtual ~vtkTimerLog() { };
00180 
00181   static vtkTimerLogEntry* GetEvent(int i);
00182 
00183   static int               Logging;
00184   static int               Indent;
00185   static int               MaxEntries;
00186   static int               NextEntry;
00187   static int               WrapFlag;
00188   static int               TicksPerSecond;
00189   static vtkTimerLogEntry *TimerLog;
00190 
00191 #ifdef _WIN32
00192 #ifndef _WIN32_WCE
00193   static timeb             FirstWallTime;
00194   static timeb             CurrentWallTime;
00195 #else
00196   static FILETIME FirstWallTime;
00197   static FILETIME CurrentWallTime;
00198 #endif
00199 #else
00200   static timeval           FirstWallTime;
00201   static timeval           CurrentWallTime;
00202   static tms               FirstCpuTicks;
00203   static tms               CurrentCpuTicks;
00204 #endif
00205 
00206   // instance variables to support simple timing functionality,
00207   // separate from timer table logging.
00208   double StartTime;
00209   double EndTime;
00210 
00211   //BTX
00212   static void DumpEntry(ostream& os, int index, double time, double deltatime,
00213                         int tick, int deltatick, const char *event);
00214   //ETX
00215 
00216 private:
00217   vtkTimerLog(const vtkTimerLog&);  // Not implemented.
00218   void operator=(const vtkTimerLog&);  // Not implemented.
00219 };
00220 
00221 
00222 //
00223 // Set built-in type.  Creates member Set"name"() (e.g., SetVisibility());
00224 //
00225 #define vtkTimerLogMacro(string) \
00226   { \
00227       vtkTimerLog::FormatAndMarkEvent("Mark: In %s, line %d, class %s: %s", \
00228                               __FILE__, __LINE__, this->GetClassName(), string); \
00229   }
00230 
00231 #endif

Generated on Mon Jan 21 23:07:18 2008 for VTK by  doxygen 1.4.3-20050530