OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / I686LINUX / util / I686LINUX / include / vtk / vtkTimerLog.h
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    $RCSfile: vtkTimerLog.h,v $
5   Language:  C++
6   Date:      $Date: 2002/12/26 18:24:22 $
7   Version:   $Revision: 1.39 $
8
9   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
10   All rights reserved.
11   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
12
13      This software is distributed WITHOUT ANY WARRANTY; without even 
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15      PURPOSE.  See the above copyright notice for more information.
16
17 =========================================================================*/
18 // .NAME vtkTimerLog - Timer support and logging
19 // .SECTION Description
20 // vtkTimerLog contains walltime and cputime measurements associated
21 // with a given event.  These results can be later analyzed when
22 // "dumping out" the table.
23 //
24 // In addition, vtkTimerLog allows the user to simply get the current
25 // time, and to start/stop a simple timer separate from the timing
26 // table logging.
27
28 #ifndef __vtkTimerLog_h
29 #define __vtkTimerLog_h
30
31 #include "vtkObject.h"
32
33 #ifdef _WIN32
34 #ifndef _WIN32_WCE
35 #include <sys/types.h> // Needed for Win32 implementation of timer
36 #include <sys/timeb.h> // Needed for Win32 implementation of timer
37 #endif
38 #else
39 #include <time.h>      // Needed for unix implementation of timer
40 #include <sys/time.h>  // Needed for unix implementation of timer
41 #include <sys/types.h> // Needed for unix implementation of timer
42 #include <sys/times.h> // Needed for unix implementation of timer
43 #endif
44
45 // var args
46 #ifndef _WIN32
47 #include <unistd.h>    // Needed for unix implementation of timer
48 #endif
49
50 // select stuff here is for sleep method
51 #ifndef NO_FD_SET
52 #   define SELECT_MASK fd_set
53 #else
54 #   ifndef _AIX
55         typedef long fd_mask;
56 #   endif
57 #   if defined(_IBMR2)
58 #       define SELECT_MASK void
59 #   else
60 #       define SELECT_MASK int
61 #   endif
62 #endif
63
64
65 #define VTK_LOG_EVENT_LENGTH 40
66
67 //BTX
68 typedef struct
69 {
70   float WallTime;
71   int CpuTicks;
72   char Event[VTK_LOG_EVENT_LENGTH];
73   unsigned char Indent;
74 } vtkTimerLogEntry;
75 //ETX
76
77 // The microsoft compiler defines this as a macro, so
78 // undefine it here
79 #undef GetCurrentTime
80
81 class VTK_COMMON_EXPORT vtkTimerLog : public vtkObject 
82 {
83 public:
84   static vtkTimerLog *New();
85
86   vtkTypeRevisionMacro(vtkTimerLog,vtkObject);
87   void PrintSelf(ostream& os, vtkIndent indent);
88
89   // Description:
90   // This flag will turn loging of events off or on.  
91   // By default, logging is on.
92   static void SetLogging(int v) {vtkTimerLog::Logging = v;}
93   static int GetLogging() {return vtkTimerLog::Logging;}
94   static void LoggingOn() {vtkTimerLog::SetLogging(1);}
95   static void LoggingOff() {vtkTimerLog::SetLogging(0);}
96
97   // Description:
98   // Set/Get the maximum number of entries allowed in the timer log
99   static void SetMaxEntries(int a);
100   static int  GetMaxEntries();
101
102 //BTX
103   // Description:
104   // Record a timing event.  The event is represented by a formatted
105   // string.
106   static void FormatAndMarkEvent(const char *EventString, ...);
107 //ETX
108   
109   // Description:
110   // Write the timing table out to a file.  Calculate some helpful
111   // statistics (deltas and  percentages) in the process.
112   static void DumpLog(const char *filename);
113
114   // Description:
115   // I want to time events, so I am creating this interface to
116   // mark events that have a start and an end.  These events can be,
117   // nested. The standard Dumplog ignores the indents.
118   static void MarkStartEvent(const char *EventString);
119   static void MarkEndEvent(const char *EventString);
120 //BTX
121   static void DumpLogWithIndents(ostream *os, float threshold);
122 //ETX
123
124   // Description:
125   // Programatic access to events.  Indexed from 0 to num-1.
126   static int GetNumberOfEvents();
127   static int GetEventIndent(int i);
128   static float GetEventWallTime(int i);
129   static const char* GetEventString(int i);
130
131   // Description:
132   // Record a timing event and capture wall time and cpu ticks.
133   static void MarkEvent(const char *EventString);
134
135   // Description:
136   // Clear the timing table.  walltime and cputime will also be set
137   // to zero when the first new event is recorded.
138   static void ResetLog();
139
140   // Description:
141   // Allocate timing table with MaxEntries elements.
142   static void AllocateLog();
143
144   // Description:
145   // Returns the elapsed number of seconds since January 1, 1970. This
146   // is also called Universal Coordinated Time.
147   static double GetCurrentTime();
148
149   // Description:
150   // Returns the CPU time for this process
151   // On Win32 platforms this actually returns wall time.
152   static double GetCPUTime();
153
154   // Description:
155   // Set the StartTime to the current time. Used with GetElapsedTime().
156   void StartTimer();
157
158   // Description:
159   // Sets EndTime to the current time. Used with GetElapsedTime().
160   void StopTimer();
161
162   // Description:
163   // Returns the difference between StartTime and EndTime as 
164   // a floating point value indicating the elapsed time in seconds.
165   double GetElapsedTime();
166
167 protected:
168   vtkTimerLog() {this->StartTime=0; this->EndTime = 0;}; //insure constructor/destructor protected
169   ~vtkTimerLog() {};
170
171   static vtkTimerLogEntry* GetEvent(int i);
172
173   static int               Logging;
174   static int               Indent;
175   static int               MaxEntries;
176   static int               NextEntry;
177   static int               WrapFlag;
178   static int               TicksPerSecond;
179   static vtkTimerLogEntry *TimerLog;
180
181 #ifdef _WIN32
182 #ifndef _WIN32_WCE
183   static timeb             FirstWallTime;
184   static timeb             CurrentWallTime;
185 #else
186   static FILETIME FirstWallTime;
187   static FILETIME CurrentWallTime;
188 #endif
189 #else
190   static timeval           FirstWallTime;
191   static timeval           CurrentWallTime;
192   static tms               FirstCpuTicks;
193   static tms               CurrentCpuTicks;
194 #endif
195
196   // instance variables to support simple timing functionality,
197   // separate from timer table logging.
198   double StartTime;
199   double EndTime;
200
201   //BTX
202   static void DumpEntry(ostream& os, int index, float time, float deltatime,
203                         int tick, int deltatick, const char *event);
204   //ETX
205
206 private:
207   vtkTimerLog(const vtkTimerLog&);  // Not implemented.
208   void operator=(const vtkTimerLog&);  // Not implemented.
209 };
210
211
212 //
213 // Set built-in type.  Creates member Set"name"() (e.g., SetVisibility());
214 //
215 #define vtkTimerLogMacro(string) \
216   { \
217       vtkTimerLog::FormatAndMarkEvent("Mark: In %s, line %d, class %s: %s", \
218                               __FILE__, __LINE__, this->GetClassName(), string); \
219   }
220
221 #endif