1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: $RCSfile: vtkTimerLog.h,v $
6 Date: $Date: 2002/12/26 18:24:22 $
7 Version: $Revision: 1.39 $
9 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
11 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
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.
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.
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
28 #ifndef __vtkTimerLog_h
29 #define __vtkTimerLog_h
31 #include "vtkObject.h"
35 #include <sys/types.h> // Needed for Win32 implementation of timer
36 #include <sys/timeb.h> // Needed for Win32 implementation of timer
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
47 #include <unistd.h> // Needed for unix implementation of timer
50 // select stuff here is for sleep method
52 # define SELECT_MASK fd_set
58 # define SELECT_MASK void
60 # define SELECT_MASK int
65 #define VTK_LOG_EVENT_LENGTH 40
72 char Event[VTK_LOG_EVENT_LENGTH];
77 // The microsoft compiler defines this as a macro, so
81 class VTK_COMMON_EXPORT vtkTimerLog : public vtkObject
84 static vtkTimerLog *New();
86 vtkTypeRevisionMacro(vtkTimerLog,vtkObject);
87 void PrintSelf(ostream& os, vtkIndent indent);
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);}
98 // Set/Get the maximum number of entries allowed in the timer log
99 static void SetMaxEntries(int a);
100 static int GetMaxEntries();
104 // Record a timing event. The event is represented by a formatted
106 static void FormatAndMarkEvent(const char *EventString, ...);
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);
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);
121 static void DumpLogWithIndents(ostream *os, float threshold);
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);
132 // Record a timing event and capture wall time and cpu ticks.
133 static void MarkEvent(const char *EventString);
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();
141 // Allocate timing table with MaxEntries elements.
142 static void AllocateLog();
145 // Returns the elapsed number of seconds since January 1, 1970. This
146 // is also called Universal Coordinated Time.
147 static double GetCurrentTime();
150 // Returns the CPU time for this process
151 // On Win32 platforms this actually returns wall time.
152 static double GetCPUTime();
155 // Set the StartTime to the current time. Used with GetElapsedTime().
159 // Sets EndTime to the current time. Used with GetElapsedTime().
163 // Returns the difference between StartTime and EndTime as
164 // a floating point value indicating the elapsed time in seconds.
165 double GetElapsedTime();
168 vtkTimerLog() {this->StartTime=0; this->EndTime = 0;}; //insure constructor/destructor protected
171 static vtkTimerLogEntry* GetEvent(int i);
175 static int MaxEntries;
176 static int NextEntry;
178 static int TicksPerSecond;
179 static vtkTimerLogEntry *TimerLog;
183 static timeb FirstWallTime;
184 static timeb CurrentWallTime;
186 static FILETIME FirstWallTime;
187 static FILETIME CurrentWallTime;
190 static timeval FirstWallTime;
191 static timeval CurrentWallTime;
192 static tms FirstCpuTicks;
193 static tms CurrentCpuTicks;
196 // instance variables to support simple timing functionality,
197 // separate from timer table logging.
202 static void DumpEntry(ostream& os, int index, float time, float deltatime,
203 int tick, int deltatick, const char *event);
207 vtkTimerLog(const vtkTimerLog&); // Not implemented.
208 void operator=(const vtkTimerLog&); // Not implemented.
213 // Set built-in type. Creates member Set"name"() (e.g., SetVisibility());
215 #define vtkTimerLogMacro(string) \
217 vtkTimerLog::FormatAndMarkEvent("Mark: In %s, line %d, class %s: %s", \
218 __FILE__, __LINE__, this->GetClassName(), string); \