Main Page | Directories | Class Hierarchy | Alphabetical List | Class List | 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 =========================================================================*/
00045 #ifndef __vtkTimerLog_h
00046 #define __vtkTimerLog_h
00047 
00048 #include "vtkObject.h"
00049 
00050 #ifdef _WIN32
00051 #ifndef _WIN32_WCE
00052 #include <sys/types.h> // Needed for Win32 implementation of timer
00053 #include <sys/timeb.h> // Needed for Win32 implementation of timer
00054 #endif
00055 #else
00056 #include <time.h>      // Needed for unix implementation of timer
00057 #include <sys/time.h>  // Needed for unix implementation of timer
00058 #include <sys/types.h> // Needed for unix implementation of timer
00059 #include <sys/times.h> // Needed for unix implementation of timer
00060 #endif
00061 
00062 // var args
00063 #ifndef _WIN32
00064 #include <unistd.h>    // Needed for unix implementation of timer
00065 #endif
00066 
00067 // select stuff here is for sleep method
00068 #ifndef NO_FD_SET
00069 #   define SELECT_MASK fd_set
00070 #else
00071 #   ifndef _AIX
00072         typedef long fd_mask;
00073 #   endif
00074 #   if defined(_IBMR2)
00075 #       define SELECT_MASK void
00076 #   else
00077 #       define SELECT_MASK int
00078 #   endif
00079 #endif
00080 
00081 
00082 #define VTK_LOG_EVENT_LENGTH 40
00083 
00084 //BTX
00085 typedef struct
00086 {
00087   double WallTime;
00088   int CpuTicks;
00089   char Event[VTK_LOG_EVENT_LENGTH];
00090   unsigned char Indent;
00091 } vtkTimerLogEntry;
00092 //ETX
00093 
00094 // The microsoft compiler defines this as a macro, so
00095 // undefine it here
00096 #undef GetCurrentTime
00097 
00098 class VTK_COMMON_EXPORT vtkTimerLog : public vtkObject 
00099 {
00100 public:
00101   static vtkTimerLog *New();
00102 
00103   vtkTypeRevisionMacro(vtkTimerLog,vtkObject);
00104   void PrintSelf(ostream& os, vtkIndent indent);
00105 
00107 
00109   static void SetLogging(int v) {vtkTimerLog::Logging = v;}
00110   static int GetLogging() {return vtkTimerLog::Logging;}
00111   static void LoggingOn() {vtkTimerLog::SetLogging(1);}
00112   static void LoggingOff() {vtkTimerLog::SetLogging(0);}
00114 
00116 
00117   static void SetMaxEntries(int a);
00118   static int  GetMaxEntries();
00120 
00121 //BTX
00124   static void FormatAndMarkEvent(const char *EventString, ...);
00125 //ETX
00126   
00129   static void DumpLog(const char *filename);
00130 
00132 
00135   static void MarkStartEvent(const char *EventString);
00136   static void MarkEndEvent(const char *EventString);
00138 //BTX
00139   static void DumpLogWithIndents(ostream *os, double threshold);
00140 //ETX
00141 
00143 
00144   static int GetNumberOfEvents();
00145   static int GetEventIndent(int i);
00146   static double GetEventWallTime(int i);
00147   static const char* GetEventString(int i);
00149 
00151   static void MarkEvent(const char *EventString);
00152 
00155   static void ResetLog();
00156 
00158   static void AllocateLog();
00159 
00161   static void CleanupLog();
00162 
00165   static double GetCurrentTime();
00166 
00169   static double GetCPUTime();
00170 
00172   void StartTimer();
00173 
00175   void StopTimer();
00176 
00179   double GetElapsedTime();
00180 
00181 protected:
00182   vtkTimerLog() {this->StartTime=0; this->EndTime = 0;}; //insure constructor/destructor protected
00183   virtual ~vtkTimerLog() { };
00184 
00185   static vtkTimerLogEntry* GetEvent(int i);
00186 
00187   static int               Logging;
00188   static int               Indent;
00189   static int               MaxEntries;
00190   static int               NextEntry;
00191   static int               WrapFlag;
00192   static int               TicksPerSecond;
00193   static vtkTimerLogEntry *TimerLog;
00194 
00195 #ifdef _WIN32
00196 #ifndef _WIN32_WCE
00197   static timeb             FirstWallTime;
00198   static timeb             CurrentWallTime;
00199 #else
00200   static FILETIME FirstWallTime;
00201   static FILETIME CurrentWallTime;
00202 #endif
00203 #else
00204   static timeval           FirstWallTime;
00205   static timeval           CurrentWallTime;
00206   static tms               FirstCpuTicks;
00207   static tms               CurrentCpuTicks;
00208 #endif
00209 
00210   // instance variables to support simple timing functionality,
00211   // separate from timer table logging.
00212   double StartTime;
00213   double EndTime;
00214 
00215   //BTX
00216   static void DumpEntry(ostream& os, int index, double time, double deltatime,
00217                         int tick, int deltatick, const char *event);
00218   //ETX
00219 
00220 private:
00221   vtkTimerLog(const vtkTimerLog&);  // Not implemented.
00222   void operator=(const vtkTimerLog&);  // Not implemented.
00223 };
00224 
00225 
00226 //
00227 // Set built-in type.  Creates member Set"name"() (e.g., SetVisibility());
00228 //
00229 #define vtkTimerLogMacro(string) \
00230   { \
00231       vtkTimerLog::FormatAndMarkEvent("Mark: In %s, line %d, class %s: %s", \
00232                               __FILE__, __LINE__, this->GetClassName(), string); \
00233   }
00234 
00235 #endif