# Ogre::Profiler Class Reference

The profiler allows you to measure the performance of your code. More...

`#include <OgreProfiler.h>`

Inheritance diagram for Ogre::Profiler:

[legend]

List of all members.

## Public Member Functions

| Profiler ()
| ~Profiler ()
void | setTimer (Timer *t)
| Sets the timer for the profiler.
Timer * | getTimer ()
| Retrieves the timer for the profiler.
void | beginProfile (const String &profileName)
| Begins a profile.
void | endProfile (const String &profileName)
| Ends a profile.
void | setEnabled (bool enabled)
| Sets whether this profiler is enabled.
bool | getEnabled () const
| Gets whether this profiler is enabled.
void | enableProfile (const String &profileName)
| Enables a previously disabled profile.
void | disableProfile (const String &profileName)
| Disables a profile.
bool | watchForMax (const String &profileName)
| Returns true if the specified profile reaches a new frame time maximum.
bool | watchForMin (const String &profileName)
| Returns true if the specified profile reaches a new frame time minimum.
bool | watchForLimit (const String &profileName, Real limit, bool greaterThan=true)
| Returns true if the specified profile goes over or under the given limit frame time.
void | logResults ()
| Outputs current profile statistics to the log.
void | reset ()
| Clears the profiler statistics.
void | setUpdateDisplayFrequency (uint freq)
| Sets the Profiler so the display of results are updated ever n frames.
uint | getUpdateDisplayFrequency () const
| Gets the frequency that the Profiler display is updated.
void * | operator new (size_t sz, const char *file, int line, const char *func)
| operator new, with debug line info
void * | operator new (size_t sz)
void * | operator new (size_t sz, void *ptr)
| placement operator new
void * | operator new[] (size_t sz, const char *file, int line, const char *func)
| array operator new, with debug line info
void * | operator new[] (size_t sz)
void | operator delete (void *ptr)
void | operator delete (void *ptr, void *)
void | operator delete (void *ptr, const char *, int, const char *)
void | operator delete[] (void *ptr)
void | operator delete[] (void *ptr, const char *, int, const char *)

## Static Public Member Functions

static Profiler & | getSingleton (void)
| Override standard Singleton retrieval.
static Profiler * | getSingletonPtr (void)
| Override standard Singleton retrieval.

## Protected Types

typedef std::list < ProfileInstance > | ProfileStack
typedef std::list< ProfileFrame > | ProfileFrameList
typedef std::list< ProfileHistory > | ProfileHistoryList
typedef std::map< String, ProfileHistoryList::iterator > | ProfileHistoryMap
typedef std::map< String, bool > | DisabledProfileMap
typedef std::list < OverlayElement * > | ProfileBarList

## Protected Member Functions

void | initialize ()
| Initializes the profiler's GUI elements.
void | displayResults ()
| Prints the profiling results of each frame.
void | processFrameStats ()
| Processes the profiler data after each frame.
void | changeEnableState ()
| Handles a change of the profiler's enabled state.
OverlayContainer * | createContainer ()
| An internal function to create the container which will hold our display elements.
OverlayElement * | createTextArea (const String &name, Real width, Real height, Real top, Real left, uint fontSize, const String &caption, bool show=true)
| An internal function to create a text area.
OverlayElement * | createPanel (const String &name, Real width, Real height, Real top, Real left, const String &materialName, bool show=true)
| An internal function to create a panel.

## Protected Attributes

