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 =========================================================================*/
00061 #ifndef __vtkTimerLog_h
00062 #define __vtkTimerLog_h
00063 
00064 #include "vtkSystemIncludes.h"
00065 
00066 #ifdef _WIN32
00067 #include <sys/types.h>
00068 #include <sys/timeb.h>
00069 #else
00070 #include <time.h>
00071 #include <sys/time.h>
00072 #include <sys/types.h>
00073 #include <sys/times.h>
00074 #endif
00075 
00076 // var args
00077 #ifndef _WIN32
00078 #include <unistd.h>
00079 #endif
00080 #include <stdarg.h>
00081 
00082 // select stuff here is for sleep method
00083 #ifndef NO_FD_SET
00084 #   define SELECT_MASK fd_set
00085 #else
00086 #   ifndef _AIX
00087         typedef long fd_mask;
00088 #   endif
00089 #   if defined(_IBMR2)
00090 #       define SELECT_MASK void
00091 #   else
00092 #       define SELECT_MASK int
00093 #   endif
00094 #endif
00095 
00096 
00097 #include "vtkObject.h"
00098 #define VTK_LOG_EVENT_LENGTH 40
00099 
00100 //BTX
00101 typedef struct
00102 {
00103   float WallTime;
00104   int CpuTicks;
00105   char Event[VTK_LOG_EVENT_LENGTH];
00106 } vtkTimerLogEntry;
00107 //ETX
00108 
00109 // The microsoft compiler defines this as a macro, so
00110 // undefine it here
00111 #undef GetCurrentTime
00112 
00113 class VTK_COMMON_EXPORT vtkTimerLog : public vtkObject 
00114 {
00115 public:
00116   static vtkTimerLog *New();
00117 
00118   vtkTypeMacro(vtkTimerLog,vtkObject);
00119   void PrintSelf(ostream& os, vtkIndent indent);
00120 
00122 
00123   static void SetMaxEntries(int a);
00124   static int  GetMaxEntries();
00126 
00127 //BTX
00130   static void FormatAndMarkEvent(char *EventString, ...);
00131 //ETX
00132   
00135   static void DumpLog(char *filename);
00136 
00138   static void MarkEvent(char *EventString);
00139 
00142   static void ResetLog();
00143 
00145   static void AllocateLog();
00146 
00149   static double GetCurrentTime();
00150 
00153   static double GetCPUTime();
00154 
00156   void StartTimer();
00157 
00159   void StopTimer();
00160 
00163   double GetElapsedTime();
00164 
00165 protected:
00166   vtkTimerLog() {this->StartTime=0; this->EndTime = 0;}; //insure constructor/destructor protected
00167   ~vtkTimerLog() {};
00168 
00169   static int               MaxEntries;
00170   static int               NextEntry;
00171   static int               WrapFlag;
00172   static int               TicksPerSecond;
00173   static vtkTimerLogEntry *TimerLog;
00174 
00175 #ifdef _WIN32
00176   static timeb             FirstWallTime;
00177   static timeb             CurrentWallTime;
00178 #else
00179   static timeval           FirstWallTime;
00180   static timeval           CurrentWallTime;
00181   static tms               FirstCpuTicks;
00182   static tms               CurrentCpuTicks;
00183 #endif
00184 
00185   // instance variables to support simple timing functionality,
00186   // separate from timer table logging.
00187   double StartTime;
00188   double EndTime;
00189 
00190   //BTX
00191   static void DumpEntry(ostream& os, int index, float time, float deltatime,
00192                         int tick, int deltatick, char *event);
00193   //ETX
00194 
00195 private:
00196   vtkTimerLog(const vtkTimerLog&);  // Not implemented.
00197   void operator=(const vtkTimerLog&);  // Not implemented.
00198 };
00199 
00200 
00201 //
00202 // Set built-in type.  Creates member Set"name"() (e.g., SetVisibility());
00203 //
00204 #define vtkTimerLogMacro(string) \
00205   { \
00206       vtkTimerLog::FormatAndMarkEvent("Mark: In %s, line %d, class %s: %s", \
00207                               __FILE__, __LINE__, this->GetClassName(), string); \
00208   }
00209 
00210 #endif

Generated on Thu Mar 28 14:19:17 2002 for VTK by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001