00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright (c) 2000-2006 Torus Knot Software Ltd 00008 Also see acknowledgements in Readme.html 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU Lesser General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/lesser.txt. 00023 00024 You may alternatively use this source under the terms of a specific version of 00025 the OGRE Unrestricted License provided you have obtained such a license from 00026 Torus Knot Software Ltd. 00027 ----------------------------------------------------------------------------- 00028 */ 00029 /* 00030 00031 Although the code is original, many of the ideas for the profiler were borrowed from 00032 "Real-Time In-Game Profiling" by Steve Rabin which can be found in Game Programming 00033 Gems 1. 00034 00035 This code can easily be adapted to your own non-Ogre project. The only code that is 00036 Ogre-dependent is in the visualization/logging routines and the use of the Timer class. 00037 00038 Enjoy! 00039 00040 */ 00041 00042 #ifndef __Profiler_H__ 00043 #define __Profiler_H__ 00044 00045 #include "OgrePrerequisites.h" 00046 #include "OgreSingleton.h" 00047 #include "OgreString.h" 00048 #include "OgreOverlay.h" 00049 00050 #if OGRE_PROFILING == 1 00051 # if OGRE_COMPILER != OGRE_COMPILER_BORL 00052 # define OgreProfile( a ) Ogre::Profile _OgreProfileInstance( (a) ) 00053 # define OgreProfileBegin( a ) Ogre::Profiler::getSingleton().beginProfile( (a) ) 00054 # define OgreProfileEnd( a ) Ogre::Profiler::getSingleton().endProfile( (a) ) 00055 # else 00056 # define OgreProfile( a ) Ogre::Profile _OgreProfileInstance( __FUNC__ ) 00057 # define OgreProfileBegin( a ) Ogre::Profiler::getSingleton().beginProfile( __FUNC__ ) 00058 # define OgreProfileEnd( a ) Ogre::Profiler::getSingleton().endProfile( __FUNC__ ) 00059 # endif 00060 #else 00061 # define OgreProfile( a ) 00062 # define OgreProfileBegin( a ) 00063 # define OgreProfileEnd( a ) 00064 #endif 00065 00066 namespace Ogre { 00067 00078 class _OgreExport Profile : public ProfilerAlloc { 00079 00080 public: 00081 Profile(const String& profileName); 00082 ~Profile(); 00083 00084 protected: 00085 00087 String mName; 00088 00089 00090 }; 00091 00103 class _OgreExport Profiler : public Singleton<Profiler>, public ProfilerAlloc { 00104 00105 public: 00106 Profiler(); 00107 ~Profiler(); 00108 00110 void setTimer(Timer* t); 00111 00113 Timer* getTimer(); 00114 00127 void beginProfile(const String& profileName); 00128 00141 void endProfile(const String& profileName); 00142 00148 void setEnabled(bool enabled); 00149 00151 bool getEnabled() const; 00152 00157 void enableProfile(const String& profileName); 00158 00163 void disableProfile(const String& profileName); 00164 00170 bool watchForMax(const String& profileName); 00171 00177 bool watchForMin(const String& profileName); 00178 00188 bool watchForLimit(const String& profileName, Real limit, bool greaterThan = true); 00189 00191 void logResults(); 00192 00194 void reset(); 00195 00197 void setUpdateDisplayFrequency(uint freq); 00198 00200 uint getUpdateDisplayFrequency() const; 00201 00217 static Profiler& getSingleton(void); 00233 static Profiler* getSingletonPtr(void); 00234 00235 protected: 00236 00238 void initialize(); 00239 00241 void displayResults(); 00242 00244 void processFrameStats(); 00245 00247 void changeEnableState(); 00248 00250 OverlayContainer* createContainer(); 00251 00253 OverlayElement* createTextArea(const String& name, Real width, Real height, Real top, Real left, 00254 uint fontSize, const String& caption, bool show = true); 00255 00257 OverlayElement* createPanel(const String& name, Real width, Real height, Real top, Real left, 00258 const String& materialName, bool show = true); 00259 00261 struct ProfileInstance { 00262 00264 String name; 00265 00267 String parent; 00268 00270 ulong currTime; 00271 00274 ulong accum; 00275 00277 uint hierarchicalLvl; 00278 }; 00279 00282 struct ProfileFrame { 00283 00285 String name; 00286 00288 ulong frameTime; 00289 00291 uint calls; 00292 00294 uint hierarchicalLvl; 00295 00296 }; 00297 00299 struct ProfileHistory { 00300 00302 String name; 00303 00305 Real currentTime; // % 00306 00308 Real maxTime; // % 00309 00311 Real minTime; // % 00312 00314 uint numCallsThisFrame; 00315 00318 Real totalTime; // % 00319 00322 ulong totalCalls; // % 00323 00325 uint hierarchicalLvl; 00326 00327 }; 00328 00329 00330 typedef std::list<ProfileInstance> ProfileStack; 00331 typedef std::list<ProfileFrame> ProfileFrameList; 00332 typedef std::list<ProfileHistory> ProfileHistoryList; 00333 typedef std::map<String, ProfileHistoryList::iterator> ProfileHistoryMap; 00334 typedef std::map<String, bool> DisabledProfileMap; 00335 00336 typedef std::list<OverlayElement*> ProfileBarList; 00337 00339 ProfileStack mProfiles; 00340 00343 ProfileFrameList mProfileFrame; 00344 00346 ProfileHistoryList mProfileHistory; 00347 00349 ProfileHistoryMap mProfileHistoryMap; 00350 00352 DisabledProfileMap mDisabledProfiles; 00353 00355 ProfileBarList mProfileBars; 00356 00358 bool mInitialized; 00359 00361 uint maxProfiles; 00362 00364 Overlay* mOverlay; 00365 00367 OverlayContainer* mProfileGui; 00368 00370 Real mBarHeight; 00371 00373 Real mGuiHeight; 00374 00376 Real mGuiWidth; 00377 00379 Real mBarIndent; 00380 00382 Real mGuiBorderWidth; 00383 00385 Real mBarLineWidth; 00386 00389 uint mUpdateDisplayFrequency; 00390 00392 uint mCurrentFrame; 00393 00395 Timer* mTimer; 00396 00398 ulong mTotalFrameTime; 00399 00401 bool mEnabled; 00402 00405 bool mEnableStateChangePending; 00406 00409 bool mNewEnableState; 00410 00411 }; // end class 00412 00413 } // end namespace 00414 00415 #endif
Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Sep 27 22:02:25 2009