ProfileStack | mProfiles
| A stack for each individual profile per frame.
ProfileFrameList | mProfileFrame
| Accumulates the results of each profile per frame (since a profile can be called more than once a frame).
ProfileHistoryList | mProfileHistory
| Keeps track of the statistics of each profile.
ProfileHistoryMap | mProfileHistoryMap
| We use this for quick look-ups of profiles in the history list.
DisabledProfileMap | mDisabledProfiles
| Holds the names of disabled profiles.
ProfileBarList | mProfileBars
| Holds the display bars for each profile results.
bool | mInitialized
| Whether the GUI elements have been initialized.
uint | maxProfiles
| The max number of profiles we can display.
Overlay * | mOverlay
| The overlay which contains our profiler results display.
OverlayContainer * | mProfileGui
| The window that displays the profiler results.
Real | mBarHeight
| The height of each bar.
Real | mGuiHeight
| The height of the stats window.
Real | mGuiWidth
| The width of the stats window.
Real | mBarIndent
| The size of the indent for each profile display bar.
Real | mGuiBorderWidth
| The width of the border between the profile window and each bar.
Real | mBarLineWidth
| The width of the min, avg, and max lines in a profile display.
uint | mUpdateDisplayFrequency
| The number of frames that must elapse before the current frame display is updated.
uint | mCurrentFrame
| The number of elapsed frame, used with mUpdateDisplayFrequency.
Timer * | mTimer
| The timer used for profiling.
ulong | mTotalFrameTime
| The total time each frame takes.
bool | mEnabled
| Whether this profiler is enabled.
bool | mEnableStateChangePending
| Keeps track of whether this profiler has received a request to be enabled/disabled.
bool | mNewEnableState
| Keeps track of the new enabled/disabled state that the user has requested which will be applied after the frame ends.

## Static Protected Attributes

static T * | ms_Singleton

## Classes

struct | ProfileFrame
| Represents the total timing information of a profile since profiles can be called more than once each frame. More...
struct | ProfileHistory
| Represents a history of each profile during the duration of the app. More...
struct | ProfileInstance
| Represents an individual profile call. More...

## Detailed Description

The profiler allows you to measure the performance of your code.

Remarks:
  Do not create profiles directly from this unless you want a profile to last outside of its scope (i.e. the main game loop). For most cases, use the macro OgreProfile(name) and braces to limit the scope. You must enable the Profile before you can used it with setEnabled(true). If you want to disable profiling in Ogre, simply set the macro OGRE_PROFILING to 0.

Author:
  Amit Mathew (amitmathew (at) yahoo (dot) com)

Definition at line 103 of file OgreProfiler.h.

## Member Typedef Documentation

typedef std::list<ProfileInstance> Ogre::Profiler::ProfileStack `[protected]`

Definition at line 330 of file OgreProfiler.h.

typedef std::list<ProfileFrame> Ogre::Profiler::ProfileFrameList `[protected]`

Definition at line 331 of file OgreProfiler.h.

typedef std::list<ProfileHistory> Ogre::Profiler::ProfileHistoryList `[protected]`

Definition at line 332 of file OgreProfiler.h.

typedef std::map<String, ProfileHistoryList::iterator> Ogre::Profiler::ProfileHistoryMap `[protected]`

Definition at line 333 of file OgreProfiler.h.

typedef std::map<String, bool> Ogre::Profiler::DisabledProfileMap `[protected]`

Definition at line 334 of file OgreProfiler.h.

typedef std::list<OverlayElement*> Ogre::Profiler::ProfileBarList `[protected]`

Definition at line 336 of file OgreProfiler.h.

## Constructor & Destructor Documentation

Ogre::Profiler::Profiler | ( |  | ) |

Ogre::Profiler::~Profiler | ( |  | ) |

## Member Function Documentation

void Ogre::Profiler::setTimer | ( | Timer * | t | ) |

Sets the timer for the profiler.

Timer* Ogre::Profiler::getTimer | ( |  | ) |

Retrieves the timer for the profiler.

void Ogre::Profiler::beginProfile | ( | const String & | profileName | ) |

Begins a profile.

Remarks:
  Use the macro OgreProfileBegin(name) instead of calling this directly so that profiling can be ignored in the release version of your app.

  You only use the macro (or this) if you want a profile to last outside of its scope (i.e. the main game loop). If you use this function, make sure you use a corresponding OgreProfileEnd(name). Usually you would use the macro OgreProfile(name). This function will be ignored for a profile that has been disabled or if the profiler is disabled.

Parameters:

  | profileName | Must be unique and must not be an empty string

void Ogre::Profiler::endProfile | ( | const String & | profileName | ) |

Ends a profile.

