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     HFBProfileTaskCycle 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*     GetComment();       
00191     int             GetThreadID();      
00192 
00193     bool            IsSingleEvent();    
00194 private:
00196 
00197     FBProfileTimeEvent();
00199     FBProfileTimeEvent(const FBProfileTimeEvent &);
00201     FBProfileTimeEvent & operator =(const FBProfileTimeEvent &);
00203 };
00204 
00206 enum FBProfilingMode
00207 {
00208     kFBProfilingModeDisabled = 0,   
00209     kFBProfilingModeEvaluation,     
00210     kFBProfilingModeRendering,      
00211     kFBProfilingModeDevices,        
00212     kFBProfilingModeSDK,            
00213     kFBProfilingModeAllLow,         
00214     kFBProfilingModeAllHi           
00215 };
00216 
00217 FB_DEFINE_ENUM(FBSDK_DLL, ProfilingMode);
00218 
00220 // FBProfiler
00222 
00225 class FBSDK_DLL FBProfiler : public FBComponent {
00226     __FBClassDeclare( FBProfiler,FBComponent );
00227 public:
00231     FBProfiler(HIObject pObject=NULL);
00232 
00233     FBPropertyProfilingMode ProfilingMode;      
00234     FBPropertyInt           EvaluationDepth;    
00235     FBPropertyInt           BufferSize;         
00236     FBPropertyBool          FrameReference;     
00237     FBPropertyBool          ActiveSampling;     
00238     
00239     // Event samples.
00243     int                     GetEventSampleCount();
00248     HFBProfileTimeEvent     GetEventSample( int pIndex );
00253     HFBProfileTimeEvent     GetEndEventSample( int pIndex );
00254 
00255     // Stats (for now only IO)
00256     
00260     int                     GetStatCount();
00265     int                     GetStatIndex(const char* pName);
00270     const char*             GetStatName(int pIndex);
00275     const char*             GetStatComment(int pIndex);
00280     double                  GetStatDuration(int pIndex);
00281 
00285     double                  GetProfilingCost();
00286 
00292     static int              RegisterTaskCycle(const char* pUniqueName, float* pColor = NULL);
00293 
00298     static bool             IsTaskCycleNameRegistered(const char* pName);
00299 
00303     static FBProfiler&      TheOne();
00304 };
00305 
00307 // FBProfilerHelper
00309 
00312 class FBSDK_DLL FBProfilerHelper
00313 {
00314 public:
00321     FBProfilerHelper(int pTC_RegisterationIndex, HFBEvaluateInfo pEvaluateInfo, HFBProfileTaskCycle pParentTaskCycle = NULL);
00325     ~FBProfilerHelper();
00326     
00328     void Stop();
00329 
00331     inline bool IsStarted() { return mCurrentTaskCycle != NULL; }
00332 private:
00334     HFBEvaluateInfo     mEvaluateInfo;
00335     HFBProfileTaskCycle mBackupTaskCycle;
00336     HFBProfileTaskCycle mCurrentTaskCycle;
00338 };
00339 
00340 
00342 // GLOBALS, for querying of FBProfileTaskCycle hierarchy or to be used in FBProfilerHelper constructor.
00344 FBSDK_DLL HFBProfileTaskCycle   FBGetMainThreadTaskCycle();     
00345 FBSDK_DLL HFBProfileTaskCycle   FBGetRenderingTaskCycle();      
00346 FBSDK_DLL HFBProfileTaskCycle   FBGetEvaluationTaskCycle();     
00347 
00348 #ifdef FBSDKUseNamespace
00349     }
00350 #endif
00351 
00352 #endif /* __FBPROFILER_H__ */