00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00037
#ifndef __vtkTimerLog_h
00038
#define __vtkTimerLog_h
00039
00040
#include "vtkObject.h"
00041
00042
#ifdef _WIN32
00043
#ifndef _WIN32_WCE
00044
#include <sys/types.h>
00045
#include <sys/timeb.h>
00046
#endif
00047
#else
00048
#include <time.h>
00049
#include <sys/time.h>
00050
#include <sys/types.h>
00051
#include <sys/times.h>
00052
#endif
00053
00054
00055
#ifndef _WIN32
00056
#include <unistd.h>
00057
#endif
00058
00059
00060
#ifndef NO_FD_SET
00061 # define SELECT_MASK fd_set
00062
#else
00063
# ifndef _AIX
00064
typedef long fd_mask;
00065
# endif
00066
# if defined(_IBMR2)
00067
# define SELECT_MASK void
00068
# else
00069
# define SELECT_MASK int
00070
# endif
00071
#endif
00072
00073
00074 #define VTK_LOG_EVENT_LENGTH 40
00075
00076
00077 typedef struct
00078
{
00079 float WallTime;
00080 int CpuTicks;
00081 char Event[
VTK_LOG_EVENT_LENGTH];
00082 unsigned char Indent;
00083 }
vtkTimerLogEntry;
00084
00085
00086
00087
00088
#undef GetCurrentTime
00089
00090 class VTK_COMMON_EXPORT vtkTimerLog :
public vtkObject
00091 {
00092
public:
00093
static vtkTimerLog *
New();
00094
00095 vtkTypeRevisionMacro(vtkTimerLog,
vtkObject);
00096
void PrintSelf(ostream& os,
vtkIndent indent);
00097
00099
00101 static void SetLogging(
int v) {
vtkTimerLog::Logging = v;}
00102 static int GetLogging() {
return vtkTimerLog::Logging;}
00103 static void LoggingOn() {
vtkTimerLog::SetLogging(1);}
00104 static void LoggingOff() {
vtkTimerLog::SetLogging(0);}
00106
00108
00109
static void SetMaxEntries(
int a);
00110
static int GetMaxEntries();
00112
00113
00116
static void FormatAndMarkEvent(
const char *EventString, ...);
00117
00118
00121
static void DumpLog(
const char *filename);
00122
00124
00127
static void MarkStartEvent(
const char *EventString);
00128
static void MarkEndEvent(
const char *EventString);
00130
00131
static void DumpLogWithIndents(ostream *os,
float threshold);
00132
00133
00135
00136
static int GetNumberOfEvents();
00137
static int GetEventIndent(
int i);
00138
static float GetEventWallTime(
int i);
00139
static const char* GetEventString(
int i);
00141
00143
static void MarkEvent(
const char *EventString);
00144
00147
static void ResetLog();
00148
00150
static void AllocateLog();
00151
00154
static double GetCurrentTime();
00155
00158
static double GetCPUTime();
00159
00161
void StartTimer();
00162
00164
void StopTimer();
00165
00168
double GetElapsedTime();
00169
00170
protected:
00171 vtkTimerLog() {this->StartTime=0; this->EndTime = 0;};
00172 ~vtkTimerLog() {};
00173
00174
static vtkTimerLogEntry* GetEvent(
int i);
00175
00176 static int Logging;
00177 static int Indent;
00178 static int MaxEntries;
00179 static int NextEntry;
00180 static int WrapFlag;
00181 static int TicksPerSecond;
00182 static vtkTimerLogEntry *TimerLog;
00183
00184
#ifdef _WIN32
00185
#ifndef _WIN32_WCE
00186
static timeb FirstWallTime;
00187
static timeb CurrentWallTime;
00188
#else
00189
static FILETIME FirstWallTime;
00190
static FILETIME CurrentWallTime;
00191
#endif
00192
#else
00193 static timeval FirstWallTime;
00194 static timeval CurrentWallTime;
00195 static tms FirstCpuTicks;
00196 static tms CurrentCpuTicks;
00197
#endif
00198
00199
00200
00201 double StartTime;
00202 double EndTime;
00203
00204
00205
static void DumpEntry(ostream& os,
int index,
float time,
float deltatime,
00206
int tick,
int deltatick,
const char *event);
00207
00208
00209
private:
00210 vtkTimerLog(
const vtkTimerLog&);
00211
void operator=(
const vtkTimerLog&);
00212 };
00213
00214
00215
00216
00217
00218 #define vtkTimerLogMacro(string) \
00219
{ \
00220
vtkTimerLog::FormatAndMarkEvent("Mark: In %s, line %d, class %s: %s", \
00221
__FILE__, __LINE__, this->GetClassName(), string); \
00222
}
00223
00224
#endif