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 © 2000-2002 The OGRE Team 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 */ 00025 /* 00026 00027 Although the code is original, many of the ideas for the profiler were borrowed from 00028 "Real-Time In-Game Profiling" by Steve Rabin which can be found in Game Programming 00029 Gems 1. 00030 00031 This code can easily be adapted to your own non-Ogre project. The only code that is 00032 Ogre-dependent is in the visualization/logging routines and the use of the Timer class. 00033 00034 Enjoy! 00035 00036 */ 00037 00038 #ifndef __Profiler_H__ 00039 #define __Profiler_H__ 00040 00041 #include "OgrePrerequisites.h" 00042 #include "OgreSingleton.h" 00043 #include "OgreString.h" 00044 00045 #if OGRE_PROFILING == 1 00046 # if OGRE_COMPILER != COMPILER_BORL 00047 # define OgreProfile( a ) Ogre::Profile _OgreProfileInstance( (a) ) 00048 # define OgreProfileBegin( a ) Ogre::Profiler::getSingleton().beginProfile( (a) ) 00049 # define OgreProfileEnd( a ) Ogre::Profiler::getSingleton().endProfile( (a) ) 00050 # else 00051 # define OgreProfile( a ) Ogre::Profile _OgreProfileInstance( __FUNC__ ) 00052 # define OgreProfileBegin( a ) Ogre::Profiler::getSingleton().beginProfile( __FUNC__ ) 00053 # define OgreProfileEnd( a ) Ogre::Profiler::getSingleton().endProfile( __FUNC__ ) 00054 # endif 00055 #else 00056 # define OgreProfile( a ) 00057 # define OgreProfileBegin( a ) 00058 # define OgreProfileEnd( a ) 00059 #endif 00060 00061 namespace Ogre { 00062 00073 class _OgreExport Profile { 00074 00075 public: 00076 Profile(const String& profileName); 00077 ~Profile(); 00078 00079 protected: 00080 00082 String mName; 00083 00084 00085 }; 00086 00098 class _OgreExport Profiler : public Singleton<Profiler> { 00099 00100 public: 00101 Profiler(); 00102 ~Profiler(); 00103 00105 void setTimer(Timer* t); 00106 00108 Timer* getTimer(); 00109 00122 void beginProfile(const String& profileName); 00123 00136 void endProfile(const String& profileName); 00137 00143 void setEnabled(bool enabled); 00144 00146 bool getEnabled() const; 00147 00152 void enableProfile(const String& profileName); 00153 00158 void disableProfile(const String& profileName); 00159 00165 bool watchForMax(const String& profileName); 00166 00172 bool watchForMin(const String& profileName); 00173 00183 bool watchForLimit(const String& profileName, Real limit, bool greaterThan = true); 00184 00186 void logResults(); 00187 00189 void reset(); 00190 00192 void setUpdateDisplayFrequency(uint freq); 00193 00195 uint getUpdateDisplayFrequency() const; 00196 00197 static Profiler& getSingleton(); 00198 00199 protected: 00200 00202 void initialize(); 00203 00205 void displayResults(); 00206 00208 void processFrameStats(); 00209 00211 void changeEnableState(); 00212 00214 GuiContainer* createContainer(); 00215 00217 GuiElement* createTextArea(const String& name, Real width, Real height, Real top, Real left, 00218 uint fontSize, const String& caption, bool show = true); 00219 00221 GuiElement* createPanel(const String& name, Real width, Real height, Real top, Real left, 00222 const String& materialName, bool show = true); 00223 00225 struct ProfileInstance { 00226 00228 String name; 00229 00231 String parent; 00232 00234 ulong currTime; 00235 00238 ulong accum; 00239 00241 uint hierarchicalLvl; 00242 }; 00243 00246 struct ProfileFrame { 00247 00249 String name; 00250 00252 ulong frameTime; 00253 00255 uint calls; 00256 00258 uint hierarchicalLvl; 00259 00260 }; 00261 00263 struct ProfileHistory { 00264 00266 String name; 00267 00269 Real currentTime; // % 00270 00272 Real maxTime; // % 00273 00275 Real minTime; // % 00276 00278 uint numCallsThisFrame; 00279 00282 Real totalTime; // % 00283 00286 ulong totalCalls; // % 00287 00289 uint hierarchicalLvl; 00290 00291 }; 00292 00293 00294 typedef std::list<ProfileInstance> ProfileStack; 00295 typedef std::list<ProfileFrame> ProfileFrameList; 00296 typedef std::list<ProfileHistory> ProfileHistoryList; 00297 typedef std::map<String, ProfileHistoryList::iterator> ProfileHistoryMap; 00298 typedef std::map<String, bool> DisabledProfileMap; 00299 00300 typedef std::list<GuiElement*> ProfileBarList; 00301 00303 ProfileStack mProfiles; 00304 00307 ProfileFrameList mProfileFrame; 00308 00310 ProfileHistoryList mProfileHistory; 00311 00313 ProfileHistoryMap mProfileHistoryMap; 00314 00316 DisabledProfileMap mDisabledProfiles; 00317 00319 ProfileBarList mProfileBars; 00320 00322 bool mInitialized; 00323 00325 uint maxProfiles; 00326 00328 Overlay* mOverlay; 00329 00331 GuiContainer* mProfileGui; 00332 00334 Real mBarHeight; 00335 00337 Real mGuiHeight; 00338 00340 Real mGuiWidth; 00341 00343 Real mBarIndent; 00344 00346 Real mGuiBorderWidth; 00347 00349 Real mBarLineWidth; 00350 00353 uint mUpdateDisplayFrequency; 00354 00356 uint mCurrentFrame; 00357 00359 Timer* mTimer; 00360 00362 ulong mTotalFrameTime; 00363 00365 bool mEnabled; 00366 00369 bool mEnableStateChangePending; 00370 00373 bool mNewEnableState; 00374 00375 }; // end class 00376 00377 } // end namespace 00378 00379 #endif
Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:22 2004