00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __UT_Performance__
00022 #define __UT_Performance__
00023
00024 #include "UT_API.h"
00025 #include <SYS/SYS_Time.h>
00026 #include "UT_PtrArray.h"
00027 #include "UT_FloatArray.h"
00028
00029 enum {
00030 LOG_OFF = 0,
00031 LOG_WINDOW,
00032 LOG_STDOUT
00033 };
00034
00035 enum {
00036 TIME_FORMAT_ALL = 0,
00037 TIME_FORMAT_MS,
00038 TIME_FORMAT_SEC
00039 };
00040
00041 enum {
00042 PERFORMANCE_WINDOW_LOG = 0,
00043 PERFORMANCE_ENDFRAME = 1,
00044 PERFORMANCE_WINDOW_LOG_HIGH = 2
00045 };
00046
00047 enum UT_PerformanceFilter
00048 {
00049 UT_PERF_FILTER_OFF,
00050 UT_PERF_FILTER_HIGHLIGHT,
00051 UT_PERF_FILTER_HIDE
00052 };
00053
00054 typedef void (*UT_PerformanceCB)(int type, void *data, const char *msg,
00055 int refresh);
00056
00057 class utPerfEvent;
00058
00059 class UT_API UT_Performance
00060 {
00061 public:
00062 UT_Performance();
00063 ~UT_Performance();
00064
00065 void startEvent(const char *type,
00066 const char *name = 0,
00067 const char *info = 0,
00068 int count = -1);
00069
00070 fpreal stopEvent(int log = 1);
00071 void logMessage(const char *m, int refresh = 1,
00072 fpreal dtime = -1,
00073 const utPerfEvent *event = 0);
00074 void logAccumulatedTime(fpreal time) { myAccumTime += time; }
00075
00076 void filterLog(UT_PerformanceFilter filter,
00077 float time_threshold_ms);
00078
00079 void logEnable(int yesno)
00080 {
00081 if( myLogEnable )
00082 frameComplete(myLastFrame);
00083 myLogEnable = yesno;
00084 myFrameState = 0;
00085 }
00086 int logEnabled() const
00087 { return myLogEnable && myLogType; }
00088
00089 int opTiming() const
00090 {
00091 return
00092 (myOpInfo || myOpHighlight ||
00093 (myLogEnable && myLogType && myLogCookTime));
00094 }
00095
00096 int frameTiming() const
00097 {
00098 return logEnabled() && myLogFLength;
00099 }
00100
00101 void setCallback(UT_PerformanceCB func, void *data)
00102 {
00103 myFunc = func;
00104 myData = data;
00105 }
00106
00107
00108
00109
00110
00111
00112
00113
00114 void frameChange(fpreal frame);
00115
00116
00117 void frameStart(fpreal frame);
00118 void frameComplete(fpreal frame);
00119 fpreal getLastFrame() const { return myLastFrame; }
00120
00121
00122
00123
00124
00125
00126 int opInfo() const { return myOpInfo; }
00127 void opInfo(int yesno) { myOpInfo = yesno; }
00128
00129 int opHighlight() const { return myOpHighlight; }
00130 void opHighlight(int yesno) { myOpHighlight = yesno; }
00131
00132
00133
00134
00135 void startMemoryLog();
00136 void stopMemoryLog(const char *label);
00137
00138
00139
00140
00141
00142 int logType() const { return myLogType; }
00143 void logType(int type);
00144 void logPause(int yesno);
00145 void logSorted(int yesno);
00146
00147 int logTimeFormat() const { return myTimeFormat; }
00148 void logTimeFormat( int format ) { myTimeFormat = format; }
00149
00150 int logCookTime() const
00151 { return logEnabled() && myLogCookTime; }
00152 void logCookTime(int yesno)
00153 { myLogCookTime = yesno; }
00154
00155 bool logSolveTime() const
00156 { return logEnabled() && myLogSolveTime; }
00157 void logSolveTime(bool enable)
00158 { myLogSolveTime = enable; }
00159
00160 int logLongCHOPs() const
00161 { return logEnabled() && myLogLongCHOPs; }
00162 void logLongCHOPs(int yesno)
00163 { myLogLongCHOPs = yesno; }
00164
00165 int logObjectViewTime() const
00166 { return logEnabled() && myLogObjectViewTime; }
00167 void logObjectViewTime(int yesno)
00168 { myLogObjectViewTime = yesno; }
00169
00170 int logViewPortTime() const
00171 { return logEnabled() && myLogViewPortTime; }
00172 void logViewPortTime(int yesno)
00173 { myLogViewPortTime = yesno; }
00174
00175 int logFLength() const
00176 { return logEnabled() && myLogFLength; }
00177 void logFLength(int yesno)
00178 { myLogFLength = yesno; }
00179
00180 int logMemory() const
00181 { return logEnabled() && myLogMemory; }
00182 void logMemory(int yesno)
00183 { myLogMemory = yesno; }
00184
00185 int logErrors() const
00186 { return logEnabled() && myLogErrors; }
00187 void logErrors(int yesno)
00188 { myLogErrors = yesno; }
00189
00190 void clearFrameAverage()
00191 { myFrameCount = 0; myFrameTotal = 0.0f; }
00192
00193
00194
00195
00196
00197 static const char *formatTime(fpreal t,
00198 const char *prefix,
00199 const char *suffix = "\n\r",
00200 int format = TIME_FORMAT_ALL);
00201 static const char *formatFrequency(fpreal t, const char *prefix,
00202 const char *suffix = "\n\r");
00203
00204 private:
00205
00206
00207 void logFrameAverage();
00208 void startFrame(fpreal frame);
00209 void endFrame(fpreal dtime);
00210 fpreal elapsedTime(SYS_TimeVal &etime);
00211
00212 int myLogType;
00213 int myTimeFormat;
00214 int myFrameState;
00215
00216 unsigned int myLogEnable : 1,
00217
00218 myOpInfo : 1,
00219 myOpHighlight : 1,
00220
00221 myLogPause : 1,
00222 myLogSorted : 1,
00223 myLogCookTime : 1,
00224 myLogLongCHOPs : 1,
00225 myLogViewPortTime : 1,
00226 myLogObjectViewTime : 1,
00227 myLogFLength : 1,
00228 myLogMemory : 1,
00229 myLogErrors : 1,
00230 myLogSolveTime : 1;
00231
00232 void appendMessage(const char *m, fpreal dtime,
00233 const utPerfEvent *event);
00234
00235 void clearMessages();
00236 void flushMessages();
00237 void clearEvents();
00238
00239
00240 UT_PtrArray<char *> myMessage;
00241 UT_PtrArray<utPerfEvent *> myMessageEvent;
00242 UT_FloatArray myMessageTime;
00243 int myMessageCount;
00244
00245 UT_PerformanceCB myFunc;
00246 void *myData;
00247
00248 float myAccumTime;
00249 SYS_TimeVal myLastTime;
00250
00251 int myFrameCount;
00252 float myFrameTotal;
00253
00254 size_t myMemoryUsage;
00255
00256 UT_PtrArray<utPerfEvent *> myEvents;
00257 int myEventCount;
00258
00259 fpreal myLastFrame;
00260 SYS_TimeVal myStartTime;
00261
00262
00263 bool myTiming;
00264
00265 UT_PerformanceFilter myFilter;
00266 fpreal myFilterThreshold;
00267 int myFilterHiddenEvents;
00268 };
00269
00270 UT_API extern UT_Performance *UTgetPerformance();
00271
00272 #endif
00273