Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound 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   Language:  C++
00006 
00007   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
00008   All rights reserved.
00009   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00010 
00011      This software is distributed WITHOUT ANY WARRANTY; without even 
00012      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00013      PURPOSE.  See the above copyright notice for more information.
00014 
00015 =========================================================================*/
00049 #ifndef __vtkTimerLog_h
00050 #define __vtkTimerLog_h
00051 
00052 #include "vtkObject.h"
00053 
00054 #ifdef _WIN32
00055 #ifndef _WIN32_WCE
00056 #include <sys/types.h> // Needed for Win32 implementation of timer
00057 #include <sys/timeb.h> // Needed for Win32 implementation of timer
00058 #endif
00059 #else
00060 #include <time.h>      // Needed for unix implementation of timer
00061 #include <sys/time.h>  // Needed for unix implementation of timer
00062 #include <sys/types.h> // Needed for unix implementation of timer
00063 #include <sys/times.h> // Needed for unix implementation of timer
00064 #endif
00065 
00066 // var args
00067 #ifndef _WIN32
00068 #include <unistd.h>    // Needed for unix implementation of timer
00069 #endif
00070 
00071 // select stuff here is for sleep method
00072 #ifndef NO_FD_SET
00073 #   define SELECT_MASK fd_set
00074 #else
00075 #   ifndef _AIX
00076         typedef long fd_mask;
00077 #   endif
00078 #   if defined(_IBMR2)
00079 #       define SELECT_MASK void
00080 #   else
00081 #       define SELECT_MASK int
00082 #   endif
00083 #endif
00084 
00085 
00086 #define VTK_LOG_EVENT_LENGTH 40
00087 
00088 //BTX
00089 typedef struct
00090 {
00091   float WallTime;
00092   int CpuTicks;
00093   char Event[VTK_LOG_EVENT_LENGTH];
00094   unsigned char Indent;
00095 } vtkTimerLogEntry;
00096 //ETX
00097 
00098 // The microsoft compiler defines this as a macro, so
00099 // undefine it here
00100 #undef GetCurrentTime
00101 
00102 class VTK_COMMON_EXPORT vtkTimerLog : public vtkObject 
00103 {
00104 public:
00105   static vtkTimerLog *New();
00106 
00107   vtkTypeRevisionMacro(vtkTimerLog,vtkObject);
00108   void PrintSelf(ostream& os, vtkIndent indent);
00109 
00111 
00113   static void SetLogging(int v) {vtkTimerLog::Logging = v;}
00114   static int GetLogging() {return vtkTimerLog::Logging;}
00115   static void LoggingOn() {vtkTimerLog::SetLogging(1);}
00116   static void LoggingOff() {vtkTimerLog::SetLogging(0);}
00118 
00120 
00121   static void SetMaxEntries(int a);
00122   static int  GetMaxEntries();
00124 
00125 //BTX
00128   static void FormatAndMarkEvent(const char *EventString, ...);
00129 //ETX
00130   
00133   static void DumpLog(const char *filename);
00134 
00136 
00139   static void MarkStartEvent(const char *EventString);
00140   static void MarkEndEvent(const char *EventString);
00142 //BTX
00143   static void DumpLogWithIndents(ostream *os, float threshold);
00144 //ETX
00145 
00147 
00148   static int GetNumberOfEvents();
00149   static int GetEventIndent(int i);
00150   static float GetEventWallTime(int i);
00151   static const char* GetEventString(int i);
00153 
00155   static void MarkEvent(const char *EventString);
00156 
00159   static void ResetLog();
00160 
00162   static void AllocateLog();
00163 
00166   static double GetCurrentTime();
00167 
00170   static double GetCPUTime();
00171 
00173   void StartTimer();
00174 
00176   void StopTimer();
00177 
00180   double GetElapsedTime();
00181 
00182 protected:
00183   vtkTimerLog() {this->StartTime=0; this->EndTime = 0;}; //insure constructor/destructor protected
00184   ~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, float time, float 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