00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __GZ_PERFORMANCE_H__
00022 #define __GZ_PERFORMANCE_H__
00023
00031 #include "gzBase.h"
00032 #include "gzThread.h"
00033 #include "gzReference.h"
00034
00035 enum gzPerformanceDumpFlags
00036 {
00037 GZ_PERF_DUMP_RUNNING = (1<<0),
00038 GZ_PERF_DUMP_STOPPED = (1<<1),
00039 GZ_PERF_DUMP_ACCUMULATED_SECTIONS = (1<<2),
00040 GZ_PERF_DUMP_HIERARCHICAL_SECTIONS = (1<<3),
00041 GZ_PERF_DUMP_ALL = 0xFFFFFFFFUL,
00042 };
00043
00044 GZ_USE_BIT_LOGIC(gzPerformanceDumpFlags);
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 class GZ_BASE_EXPORT gzSectionResult
00061 {
00062 public:
00063
00064 gzULong iterations;
00065 gzULong recursive;
00066
00067 gzDouble execTotTime;
00068 gzDouble execSelfTime;
00069 gzDouble execParentTime;
00070
00071 gzDouble execTotPercentage;
00072 gzDouble execSelfPercentage;
00073 gzDouble execParentPercentage;
00074
00075 gzULong callers;
00076 };
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 class GZ_BASE_EXPORT gzSectionInfo : public gzReference
00093 {
00094 public:
00095
00096 gzSectionInfo(const gzString &name, gzULong treadID);
00097 virtual ~gzSectionInfo(){};
00098
00099 gzString sectionName;
00100 gzULong threadID;
00101 };
00102
00103 GZ_BASE_EXPORT gzVoid gzEnterPerformanceSection(const gzString & sectionName);
00104
00105 GZ_BASE_EXPORT gzVoid gzLeavePerformanceSection();
00106
00107 GZ_BASE_EXPORT gzVoid gzStartPerformanceThread();
00108
00109 GZ_BASE_EXPORT gzVoid gzStopPerformanceThread();
00110
00111 GZ_BASE_EXPORT gzVoid gzEnablePerformanceSections(gzBool on=TRUE);
00112
00113 GZ_BASE_EXPORT gzVoid gzDumpPerformanceInfo(gzPerformanceDumpFlags dumpFlags=GZ_PERF_DUMP_ALL);
00114
00115 GZ_BASE_EXPORT gzString gzCreatePerfLineInfo(const char *file,gzULong line);
00116
00117 GZ_BASE_EXPORT gzSectionResult gzGetSectionResult(const gzString §ionName,gzULong threadID=gzThread::getThreadID());
00118
00119 GZ_BASE_EXPORT gzVoid gzGetAllPerformanceSections(gzRefList<gzSectionInfo> &perfSecList,gzULong threadID=gzThread::getThreadID());
00120
00121 GZ_BASE_EXPORT gzVoid gzClearPerformanceSection(const gzString &name=GZ_EMPTY_STRING,gzULong threadID=gzThread::getThreadID());
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 class GZ_BASE_EXPORT gzPerformanceBody
00139 {
00140 public:
00141 gzPerformanceBody(const gzString §ionName)
00142 {
00143 gzEnterPerformanceSection(sectionName);
00144 }
00145
00146 virtual ~gzPerformanceBody()
00147 {
00148 gzLeavePerformanceSection();
00149 }
00150
00151 private:
00152
00153 gzPerformanceBody( const gzPerformanceBody ©){}
00154
00155 gzPerformanceBody & operator=(const gzPerformanceBody ©){ return *this; }
00156 };
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172 class GZ_BASE_EXPORT gzPerformanceMonitorInterface
00173 {
00174 public:
00175
00176 virtual gzVoid enter(const gzString &monitor)=0;
00177 virtual gzVoid leave(const gzString &monitor)=0;
00178 virtual gzVoid addValue(const gzString &monitor,const gzDouble &value,const gzDouble *time)=0;
00179
00180 static gzVoid setPerformanceMonitor(gzPerformanceMonitorInterface *monitor);
00181 };
00182
00183 GZ_BASE_EXPORT gzVoid gzEnterMonitor(const gzString & monitor);
00184 GZ_BASE_EXPORT gzVoid gzLeaveMonitor(const gzString & monitor);
00185 GZ_BASE_EXPORT gzVoid gzAddMonitorValue(const gzString & monitor,const gzDouble &value,const gzDouble *time=NULL);
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202 class GZ_BASE_EXPORT gzMonitorBody
00203 {
00204 public:
00205 gzMonitorBody(const gzString &monitor):m_name(monitor)
00206 {
00207 gzEnterMonitor(monitor);
00208 }
00209
00210 virtual ~gzMonitorBody()
00211 {
00212 gzLeaveMonitor(m_name);
00213 }
00214
00215 private:
00216
00217 gzMonitorBody( const gzMonitorBody ©){}
00218
00219 gzMonitorBody & operator=(const gzMonitorBody ©){ return *this; }
00220
00221 gzString m_name;
00222 };
00223
00225
00226 #if defined GZ_INSTRUMENT_CODE
00227
00228 #define GZ_INSTRUMENT_AUTO gzPerformanceBody _instrument_(gzCreatePerfLineInfo(__FILE__,__LINE__))
00229 #define GZ_INSTRUMENT_NAME(x) gzPerformanceBody _instrument_(x)
00230 #define GZ_ENTER_PERFORMANCE_SECTION(x) gzEnterPerformanceSection(x)
00231 #define GZ_LEAVE_PERFORMANCE_SECTION gzLeavePerformanceSection()
00232
00233 #define GZ_MONITOR_AUTO gzMonitorBody _instrument_(gzCreatePerfLineInfo(__FILE__,__LINE__))
00234 #define GZ_MONITOR_NAME(x) gzMonitorBody _instrument_(x)
00235 #define GZ_ENTER_MONITOR(x) gzEnterMonitor(x)
00236 #define GZ_LEAVE_MONITOR(x) gzLeaveMonitor(x)
00237 #define GZ_ADD_MONITOR_VALUE(x,y) gzAddMonitorValue(x,y)
00238
00239 #else
00240
00241 #define GZ_INSTRUMENT_AUTO
00242 #define GZ_INSTRUMENT_NAME(x)
00243 #define GZ_ENTER_PERFORMANCE_SECTION(x)
00244 #define GZ_LEAVE_PERFORMANCE_SECTION
00245
00246 #define GZ_MONITOR_AUTO
00247 #define GZ_MONITOR_NAME(x)
00248 #define GZ_ENTER_MONITOR(x)
00249 #define GZ_LEAVE_MONITOR(x)
00250 #define GZ_ADD_MONITOR_VALUE(x,y)
00251
00252 #endif
00253
00254 #endif // __GZ_PERFORMANCE_H__