Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

OgreProfiler.h

Go to the documentation of this file.
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-2005 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 #include "OgreOverlay.h"
00045 
00046 #if OGRE_PROFILING == 1
00047 #   if OGRE_COMPILER != OGRE_COMPILER_BORL
00048 #       define OgreProfile( a ) Ogre::Profile _OgreProfileInstance( (a) )
00049 #       define OgreProfileBegin( a ) Ogre::Profiler::getSingleton().beginProfile( (a) )
00050 #       define OgreProfileEnd( a ) Ogre::Profiler::getSingleton().endProfile( (a) )
00051 #   else
00052 #       define OgreProfile( a ) Ogre::Profile _OgreProfileInstance( __FUNC__ )
00053 #       define OgreProfileBegin( a ) Ogre::Profiler::getSingleton().beginProfile( __FUNC__ )
00054 #       define OgreProfileEnd( a ) Ogre::Profiler::getSingleton().endProfile( __FUNC__ )
00055 #   endif
00056 #else
00057 #   define OgreProfile( a )
00058 #   define OgreProfileBegin( a )
00059 #   define OgreProfileEnd( a )
00060 #endif
00061 
00062 namespace Ogre {
00063 
00074     class _OgreExport Profile {
00075 
00076         public:
00077             Profile(const String& profileName);
00078             ~Profile();
00079 
00080         protected:
00081 
00083             String mName;
00084             
00085 
00086     };
00087 
00099     class _OgreExport Profiler : public Singleton<Profiler> {
00100 
00101         public:
00102             Profiler();
00103             ~Profiler();
00104 
00106             void setTimer(Timer* t);
00107 
00109             Timer* getTimer();
00110 
00123             void beginProfile(const String& profileName);
00124 
00137             void endProfile(const String& profileName);
00138 
00144             void setEnabled(bool enabled);
00145 
00147             bool getEnabled() const;
00148 
00153             void enableProfile(const String& profileName);
00154 
00159             void disableProfile(const String& profileName);
00160 
00166             bool watchForMax(const String& profileName);
00167 
00173             bool watchForMin(const String& profileName);
00174 
00184             bool watchForLimit(const String& profileName, Real limit, bool greaterThan = true);
00185 
00187             void logResults();
00188 
00190             void reset();
00191 
00193             void setUpdateDisplayFrequency(uint freq);
00194 
00196             uint getUpdateDisplayFrequency() const;
00197 
00213             static Profiler& getSingleton(void);
00229             static Profiler* getSingletonPtr(void);
00230 
00231         protected:
00232 
00234             void initialize();
00235 
00237             void displayResults();
00238 
00240             void processFrameStats();
00241 
00243             void changeEnableState();
00244 
00246             OverlayContainer* createContainer();
00247 
00249             OverlayElement* createTextArea(const String& name, Real width, Real height, Real top, Real left, 
00250                                        uint fontSize, const String& caption, bool show = true);
00251 
00253             OverlayElement* createPanel(const String& name, Real width, Real height, Real top, Real left, 
00254                                     const String& materialName, bool show = true);
00255 
00257             struct ProfileInstance {
00258 
00260                 String      name;
00261 
00263                 String      parent;
00264 
00266                 ulong       currTime;
00267 
00270                 ulong       accum;
00271 
00273                 uint        hierarchicalLvl;
00274             };
00275 
00278             struct ProfileFrame {
00279                 
00281                 String  name;
00282 
00284                 ulong   frameTime;
00285 
00287                 uint    calls;
00288 
00290                 uint    hierarchicalLvl;
00291 
00292             };
00293             
00295             struct ProfileHistory {
00296 
00298                 String  name;
00299 
00301                 Real    currentTime; // %
00302 
00304                 Real    maxTime; // %
00305 
00307                 Real    minTime; // %
00308 
00310                 uint    numCallsThisFrame;
00311 
00314                 Real    totalTime; // %
00315 
00318                 ulong   totalCalls; // %
00319 
00321                 uint    hierarchicalLvl;
00322 
00323             };
00324 
00325             
00326             typedef std::list<ProfileInstance> ProfileStack;
00327             typedef std::list<ProfileFrame> ProfileFrameList;
00328             typedef std::list<ProfileHistory> ProfileHistoryList;
00329             typedef std::map<String, ProfileHistoryList::iterator> ProfileHistoryMap;
00330             typedef std::map<String, bool> DisabledProfileMap;
00331 
00332             typedef std::list<OverlayElement*> ProfileBarList;
00333 
00335             ProfileStack mProfiles;
00336 
00339             ProfileFrameList mProfileFrame;
00340 
00342             ProfileHistoryList mProfileHistory;
00343 
00345             ProfileHistoryMap mProfileHistoryMap;
00346 
00348             DisabledProfileMap mDisabledProfiles;
00349 
00351             ProfileBarList mProfileBars;
00352 
00354             bool mInitialized;
00355 
00357             uint maxProfiles;
00358 
00360             Overlay* mOverlay;
00361 
00363             OverlayContainer* mProfileGui;
00364 
00366             Real mBarHeight;
00367 
00369             Real mGuiHeight;
00370 
00372             Real mGuiWidth;
00373 
00375             Real mBarIndent;
00376 
00378             Real mGuiBorderWidth;
00379 
00381             Real mBarLineWidth;
00382 
00385             uint mUpdateDisplayFrequency;
00386 
00388             uint mCurrentFrame;
00389 
00391             Timer* mTimer;
00392 
00394             ulong mTotalFrameTime;
00395 
00397             bool mEnabled;
00398 
00401             bool mEnableStateChangePending;
00402 
00405             bool mNewEnableState;
00406 
00407     }; // end class
00408 
00409 } // end namespace
00410 
00411 #endif

Copyright © 2000-2005 by The OGRE Team
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Mar 12 14:37:47 2006