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

Common/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 =========================================================================*/
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 // The microsoft compiler defines this as a macro, so
00083 // undefine it here
00084 #undef GetCurrentTime
00085 
00086 class VTK_COMMON_EXPORT vtkTimerLog : public vtkObject 
00087 {
00088 public:
00089   static vtkTimerLog *New();
00090 
00091   vtkTypeRevisionMacro(vtkTimerLog,vtkObject);
00092   void PrintSelf(ostream& os, vtkIndent indent);
00093 
00095 
00097   static void SetLogging(int v) {vtkTimerLog::Logging = v;}
00098   static int GetLogging() {return vtkTimerLog::Logging;}
00099   static void LoggingOn() {vtkTimerLog::SetLogging(1);}
00100   static void LoggingOff() {vtkTimerLog::SetLogging(0);}
00102 
00104 
00105   static void SetMaxEntries(int a);
00106   static int  GetMaxEntries();
00108 
00109 //BTX
00112   static void FormatAndMarkEvent(const char *EventString, ...);
00113 //ETX
00114   
00117   static void DumpLog(const char *filename);
00118 
00120 
00123   static void MarkStartEvent(const char *EventString);
00124   static void MarkEndEvent(const char *EventString);
00126 //BTX
00127   static void DumpLogWithIndents(ostream *os, double threshold);
00128 //ETX
00129 
00131 
00132   static int GetNumberOfEvents();
00133   static int GetEventIndent(int i);
00134   static double GetEventWallTime(int i);
00135   static const char* GetEventString(int i);
00137 
00139   static void MarkEvent(const char *EventString);
00140 
00143   static void ResetLog();
00144 
00146   static void AllocateLog();
00147 
00149   static void CleanupLog();
00150 
00153   static double GetCurrentTime();
00154 
00157   static double GetCPUTime();
00158 
00160   void StartTimer();
00161 
00163   void StopTimer();
00164 
00167   double GetElapsedTime();
00168 
00169 protected:
00170   vtkTimerLog() {this->StartTime=0; this->EndTime = 0;}; //insure constructor/destructor protected
00171   ~vtkTimerLog() {};
00172 
00173   static vtkTimerLogEntry* GetEvent(int i);
00174 
00175   static int               Logging;
00176   static int               Indent;
00177   static int               MaxEntries;
00178   static int               NextEntry;
00179   static int               WrapFlag;
00180   static int               TicksPerSecond;
00181   static vtkTimerLogEntry *TimerLog;
00182 
00183 #ifdef _WIN32
00184 #ifndef _WIN32_WCE
00185   static timeb             FirstWallTime;
00186   static timeb             CurrentWallTime;
00187 #else
00188   static FILETIME FirstWallTime;
00189   static FILETIME CurrentWallTime;
00190 #endif
00191 #else
00192   static timeval           FirstWallTime;
00193   static timeval           CurrentWallTime;
00194   static tms               FirstCpuTicks;
00195   static tms               CurrentCpuTicks;
00196 #endif
00197 
00198   // instance variables to support simple timing functionality,
00199   // separate from timer table logging.
00200   double StartTime;
00201   double EndTime;
00202 
00203   //BTX
00204   static void DumpEntry(ostream& os, int index, double time, double deltatime,
00205                         int tick, int deltatick, const char *event);
00206   //ETX
00207 
00208 private:
00209   vtkTimerLog(const vtkTimerLog&);  // Not implemented.
00210   void operator=(const vtkTimerLog&);  // Not implemented.
00211 };
00212 
00213 
00214 //
00215 // Set built-in type.  Creates member Set"name"() (e.g., SetVisibility());
00216 //
00217 #define vtkTimerLogMacro(string) \
00218   { \
00219       vtkTimerLog::FormatAndMarkEvent("Mark: In %s, line %d, class %s: %s", \
00220                               __FILE__, __LINE__, this->GetClassName(), string); \
00221   }
00222 
00223 #endif