OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OgreProfiler.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2011 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 /*
29 
30  Although the code is original, many of the ideas for the profiler were borrowed from
31 "Real-Time In-Game Profiling" by Steve Rabin which can be found in Game Programming
32 Gems 1.
33 
34  This code can easily be adapted to your own non-Ogre project. The only code that is
35 Ogre-dependent is in the visualization/logging routines and the use of the Timer class.
36 
37  Enjoy!
38 
39 */
40 
41 #ifndef __Profiler_H__
42 #define __Profiler_H__
43 
44 #include "OgrePrerequisites.h"
45 #include "OgreSingleton.h"
46 #include "OgreString.h"
47 #include "OgreOverlay.h"
48 
49 #if OGRE_PROFILING == 1
50 # define OgreProfile( a ) Ogre::Profile _OgreProfileInstance( (a) )
51 # define OgreProfileBegin( a ) Ogre::Profiler::getSingleton().beginProfile( (a) )
52 # define OgreProfileEnd( a ) Ogre::Profiler::getSingleton().endProfile( (a) )
53 # define OgreProfileGroup( a, g ) Ogre::Profile _OgreProfileInstance( (a), (g) )
54 # define OgreProfileBeginGroup( a, g ) Ogre::Profiler::getSingleton().beginProfile( (a), (g) )
55 # define OgreProfileEndGroup( a, g ) Ogre::Profiler::getSingleton().endProfile( (a), (g) )
56 #else
57 # define OgreProfile( a )
58 # define OgreProfileBegin( a )
59 # define OgreProfileEnd( a )
60 # define OgreProfileGroup( a, g )
61 # define OgreProfileBeginGroup( a, g )
62 # define OgreProfileEndGroup( a, g )
63 #endif
64 
65 namespace Ogre {
76  {
78  OGREPROF_USER_DEFAULT = 0x00000001,
80  OGREPROF_ALL = 0xFF000000,
82  OGREPROF_GENERAL = 0x80000000,
84  OGREPROF_CULLING = 0x40000000,
86  OGREPROF_RENDERING = 0x20000000
87  };
88 
100 
101  public:
102  Profile(const String& profileName, uint32 groupID = (uint32)OGREPROF_USER_DEFAULT);
103  ~Profile();
104 
105  protected:
106 
111 
112 
113  };
114 
126  class _OgreExport Profiler : public Singleton<Profiler>, public ProfilerAlloc {
127 
128  public:
129  Profiler();
130  ~Profiler();
131 
133  void setTimer(Timer* t);
134 
136  Timer* getTimer();
137 
151  void beginProfile(const String& profileName, uint32 groupID = (uint32)OGREPROF_USER_DEFAULT);
152 
167  void endProfile(const String& profileName, uint32 groupID = (uint32)OGREPROF_USER_DEFAULT);
168 
174  void setEnabled(bool enabled);
175 
177  bool getEnabled() const;
178 
183  void enableProfile(const String& profileName);
184 
189  void disableProfile(const String& profileName);
190 
193  void setProfileGroupMask(uint32 mask) { mProfileMask = mask; }
196  uint32 getProfileGroupMask() const { return mProfileMask; }
197 
203  bool watchForMax(const String& profileName);
204 
210  bool watchForMin(const String& profileName);
211 
221  bool watchForLimit(const String& profileName, Real limit, bool greaterThan = true);
222 
224  void logResults();
225 
227  void reset();
228 
230  {
234  DISPLAY_MILLISECONDS
235  };
236 
239  void setDisplayMode(DisplayMode d) { mDisplayMode = d; }
242  DisplayMode getDisplayMode() const { return mDisplayMode; }
243 
245  void setUpdateDisplayFrequency(uint freq);
246 
248  uint getUpdateDisplayFrequency() const;
249 
251  void setOverlayDimensions(Real width, Real height);
252 
254  void setOverlayPosition(Real left, Real top);
255 
256  Real getOverlayWidth() const;
257  Real getOverlayHeight() const;
258  Real getOverlayLeft() const;
259  Real getOverlayTop() const;
260 
276  static Profiler& getSingleton(void);
292  static Profiler* getSingletonPtr(void);
293 
294  protected:
295 
297  void initialize();
298 
300  void displayResults();
301 
303  void processFrameStats();
304 
306  void changeEnableState();
307 
309  OverlayContainer* createContainer();
310 
312  OverlayElement* createTextArea(const String& name, Real width, Real height, Real top, Real left,
313  uint fontSize, const String& caption, bool show = true);
314 
316  OverlayElement* createPanel(const String& name, Real width, Real height, Real top, Real left,
317  const String& materialName, bool show = true);
318 
321 
324 
327 
330 
334 
337  };
338 
341  struct ProfileFrame {
342 
345 
348 
351 
354 
355  };
356 
358  struct ProfileHistory {
359 
362 
367 
372 
377 
380 
385 
389 
392 
393  };
394 
395 
401 
403 
406 
410 
413 
416 
419 
422 
425 
428 
431 
434 
437 
440 
443 
446 
449 
452 
455 
458 
461 
465 
468 
471 
474 
476  bool mEnabled;
477 
481 
485 
488 
491 
494 
498 
499 
500  }; // end class
504 } // end namespace
505 
506 #endif
User default profile.
Definition: OgreProfiler.h:78
String parent
The name of the parent, empty string if root.
Definition: OgreProfiler.h:326
float Real
Software floating point type.
unsigned int uint32
Definition: OgrePlatform.h:246
#define _OgreExport
Definition: OgrePlatform.h:203
Real mGuiLeft
The horz position of the stats window.
Definition: OgreProfiler.h:445
unsigned long ulong
Represents the total timing information of a profile since profiles can be called more than once each...
Definition: OgreProfiler.h:341
uint mCurrentFrame
The number of elapsed frame, used with mUpdateDisplayFrequency.
Definition: OgreProfiler.h:467
Real mGuiHeight
The height of the stats window.
Definition: OgreProfiler.h:439
Template class for creating single-instance global classes.
Definition: OgreSingleton.h:64
uint mMaxDisplayProfiles
The max number of profiles we can display.
Definition: OgreProfiler.h:427
Real mAverageFrameTime
Rolling average of millisecs.
Definition: OgreProfiler.h:496
uint hierarchicalLvl
The hierarchical level of this profile, 0 being the main loop.
Definition: OgreProfiler.h:353
list< OverlayElement * >::type ProfileBarList
Definition: OgreProfiler.h:402
uint32 getProfileGroupMask() const
Get the mask which all profiles must pass to be enabled.
Definition: OgreProfiler.h:196
Represents a history of each profile during the duration of the app.
Definition: OgreProfiler.h:358
map< String, bool >::type DisabledProfileMap
Definition: OgreProfiler.h:400
ProfileStack mProfiles
A stack for each individual profile per frame.
Definition: OgreProfiler.h:405
String name
The name of the profile.
Definition: OgreProfiler.h:323
uint32 mGroupID
The group ID.
Definition: OgreProfiler.h:110
Real mBarLineWidth
The width of the min, avg, and max lines in a profile display.
Definition: OgreProfiler.h:457
bool mEnableStateChangePending
Keeps track of whether this profiler has received a request to be enabled/disabled.
Definition: OgreProfiler.h:480
A 2D element which contains other OverlayElement instances.
Real currentTimePercent
The current percentage of frame time this profile has taken.
Definition: OgreProfiler.h:364
Real maxTimePercent
The maximum percentage of frame time this profile has taken.
Definition: OgreProfiler.h:369
uint hierarchicalLvl
The hierarchical level of this profile, 0 being the root profile.
Definition: OgreProfiler.h:391
String mName
The name of this profile.
Definition: OgreProfiler.h:108
uint numCallsThisFrame
The number of times this profile has been called each frame.
Definition: OgreProfiler.h:379
uint mUpdateDisplayFrequency
The number of frames that must elapse before the current frame display is updated.
Definition: OgreProfiler.h:464
bool mEnabled
Whether this profiler is enabled.
Definition: OgreProfiler.h:476
list< ProfileFrame >::type ProfileFrameList
Definition: OgreProfiler.h:397
Real totalTimeMillisecs
The total frame time this profile has taken in milliseconds.
Definition: OgreProfiler.h:384
ProfileHistoryMap mProfileHistoryMap
We use this for quick look-ups of profiles in the history list.
Definition: OgreProfiler.h:415
Timer * mTimer
The timer used for profiling.
Definition: OgreProfiler.h:470
uint calls
The number of times this profile was called this frame.
Definition: OgreProfiler.h:350
uint hierarchicalLvl
The hierarchical level of this profile, 0 being the root profile.
Definition: OgreProfiler.h:336
The profiler allows you to measure the performance of your code.
Definition: OgreProfiler.h:126
Display % frame usage on the overlay.
Definition: OgreProfiler.h:232
Timer class.
ProfileGroupMask
List of reserved profiling masks.
Definition: OgreProfiler.h:75
Real mGuiWidth
The width of the stats window.
Definition: OgreProfiler.h:442
Real maxTimeMillisecs
The maximum frame time this profile has taken in milliseconds.
Definition: OgreProfiler.h:371
DisabledProfileMap mDisabledProfiles
Holds the names of disabled profiles.
Definition: OgreProfiler.h:418
ulong mMaxTotalFrameTime
The max frame time recorded.
Definition: OgreProfiler.h:493
String name
The name of the profile.
Definition: OgreProfiler.h:344
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
ulong currTime
The time this profile was started.
Definition: OgreProfiler.h:329
Real mBarHeight
The height of each bar.
Definition: OgreProfiler.h:436
ulong accum
Represents the total time of all child profiles to subtract from this profile.
Definition: OgreProfiler.h:333
Represents an individual profile call.
Definition: OgreProfiler.h:320
OverlayContainer * mProfileGui
The window that displays the profiler results.
Definition: OgreProfiler.h:433
Real mGuiBorderWidth
The width of the border between the profile window and each bar.
Definition: OgreProfiler.h:454
ulong frameTime
The total time this profile has taken this frame.
Definition: OgreProfiler.h:347
DisplayMode getDisplayMode() const
Get the display mode for the overlay.
Definition: OgreProfiler.h:242
Real currentTimeMillisecs
The current frame time this profile has taken in milliseconds.
Definition: OgreProfiler.h:366
void setDisplayMode(DisplayMode d)
Set the display mode for the overlay.
Definition: OgreProfiler.h:239
General processing.
Definition: OgreProfiler.h:82
ulong totalCalls
The total number of times this profile was called (used to calculate average)
Definition: OgreProfiler.h:388
Abstract definition of a 2D element to be displayed in an Overlay.
Real minTimeMillisecs
The minimum frame time this profile has taken in milliseconds.
Definition: OgreProfiler.h:376
bool mNewEnableState
Keeps track of the new enabled/disabled state that the user has requested which will be applied after...
Definition: OgreProfiler.h:484
ProfileFrameList mProfileFrame
Accumulates the results of each profile per frame (since a profile can be called more than once a fra...
Definition: OgreProfiler.h:409
list< ProfileInstance >::type ProfileStack
Definition: OgreProfiler.h:396
void setProfileGroupMask(uint32 mask)
Set the mask which all profiles must pass to be enabled.
Definition: OgreProfiler.h:193
ProfileBarList mProfileBars
Holds the display bars for each profile results.
Definition: OgreProfiler.h:421
bool mInitialized
Whether the GUI elements have been initialized.
Definition: OgreProfiler.h:424
Real mBarIndent
The size of the indent for each profile display bar.
Definition: OgreProfiler.h:451
list< ProfileHistory >::type ProfileHistoryList
Definition: OgreProfiler.h:398
_StringBase String
DisplayMode mDisplayMode
How to display the overlay.
Definition: OgreProfiler.h:490
String name
The name of the profile.
Definition: OgreProfiler.h:361
ProfileHistoryList mProfileHistory
Keeps track of the statistics of each profile.
Definition: OgreProfiler.h:412
All in-built Ogre profiling will match this mask.
Definition: OgreProfiler.h:80
Real mGuiTop
The vertical position of the stats window.
Definition: OgreProfiler.h:448
Overlay * mOverlay
The overlay which contains our profiler results display.
Definition: OgreProfiler.h:430
ulong mTotalFrameTime
The total time each frame takes.
Definition: OgreProfiler.h:473
An individual profile that will be processed by the Profiler.
Definition: OgreProfiler.h:99
Real minTimePercent
The minimum percentage of frame time this profile has taken.
Definition: OgreProfiler.h:374
Represents a layer which is rendered on top of the 'normal' scene contents.
Definition: OgreOverlay.h:70
uint32 mProfileMask
Mask to decide whether a type of profile is enabled or not.
Definition: OgreProfiler.h:487
map< String, ProfileHistoryList::iterator >::type ProfileHistoryMap
Definition: OgreProfiler.h:399
unsigned int uint
Real totalTimePercent
The total percentage of frame time this profile has taken.
Definition: OgreProfiler.h:382
Real mBarSpacing
The distance between bars.
Definition: OgreProfiler.h:460