Remarks:
  Use the macro OgreProfileEnd(name) instead of calling this directly so that profiling can be ignored in the release version of your app.

  This function is usually not called directly unless you want a profile to last outside of its scope. In most cases, using the macro OgreProfile(name) which will call this function automatically when it goes out of scope. Make sure the name of this profile matches its corresponding beginProfile name. This function will be ignored for a profile that has been disabled or if the profiler is disabled.

void Ogre::Profiler::setEnabled | ( | bool | enabled | ) |

Sets whether this profiler is enabled.

Only takes effect after the the frame has ended.

Remarks:
  When this is called the first time with the parameter true, it initializes the GUI for the Profiler

bool Ogre::Profiler::getEnabled | ( |  | ) | const

Gets whether this profiler is enabled.

void Ogre::Profiler::enableProfile | ( | const String & | profileName | ) |

Enables a previously disabled profile.

Remarks:
  Only enables the profile if this function is not called during the profile it is trying to enable.

void Ogre::Profiler::disableProfile | ( | const String & | profileName | ) |

Disables a profile.

Remarks:
  Only disables the profile if this function is not called during the profile it is trying to disable.

bool Ogre::Profiler::watchForMax | ( | const String & | profileName | ) |

Returns true if the specified profile reaches a new frame time maximum.

Remarks:
  If this is called during a frame, it will be reading the results from the previous frame. Therefore, it is best to use this after the frame has ended.

bool Ogre::Profiler::watchForMin | ( | const String & | profileName | ) |

Returns true if the specified profile reaches a new frame time minimum.

Remarks:
  If this is called during a frame, it will be reading the results from the previous frame. Therefore, it is best to use this after the frame has ended.

bool Ogre::Profiler::watchForLimit | ( | const String & | profileName,
|  | Real | limit,
|  | bool | greaterThan = `true` |
| ) |  |  |

Returns true if the specified profile goes over or under the given limit frame time.

Remarks:
  If this is called during a frame, it will be reading the results from the previous frame. Therefore, it is best to use this after the frame has ended.

Parameters:

  | limit | A number between 0 and 1 representing the percentage of frame time
  | greaterThan | If true, this will return whether the limit is exceeded. Otherwise, it will return if the frame time has gone under this limit.

void Ogre::Profiler::logResults | ( |  | ) |

Outputs current profile statistics to the log.

void Ogre::Profiler::reset | ( |  | ) |

Clears the profiler statistics.

void Ogre::Profiler::setUpdateDisplayFrequency | ( | uint | freq | ) |

Sets the Profiler so the display of results are updated ever n frames.

uint Ogre::Profiler::getUpdateDisplayFrequency | ( |  | ) | const

Gets the frequency that the Profiler display is updated.

static Profiler& Ogre::Profiler::getSingleton | ( | void |  | ) | `[static]`

Override standard Singleton retrieval.

Remarks:
  Why do we do this? Well, it's because the Singleton implementation is in a .h file, which means it gets compiled into anybody who includes it. This is needed for the Singleton template to work, but we actually only want it compiled into the implementation of the class based on the Singleton, not all of them. If we don't change this, we get link errors when trying to use the Singleton-based class from an outside dll.

  This method just delegates to the template version anyway, but the implementation stays in this single compilation unit, preventing link errors.

Reimplemented from Ogre::Singleton< T >.

static Profiler* Ogre::Profiler::getSingletonPtr | ( | void |  | ) | `[static]`

Override standard Singleton retrieval.

Remarks:
  Why do we do this? Well, it's because the Singleton implementation is in a .h file, which means it gets compiled into anybody who includes it. This is needed for the Singleton template to work, but we actually only want it compiled into the implementation of the class based on the Singleton, not all of them. If we don't change this, we get link errors when trying to use the Singleton-based class from an outside dll.

  This method just delegates to the template version anyway, but the implementation stays in this single compilation unit, preventing link errors.

Reimplemented from Ogre::Singleton< T >.

void Ogre::Profiler::initialize | ( |  | ) | `[protected]`

Initializes the profiler's GUI elements.

