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 
00008 Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen 
00009 All rights reserved.
00010 
00011 Redistribution and use in source and binary forms, with or without
00012 modification, are permitted provided that the following conditions are met:
00013 
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016 
00017  * Redistributions in binary form must reproduce the above copyright notice,
00018    this list of conditions and the following disclaimer in the documentation
00019    and/or other materials provided with the distribution.
00020 
00021  * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
00022    of any contributors may be used to endorse or promote products derived
00023    from this software without specific prior written permission.
00024 
00025  * Modified source versions must be plainly marked as such, and must not be
00026    misrepresented as being the original software.
00027 
00028 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00029 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00030 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00031 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
00032 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00033 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00034 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00035 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00036 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00037 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038 
00039 =========================================================================*/
00058 #ifndef __vtkTimerLog_h
00059 #define __vtkTimerLog_h
00060 
00061 #include "vtkSystemIncludes.h"
00062 
00063 #ifdef _WIN32
00064 #include <sys/types.h>
00065 #include <sys/timeb.h>
00066 #else
00067 #include <time.h>
00068 #include <sys/time.h>
00069 #include <sys/types.h>
00070 #include <sys/times.h>
00071 #endif
00072 
00073 // var args
00074 #ifndef _WIN32
00075 #include <unistd.h>
00076 #endif
00077 #include <stdarg.h>
00078 
00079 // select stuff here is for sleep method
00080 #ifndef NO_FD_SET
00081 #   define SELECT_MASK fd_set
00082 #else
00083 #   ifndef _AIX
00084    typedef long fd_mask;
00085 #   endif
00086 #   if defined(_IBMR2)
00087 #  define SELECT_MASK void
00088 #   else
00089 #  define SELECT_MASK int
00090 #   endif
00091 #endif
00092 
00093 
00094 #include "vtkObject.h"
00095 #define VTK_LOG_EVENT_LENGTH 40
00096 
00097 //BTX
00098 typedef struct
00099 {
00100   float WallTime;
00101   int CpuTicks;
00102   char Event[VTK_LOG_EVENT_LENGTH];
00103 } vtkTimerLogEntry;
00104 //ETX
00105 
00106 // The microsoft compiler defines this as a macro, so
00107 // undefine it here
00108 #undef GetCurrentTime
00109 
00110 class VTK_EXPORT vtkTimerLog : public vtkObject 
00111 {
00112 public:
00113   static vtkTimerLog *New();
00114 
00115   vtkTypeMacro(vtkTimerLog,vtkObject);
00116   void PrintSelf(ostream& os, vtkIndent indent);
00117 
00119   static void SetMaxEntries(int a);
00120   static int  GetMaxEntries();
00121 
00122 //BTX
00125   static void FormatAndMarkEvent(char *EventString, ...);
00126 //ETX
00127   
00130   static void DumpLog(char *filename);
00131 
00133   static void MarkEvent(char *EventString);
00134 
00137   static void ResetLog();
00138 
00140   static void AllocateLog();
00141 
00144   static double GetCurrentTime();
00145 
00148   static double GetCPUTime();
00149 
00151   void StartTimer();
00152 
00154   void StopTimer();
00155 
00158   double GetElapsedTime();
00159 
00160 protected:
00161   vtkTimerLog() {}; //insure constructor/destructor protected
00162   ~vtkTimerLog() {};
00163   vtkTimerLog(const vtkTimerLog&) {};
00164   void operator=(const vtkTimerLog&) {};
00165 
00166   static int               MaxEntries;
00167   static int               NextEntry;
00168   static int               WrapFlag;
00169   static int               TicksPerSecond;
00170   static vtkTimerLogEntry *TimerLog;
00171 
00172 #ifdef _WIN32
00173   static timeb             FirstWallTime;
00174   static timeb             CurrentWallTime;
00175 #else
00176   static timeval           FirstWallTime;
00177   static timeval           CurrentWallTime;
00178   static tms               FirstCpuTicks;
00179   static tms               CurrentCpuTicks;
00180 #endif
00181 
00182   // instance variables to support simple timing functionality,
00183   // separate from timer table logging.
00184   double StartTime;
00185   double EndTime;
00186 
00187   //BTX
00188   static void DumpEntry(ostream& os, int index, float time, float deltatime,
00189                         int tick, int deltatick, char *event);
00190   //ETX
00191 
00192 };
00193 
00194 
00195 //
00196 // Set built-in type.  Creates member Set"name"() (e.g., SetVisibility());
00197 //
00198 #define vtkTimerLogMacro(string) \
00199   { \
00200       vtkTimerLog::FormatAndMarkEvent("Mark: In %s, line %d, class %s: %s", \
00201                __FILE__, __LINE__, this->GetClassName(), string); \
00202   }
00203 
00204 #endif

Generated on Wed Nov 21 12:26:54 2001 for VTK by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001