Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound 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 © 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
    00212             static Profiler& getSingleton(void);
    00228             static Profiler* getSingletonPtr(void);
    00229
    00230         protected:
    00231
    00233             void initialize();
    00234
    00236             void displayResults();
    00237
    00239             void processFrameStats();
    00240
    00242             void changeEnableState();
    00243
    00245             GuiContainer* createContainer();
    00246
    00248             GuiElement* createTextArea(const String& name, Real width, Real height, Real top, Real left,
    00249                                        uint fontSize, const String& caption, bool show = true);
    00250
    00252             GuiElement* createPanel(const String& name, Real width, Real height, Real top, Real left,
    00253                                     const String& materialName, bool show = true);
    00254
    00256             struct ProfileInstance {
    00257
    00259                 String      name;
    00260
    00262                 String      parent;
    00263
    00265                 ulong       currTime;
    00266
    00269                 ulong       accum;
    00270
    00272                 uint        hierarchicalLvl;
    00273             };
    00274
    00277             struct ProfileFrame {
    00278
    00280                 String  name;
    00281
    00283                 ulong   frameTime;
    00284
    00286                 uint    calls;
    00287
    00289                 uint    hierarchicalLvl;
    00290
    00291             };
    00292
    00294             struct ProfileHistory {
    00295
    00297                 String  name;
    00298
    00300                 Real    currentTime; // %
    00301
    00303                 Real    maxTime; // %
    00304
    00306                 Real    minTime; // %
    00307
    00309                 uint    numCallsThisFrame;
    00310
    00313                 Real    totalTime; // %
    00314
    00317                 ulong   totalCalls; // %
    00318
    00320                 uint    hierarchicalLvl;
    00321
    00322             };
    00323
    00324
    00325             typedef std::list<ProfileInstance> ProfileStack;
    00326             typedef std::list<ProfileFrame> ProfileFrameList;
    00327             typedef std::list<ProfileHistory> ProfileHistoryList;
    00328             typedef std::map<String, ProfileHistoryList::iterator> ProfileHistoryMap;
    00329             typedef std::map<String, bool> DisabledProfileMap;
    00330
    00331             typedef std::list<GuiElement*> ProfileBarList;
    00332
    00334             ProfileStack mProfiles;
    00335
    00338             ProfileFrameList mProfileFrame;
    00339
    00341             ProfileHistoryList mProfileHistory;
    00342
    00344             ProfileHistoryMap mProfileHistoryMap;
    00345
    00347             DisabledProfileMap mDisabledProfiles;
    00348
    00350             ProfileBarList mProfileBars;
    00351
    00353             bool mInitialized;
    00354
    00356             uint maxProfiles;
    00357
    00359             Overlay* mOverlay;
    00360
    00362             GuiContainer* mProfileGui;
    00363
    00365             Real mBarHeight;
    00366
    00368             Real mGuiHeight;
    00369
    00371             Real mGuiWidth;
    00372
    00374             Real mBarIndent;
    00375
    00377             Real mGuiBorderWidth;
    00378
    00380             Real mBarLineWidth;
    00381
    00384             uint mUpdateDisplayFrequency;
    00385
    00387             uint mCurrentFrame;
    00388
    00390             Timer* mTimer;
    00391
    00393             ulong mTotalFrameTime;
    00394
    00396             bool mEnabled;
    00397
    00400             bool mEnableStateChangePending;
    00401
    00404             bool mNewEnableState;
    00405
    00406     }; // end class
    00407
    00408 } // end namespace
    00409
    00410 #endif

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:39 2004