void Ogre::Profiler::displayResults | ( |  | ) | `[protected]`

Prints the profiling results of each frame.

void Ogre::Profiler::processFrameStats | ( |  | ) | `[protected]`

Processes the profiler data after each frame.

void Ogre::Profiler::changeEnableState | ( |  | ) | `[protected]`

Handles a change of the profiler's enabled state.

OverlayContainer* Ogre::Profiler::createContainer | ( |  | ) | `[protected]`

An internal function to create the container which will hold our display elements.

OverlayElement* Ogre::Profiler::createTextArea | ( | const String & | name,
|  | Real | width,
|  | Real | height,
|  | Real | top,
|  | Real | left,
|  | uint | fontSize,
|  | const String & | caption,
|  | bool | show = `true` |
| ) |  |  | `[protected]`

An internal function to create a text area.

OverlayElement* Ogre::Profiler::createPanel | ( | const String & | name,
|  | Real | width,
|  | Real | height,
|  | Real | top,
|  | Real | left,
|  | const String & | materialName,
|  | bool | show = `true` |
| ) |  |  | `[protected]`

An internal function to create a panel.

template<class Alloc>

void* Ogre::AllocatedObject< Alloc >::operator new | ( | size_t | sz,
|  | const char * | file,
|  | int | line,
|  | const char * | func |
| ) |  |  | `[inherited]`

operator new, with debug line info

Definition at line 62 of file OgreMemoryAllocatedObject.h.

template<class Alloc>

void* Ogre::AllocatedObject< Alloc >::operator new | ( | size_t | sz | ) | `[inherited]`

Definition at line 67 of file OgreMemoryAllocatedObject.h.

template<class Alloc>

void* Ogre::AllocatedObject< Alloc >::operator new | ( | size_t | sz,
|  | void * | ptr |
| ) |  |  | `[inherited]`

placement operator new

Definition at line 73 of file OgreMemoryAllocatedObject.h.

template<class Alloc>

void* Ogre::AllocatedObject< Alloc >::operator new[] | ( | size_t | sz,
|  | const char * | file,
|  | int | line,
|  | const char * | func |
| ) |  |  | `[inherited]`

array operator new, with debug line info

Definition at line 79 of file OgreMemoryAllocatedObject.h.

template<class Alloc>

void* Ogre::AllocatedObject< Alloc >::operator new[] | ( | size_t | sz | ) | `[inherited]`

Definition at line 84 of file OgreMemoryAllocatedObject.h.

template<class Alloc>

void Ogre::AllocatedObject< Alloc >::operator delete | ( | void * | ptr | ) | `[inherited]`

Definition at line 89 of file OgreMemoryAllocatedObject.h.

template<class Alloc>

void Ogre::AllocatedObject< Alloc >::operator delete | ( | void * | ptr,
|  | void * |  |
| ) |  |  | `[inherited]`

Definition at line 95 of file OgreMemoryAllocatedObject.h.

template<class Alloc>

void Ogre::AllocatedObject< Alloc >::operator delete | ( | void * | ptr,
|  | const char * | ,
|  | int | ,
|  | const char * |  |
| ) |  |  | `[inherited]`

Definition at line 101 of file OgreMemoryAllocatedObject.h.

template<class Alloc>

void Ogre::AllocatedObject< Alloc >::operator delete[] | ( | void * | ptr | ) | `[inherited]`

Definition at line 106 of file OgreMemoryAllocatedObject.h.

template<class Alloc>

void Ogre::AllocatedObject< Alloc >::operator delete[] | ( | void * | ptr,
|  | const char * | ,
|  | int | ,
|  | const char * |  |
| ) |  |  | `[inherited]`

Definition at line 112 of file OgreMemoryAllocatedObject.h.

## Member Data Documentation

ProfileStack Ogre::Profiler::mProfiles `[protected]`

A stack for each individual profile per frame.

Definition at line 339 of file OgreProfiler.h.

ProfileFrameList Ogre::Profiler::mProfileFrame `[protected]`

Accumulates the results of each profile per frame (since a profile can be called more than once a frame).

