Gizmo3D

gzPerformance.h

Go to the documentation of this file.
00001 //*****************************************************************************
00002 // File         : gzPerformance.h
00003 // Module       : gzBase
00004 // Description  : Class definition of performance measure functionality
00005 // Author       : Anders Modén      
00006 // Product      : GizmoBase 2.1.1
00007 //      
00008 // Copyright © 2003- Saab Training System AB, Sweden
00009 //          
00010 // NOTE:    GizmoBase is a platform abstraction utility layer for C++. It contains 
00011 //          design patterns and C++ solutions for the advanced programmer.
00012 //
00013 //
00014 // Revision History...                          
00015 //                                  
00016 // Who  Date    Description                     
00017 //                                  
00018 // AMO  030612  Created file    
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 // Class    : gzSectionResult
00048 //                                  
00049 // Purpose  : Structure to keep result data of a performance section
00050 //                                  
00051 // Notes    : - 
00052 //                                  
00053 // Revision History...                          
00054 //                                  
00055 // Who  Date    Description                     
00056 //                                  
00057 // AMO  030623  Created 
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 // Class    : gzSectionInfo
00080 //                                  
00081 // Purpose  : Structure to keep name and thread info of sections
00082 //                                  
00083 // Notes    : - 
00084 //                                  
00085 // Revision History...                          
00086 //                                  
00087 // Who  Date    Description                     
00088 //                                  
00089 // AMO  050209  Created 
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 &sectionName,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 // Class    : gzPerformanceBody
00126 //                                  
00127 // Purpose  : Class to manage section enter/exit code
00128 //                                  
00129 // Notes    : - 
00130 //                                  
00131 // Revision History...                          
00132 //                                  
00133 // Who  Date    Description                     
00134 //                                  
00135 // AMO  030623  Created 
00136 //                                  
00137 //******************************************************************************
00138 class GZ_BASE_EXPORT gzPerformanceBody 
00139 {
00140 public:
00141     gzPerformanceBody(const gzString &sectionName)
00142     {
00143         gzEnterPerformanceSection(sectionName);
00144     }
00145 
00146     virtual ~gzPerformanceBody()
00147     { 
00148         gzLeavePerformanceSection();
00149     }
00150 
00151 private:    // Do not allow copy or assignments
00152 
00153     gzPerformanceBody( const gzPerformanceBody &copy){}
00154 
00155     gzPerformanceBody & operator=(const gzPerformanceBody &copy){ return *this; }
00156 };
00157 
00158 //******************************************************************************
00159 // Class    : gzPerformanceMonitorInterface
00160 //                                  
00161 // Purpose  : Interface to external monitor
00162 //                                  
00163 // Notes    : - 
00164 //                                  
00165 // Revision History...                          
00166 //                                  
00167 // Who  Date    Description                     
00168 //                                  
00169 // AMO  030623  Created 
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 // Class    : gzMonitorBody
00190 //                                  
00191 // Purpose  : Class to manage section enter/exit code
00192 //                                  
00193 // Notes    : - 
00194 //                                  
00195 // Revision History...                          
00196 //                                  
00197 // Who  Date    Description                     
00198 //                                  
00199 // AMO  030623  Created 
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:    // Do not allow copy or assignments
00216 
00217     gzMonitorBody( const gzMonitorBody &copy){}
00218 
00219     gzMonitorBody & operator=(const gzMonitorBody &copy){ 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__

Documentation for Gizmo3D generated at Wed Feb 20 11:54:07 2008 by   Saab Training Systems AB, ¸ (c) 2003-and beyond