fbsdk/fbprofiler.h Source File
 
 
 
fbsdk/fbprofiler.h
Go to the documentation of this file.
00001 #ifndef __FBPROFILER_H__
00002 #define __FBPROFILER_H__
00003 /**************************************************************************
00004  Copyright (c) 1994 - 2009 Autodesk, Inc. and/or its licensors.
00005  All Rights Reserved.
00006  
00007  The coded instructions, statements, computer programs, and/or related 
00008  material (collectively the "Data") in these files contain unpublished 
00009  information proprietary to Autodesk, Inc. and/or its licensors, which is 
00010  protected by Canada and United States of America federal copyright law 
00011  and by international treaties.
00012  
00013  The Data may not be disclosed or distributed to third parties, in whole 
00014  or in part, without the prior written consent of Autodesk, Inc. 
00015  ("Autodesk").
00016  
00017  THE DATA IS PROVIDED "AS IS" AND WITHOUT WARRANTY.
00018  ALL WARRANTIES ARE EXPRESSLY EXCLUDED AND DISCLAIMED. AUTODESK MAKES NO 
00019  WARRANTY OF ANY KIND WITH RESPECT TO THE DATA, EXPRESS, IMPLIED OR 
00020  ARISING BY CUSTOM OR TRADE USAGE, AND DISCLAIMS ANY IMPLIED WARRANTIES 
00021  OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR 
00022  PURPOSE OR USE. WITHOUT LIMITING THE FOREGOING, AUTODESK DOES NOT 
00023  WARRANT THAT THE OPERATION OF THE DATA WILL BE UNINTERRUPTED OR ERROR 
00024  FREE.
00025  
00026  IN NO EVENT SHALL AUTODESK, ITS AFFILIATES, PARENT COMPANIES, LICENSORS 
00027  OR SUPPLIERS ("AUTODESK GROUP") BE LIABLE FOR ANY LOSSES, DAMAGES OR 
00028  EXPENSES OF ANY KIND (INCLUDING WITHOUT LIMITATION PUNITIVE OR MULTIPLE 
00029  DAMAGES OR OTHER SPECIAL, DIRECT, INDIRECT, EXEMPLARY, INCIDENTAL, LOSS 
00030  OF PROFITS, REVENUE OR DATA, COST OF COVER OR CONSEQUENTIAL LOSSES OR 
00031  DAMAGES OF ANY KIND), HOWEVER CAUSED, AND REGARDLESS OF THE THEORY OF 
00032  LIABILITY, WHETHER DERIVED FROM CONTRACT, TORT (INCLUDING, BUT NOT 
00033  LIMITED TO, NEGLIGENCE), OR OTHERWISE, ARISING OUT OF OR RELATING TO THE 
00034  DATA OR ITS USE OR ANY OTHER PERFORMANCE, WHETHER OR NOT AUTODESK HAS 
00035  BEEN ADVISED OF THE POSSIBILITY OF SUCH LOSS OR DAMAGE.
00036  
00037 **************************************************************************/
00038 
00039 #include <kaydaradef.h>
00040 #ifndef FBSDK_DLL 
00041 
00044         #define FBSDK_DLL K_DLLIMPORT
00045 #endif
00046 
00047 #include <fbsdk/fbcomponent.h>
00048 #include <fbsdk/fbcore.h>
00049 
00050 #ifdef FBSDKUseNamespace
00051         namespace FBSDKNamespace {
00052 #endif
00053 
00060 #define FBProfiler_CreateTaskCycle( pClass, pR, pG, pB ) \
00061     int gProfilingIndex_##pClass = -1; \
00062     float gProfilingColor_##pClass[3] = { pR, pG, pB };
00063 
00069 #define FBProfiling_SetupTaskCycle( pClass ) \
00070     if(gProfilingIndex_##pClass == -1) \
00071                 gProfilingIndex_##pClass = FBProfiler::TheOne().RegisterTaskCycle(#pClass,gProfilingColor_##pClass);
00072 
00078 #define FBProfiling_TaskCycleIndex( pClass ) \
00079         gProfilingIndex_##pClass
00080 
00082 __FB_FORWARD(FBProfiler);
00083 FB_FORWARD(FBProfileTaskCycle);
00084 __FB_FORWARD(FBProfileTimeEvent);
00085 FB_FORWARD(FBEvaluateInfo);
00086 FB_FORWARD(FBProfilerHelper);
00087 
00128 class FBSDK_DLL FBProfileTaskCycle 
00129 {
00130 public:
00131         int                             GetIndex();             
00132         const char*             GetName();              
00133         const float*    GetColor();             
00134 
00141         void                    GetAvgMinMaxUsage(double& pAvg, double& pMin, double& pMax);
00142 
00143         // Sampling.
00144         void                    Start();                
00145         void                    Stop();                 
00146         bool                    IsStarted();    
00147         
00153         int                             GetChildCount();
00154         
00160         FBProfileTaskCycle*     GetChild(int pIndex);
00161 private:
00163 
00164         FBProfileTaskCycle();
00166         FBProfileTaskCycle(const FBProfileTaskCycle &);
00168         FBProfileTaskCycle & operator =(const FBProfileTaskCycle &);
00170 };
00171 
00173 // FBProfileTimeEvent
00175 
00184 class FBSDK_DLL FBProfileTimeEvent
00185 {
00186 public:
00187         FBTime                  GetTime();                      
00188         const float*    GetColor();                     
00189         
00190         const char*             GetTypeName();          
00191         const char*             GetComment();           
00192         int                             GetThreadID();          
00193 
00194         bool                    IsSingleEvent();        
00195 private:
00197 
00198         FBProfileTimeEvent();
00200         FBProfileTimeEvent(const FBProfileTimeEvent &);
00202         FBProfileTimeEvent & operator =(const FBProfileTimeEvent &);
00204 };
00205 
00207 enum FBProfilingMode
00208 {
00209         kFBProfilingModeDisabled = 0,   
00210         kFBProfilingModeEvaluation,             
00211     kFBProfilingModeRendering,          
00212     kFBProfilingModeDevices,            
00213     kFBProfilingModeSDK,                        
00214     kFBProfilingModeAllLow,                     
00215     kFBProfilingModeAllHi                       
00216 };
00217 
00218 FB_DEFINE_ENUM(FBSDK_DLL, ProfilingMode);
00219 
00221 // FBProfiler
00223 
00226 class FBSDK_DLL FBProfiler : public FBComponent {
00227         __FBClassDeclare( FBProfiler,FBComponent );
00228 public:
00232         FBProfiler(HIObject pObject=NULL);
00233 
00234         FBPropertyProfilingMode ProfilingMode;          
00235         FBPropertyInt                   EvaluationDepth;        
00236         FBPropertyInt                   BufferSize;                     
00237         FBPropertyBool                  FrameReference;         
00238         FBPropertyBool                  ActiveSampling;         
00239         
00240         // Event samples.
00244         int                                             GetEventSampleCount();
00249         FBProfileTimeEvent*             GetEventSample( int pIndex );
00254         FBProfileTimeEvent*             GetEndEventSample( int pIndex );
00255 
00256         // Stats (for now only IO)
00257         
00261         int                                             GetStatCount();
00266         int                                             GetStatIndex(const char* pName);
00271         const char*                             GetStatName(int pIndex);
00276         const char*                             GetStatComment(int pIndex);
00277 
00282         double                                  GetStatStart(int pIndex);
00283 
00288         double                                  GetStatStop(int pIndex);
00289 
00294         double                                  GetStatDuration(int pIndex);
00295 
00299         double                                  GetProfilingCost();
00300 
00306         static int                              RegisterTaskCycle(const char* pUniqueName, float* pColor = NULL);
00307 
00312         static bool                             IsTaskCycleNameRegistered(const char* pName);
00313 
00317         static FBProfiler&              TheOne();
00318 };
00319 
00321 // FBProfilerHelper
00323 
00326 class FBSDK_DLL FBProfilerHelper
00327 {
00328 public:
00335         FBProfilerHelper(int pTC_RegisterationIndex, FBEvaluateInfo* pEvaluateInfo, FBProfileTaskCycle* pParentTaskCycle = NULL);
00339         ~FBProfilerHelper();
00340         
00342         void Stop();
00343 
00345         inline bool IsStarted() { return mCurrentTaskCycle != NULL; }
00346 private:
00348         FBEvaluateInfo*         mEvaluateInfo;
00349         FBProfileTaskCycle*     mBackupTaskCycle;
00350         FBProfileTaskCycle*     mCurrentTaskCycle;
00352 };
00353 
00354 
00356 // GLOBALS, for querying of FBProfileTaskCycle hierarchy or to be used in FBProfilerHelper constructor.
00358 FBSDK_DLL FBProfileTaskCycle*   FBGetMainThreadTaskCycle();             
00359 FBSDK_DLL FBProfileTaskCycle*   FBGetRenderingTaskCycle();              
00360 FBSDK_DLL FBProfileTaskCycle*   FBGetEvaluationTaskCycle();             
00361 
00362 #ifdef FBSDKUseNamespace
00363         }
00364 #endif
00365 
00366 #endif /* __FBPROFILER_H__ */