Definition at line 343 of file OgreProfiler.h.

ProfileHistoryList Ogre::Profiler::mProfileHistory `[protected]`

Keeps track of the statistics of each profile.

Definition at line 346 of file OgreProfiler.h.

ProfileHistoryMap Ogre::Profiler::mProfileHistoryMap `[protected]`

We use this for quick look-ups of profiles in the history list.

Definition at line 349 of file OgreProfiler.h.

DisabledProfileMap Ogre::Profiler::mDisabledProfiles `[protected]`

Holds the names of disabled profiles.

Definition at line 352 of file OgreProfiler.h.

ProfileBarList Ogre::Profiler::mProfileBars `[protected]`

Holds the display bars for each profile results.

Definition at line 355 of file OgreProfiler.h.

bool Ogre::Profiler::mInitialized `[protected]`

Whether the GUI elements have been initialized.

Definition at line 358 of file OgreProfiler.h.

uint Ogre::Profiler::maxProfiles `[protected]`

The max number of profiles we can display.

Definition at line 361 of file OgreProfiler.h.

Overlay* Ogre::Profiler::mOverlay `[protected]`

The overlay which contains our profiler results display.

Definition at line 364 of file OgreProfiler.h.

OverlayContainer* Ogre::Profiler::mProfileGui `[protected]`

The window that displays the profiler results.

Definition at line 367 of file OgreProfiler.h.

Real Ogre::Profiler::mBarHeight `[protected]`

The height of each bar.

Definition at line 370 of file OgreProfiler.h.

Real Ogre::Profiler::mGuiHeight `[protected]`

The height of the stats window.

Definition at line 373 of file OgreProfiler.h.

Real Ogre::Profiler::mGuiWidth `[protected]`

The width of the stats window.

Definition at line 376 of file OgreProfiler.h.

Real Ogre::Profiler::mBarIndent `[protected]`

The size of the indent for each profile display bar.

Definition at line 379 of file OgreProfiler.h.

Real Ogre::Profiler::mGuiBorderWidth `[protected]`

The width of the border between the profile window and each bar.

Definition at line 382 of file OgreProfiler.h.

Real Ogre::Profiler::mBarLineWidth `[protected]`

The width of the min, avg, and max lines in a profile display.

Definition at line 385 of file OgreProfiler.h.

uint Ogre::Profiler::mUpdateDisplayFrequency `[protected]`

The number of frames that must elapse before the current frame display is updated.

Definition at line 389 of file OgreProfiler.h.

uint Ogre::Profiler::mCurrentFrame `[protected]`

The number of elapsed frame, used with mUpdateDisplayFrequency.

Definition at line 392 of file OgreProfiler.h.

Timer* Ogre::Profiler::mTimer `[protected]`

The timer used for profiling.

Definition at line 395 of file OgreProfiler.h.

ulong Ogre::Profiler::mTotalFrameTime `[protected]`

The total time each frame takes.

Definition at line 398 of file OgreProfiler.h.

bool Ogre::Profiler::mEnabled `[protected]`

Whether this profiler is enabled.

Definition at line 401 of file OgreProfiler.h.

bool Ogre::Profiler::mEnableStateChangePending `[protected]`

Keeps track of whether this profiler has received a request to be enabled/disabled.

Definition at line 405 of file OgreProfiler.h.

bool Ogre::Profiler::mNewEnableState `[protected]`

Keeps track of the new enabled/disabled state that the user has requested which will be applied after the frame ends.

Definition at line 409 of file OgreProfiler.h.

template<typename T>

T* Ogre::Singleton< T >::ms_Singleton `[static, protected, inherited]`

Definition at line 61 of file OgreSingleton.h.

Referenced by Ogre::Singleton< Ogre::FontManager >::getSingleton(), Ogre::Singleton< Ogre::FontManager >::getSingletonPtr(), Ogre::Singleton< Ogre::FontManager >::Singleton(), and Ogre::Singleton< Ogre::FontManager >::~Singleton().

The documentation for this class was generated from the following file:

- OgreProfiler.h

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Dec 27 17:33:58 2009