arsa  2.7
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
irr::IProfiler Class Referenceabstract

Code-profiler. Please check the example in the Irrlicht examples folder about how to use it. More...

#include <IProfiler.h>

Public Member Functions

 IProfiler ()
 Constructor. You could use this to create a new profiler, but usually getProfiler() is used to access the global instance. More...
 
virtual ~IProfiler ()
 
void add (s32 id, const core::stringw &name, const core::stringw &groupName)
 Add an id with given name and group which can be used for profiling with start/stop. More...
 
s32 add (const core::stringw &name, const core::stringw &groupName)
 Add an automatically generated for the given name and group which can be used for profiling with start/stop. More...
 
u32 getProfileDataCount () const
 Return the number of profile data blocks. There is one for each id. More...
 
bool findDataIndex (u32 &result, const core::stringw &name) const
 Search for the index of the profile data by name. More...
 
const SProfileDatagetProfileDataByIndex (u32 index) const
 Get the profile data. More...
 
const SProfileDatagetProfileDataById (u32 id)
 Get the profile data. More...
 
u32 getGroupCount () const
 Get the number of profile groups. Will be at least 1. More...
 
const SProfileDatagetGroupData (u32 index) const
 Get profile data for a group. More...
 
bool findGroupIndex (u32 &result, const core::stringw &name) const
 Find the group index by the group-name. More...
 
void start (s32 id)
 Start profile-timing for the given id. More...
 
void stop (s32 id)
 Stop profile-timing for the given id. More...
 
void resetDataById (s32 id)
 Reset profile data for the given id. More...
 
void resetDataByIndex (u32 index)
 Reset profile data for the given index. More...
 
void resetGroup (u32 index)
 Reset profile data for a whole group. More...
 
void resetAll ()
 Reset all profile data. More...
 
virtual void printAll (core::stringw &result, bool includeOverview=false, bool suppressUncalled=true) const =0
 Write all profile-data into a string. More...
 
virtual void printGroup (core::stringw &result, u32 groupIndex, bool suppressUncalled) const =0
 Write the profile data of one group into a string. More...
 

Protected Member Functions

u32 addGroup (const core::stringw &name)
 

Protected Attributes

ITimerTimer
 
core::array< SProfileDataProfileDatas
 
core::array< SProfileDataProfileGroups
 

Detailed Description

Code-profiler. Please check the example in the Irrlicht examples folder about how to use it.

Definition at line 101 of file IProfiler.h.

Constructor & Destructor Documentation

◆ IProfiler()

irr::IProfiler::IProfiler ( )
inline

Constructor. You could use this to create a new profiler, but usually getProfiler() is used to access the global instance.

Definition at line 105 of file IProfiler.h.

105  : Timer(0), NextAutoId(INT_MAX)
106  {}
ITimer * Timer
Definition: IProfiler.h:214

◆ ~IProfiler()

virtual irr::IProfiler::~IProfiler ( )
inlinevirtual

Definition at line 108 of file IProfiler.h.

109  {}

Member Function Documentation

◆ add() [1/2]

void irr::IProfiler::add ( s32  id,
const core::stringw name,
const core::stringw groupName 
)
inline

Add an id with given name and group which can be used for profiling with start/stop.

After calling this once you can start/stop profiling for the given id.

Parameters
idShould be >= 0 as negative id's are reserved for Irrlicht. Also very large numbers (near INT_MAX) might have been added automatically by the other add function.
nameName for displaying profile data.
groupNameEach id belongs into a group - this helps on displaying profile data.

Definition at line 346 of file IProfiler.h.

347 {
348  u32 groupIdx;
349  if ( !findGroupIndex(groupIdx, groupName) )
350  {
351  groupIdx = addGroup(groupName);
352  }
353 
354  SProfileData data(id);
355  s32 idx = ProfileDatas.binary_search(data);
356  if ( idx < 0 )
357  {
358  data.reset();
359  data.GroupIndex = groupIdx;
360  data.Name = name;
361 
362  ProfileDatas.push_back(data);
363  ProfileDatas.sort();
364  }
365  else
366  {
367  // only reset on group changes, otherwise we want to keep the data or coding CProfileScope would become tricky.
368  if ( groupIdx != ProfileDatas[idx].GroupIndex )
369  {
370  resetDataByIndex((u32)idx);
371  ProfileDatas[idx].GroupIndex = groupIdx;
372  }
373  ProfileDatas[idx].Name = name;
374  }
375 }
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
GLuint const GLchar * name
signed int s32
32 bit signed variable.
Definition: irrTypes.h:70
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
void resetDataByIndex(u32 index)
Reset profile data for the given index.
Definition: IProfiler.h:432
bool findGroupIndex(u32 &result, const core::stringw &name) const
Find the group index by the group-name.
Definition: IProfiler.h:409
core::array< SProfileData > ProfileDatas
Definition: IProfiler.h:215
u32 addGroup(const core::stringw &name)
Definition: IProfiler.h:377

◆ add() [2/2]

s32 irr::IProfiler::add ( const core::stringw name,
const core::stringw groupName 
)
inline

Add an automatically generated for the given name and group which can be used for profiling with start/stop.

After calling this once you can start/stop profiling with the returned id.

Parameters
nameName for displaying profile data.
groupNameEach id belongs into a group - this helps on displaying profile data.
Returns
Automatic id's start at INT_MAX and count down for each new id. If the name already has an id then that id will be returned.

Definition at line 329 of file IProfiler.h.

330 {
331  u32 index;
332  if ( findDataIndex(index, name) )
333  {
334  add( ProfileDatas[index].Id, name, groupName );
335  return ProfileDatas[index].Id;
336  }
337  else
338  {
339  s32 id = NextAutoId;
340  --NextAutoId;
341  add( id, name, groupName );
342  return id;
343  }
344 }
GLuint id
GLuint const GLchar * name
signed int s32
32 bit signed variable.
Definition: irrTypes.h:70
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
void add(s32 id, const core::stringw &name, const core::stringw &groupName)
Add an id with given name and group which can be used for profiling with start/stop.
Definition: IProfiler.h:346
GLuint index
core::array< SProfileData > ProfileDatas
Definition: IProfiler.h:215
bool findDataIndex(u32 &result, const core::stringw &name) const
Search for the index of the profile data by name.
Definition: IProfiler.h:386

◆ addGroup()

u32 irr::IProfiler::addGroup ( const core::stringw name)
inlineprotected

Definition at line 377 of file IProfiler.h.

378 {
379  SProfileData group;
380  group.Id = -1; // Id for groups doesn't matter so far
381  group.Name = name;
382  ProfileGroups.push_back(group);
383  return ProfileGroups.size()-1;
384 }
GLboolean GLuint group
core::array< SProfileData > ProfileGroups
Definition: IProfiler.h:216
GLuint const GLchar * name

◆ findDataIndex()

bool irr::IProfiler::findDataIndex ( u32 result,
const core::stringw name 
) const
inline

Search for the index of the profile data by name.

Parameters
resultReceives the resulting data index when one was found.
nameString with name to search for
Returns
true when found, false when not found

Definition at line 386 of file IProfiler.h.

387 {
388  for ( u32 i=0; i < ProfileDatas.size(); ++i )
389  {
390  if ( ProfileDatas[i].Name == name )
391  {
392  result = i;
393  return true;
394  }
395  }
396 
397  return false;
398 }
GLuint64EXT * result
GLuint const GLchar * name
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
core::array< SProfileData > ProfileDatas
Definition: IProfiler.h:215

◆ findGroupIndex()

bool irr::IProfiler::findGroupIndex ( u32 result,
const core::stringw name 
) const
inline

Find the group index by the group-name.

Parameters
resultReceives the resulting group index when one was found.
nameString with name to search for
Returns
true when found, false when not found

Definition at line 409 of file IProfiler.h.

410 {
411  for ( u32 i=0; i < ProfileGroups.size(); ++i )
412  {
413  if ( ProfileGroups[i].Name == name )
414  {
415  result = i;
416  return true;
417  }
418  }
419 
420  return false;
421 }
GLuint64EXT * result
core::array< SProfileData > ProfileGroups
Definition: IProfiler.h:216
GLuint const GLchar * name
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62

◆ getGroupCount()

u32 irr::IProfiler::getGroupCount ( ) const
inline

Get the number of profile groups. Will be at least 1.

NOTE: The first groups is always L"overview" which is an overview for all existing groups

Definition at line 152 of file IProfiler.h.

153  {
154  return ProfileGroups.size();
155  }
core::array< SProfileData > ProfileGroups
Definition: IProfiler.h:216

◆ getGroupData()

const SProfileData& irr::IProfiler::getGroupData ( u32  index) const
inline

Get profile data for a group.

NOTE: The first groups is always L"overview" which is an overview for all existing groups

Definition at line 159 of file IProfiler.h.

160  {
161  return ProfileGroups[index];
162  }
core::array< SProfileData > ProfileGroups
Definition: IProfiler.h:216
GLuint index

◆ getProfileDataById()

const SProfileData * irr::IProfiler::getProfileDataById ( u32  id)
inline

Get the profile data.

Parameters
idSame value as used in ::add
Returns
Profile data for the given id or 0 when it does not exist.

Definition at line 400 of file IProfiler.h.

401 {
402  SProfileData data(id);
403  s32 idx = ProfileDatas.binary_search(data);
404  if ( idx >= 0 )
405  return &ProfileDatas[idx];
406  return NULL;
407 }
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
signed int s32
32 bit signed variable.
Definition: irrTypes.h:70
#define NULL
Definition: begin_code.h:167
core::array< SProfileData > ProfileDatas
Definition: IProfiler.h:215

◆ getProfileDataByIndex()

const SProfileData& irr::IProfiler::getProfileDataByIndex ( u32  index) const
inline

Get the profile data.

Parameters
indexA value between 0 and getProfileDataCount()-1. Indices can change when new id's are added.

Definition at line 140 of file IProfiler.h.

141  {
142  return ProfileDatas[index];
143  }
GLuint index
core::array< SProfileData > ProfileDatas
Definition: IProfiler.h:215

◆ getProfileDataCount()

u32 irr::IProfiler::getProfileDataCount ( ) const
inline

Return the number of profile data blocks. There is one for each id.

Definition at line 127 of file IProfiler.h.

128  {
129  return ProfileDatas.size();
130  }
core::array< SProfileData > ProfileDatas
Definition: IProfiler.h:215

◆ printAll()

virtual void irr::IProfiler::printAll ( core::stringw result,
bool  includeOverview = false,
bool  suppressUncalled = true 
) const
pure virtual

Write all profile-data into a string.

Parameters
resultReceives the result string.
includeOverviewWhen true a group-overview is attached first
suppressUncalledWhen true elements which got never called are not printed

◆ printGroup()

virtual void irr::IProfiler::printGroup ( core::stringw result,
u32  groupIndex,
bool  suppressUncalled 
) const
pure virtual

Write the profile data of one group into a string.

Parameters
resultReceives the result string.
groupIndex_

◆ resetAll()

void irr::IProfiler::resetAll ( )
inline

Reset all profile data.

NOTE: This is not deleting id's or groups, just resetting all timers to 0.

Definition at line 455 of file IProfiler.h.

456 {
457  for ( u32 i=0; i<ProfileDatas.size(); ++i )
458  {
459  ProfileDatas[i].reset();
460  }
461 
462  for ( u32 i=0; i<ProfileGroups.size(); ++i )
463  {
464  ProfileGroups[i].reset();
465  }
466 }
core::array< SProfileData > ProfileGroups
Definition: IProfiler.h:216
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
core::array< SProfileData > ProfileDatas
Definition: IProfiler.h:215

◆ resetDataById()

void irr::IProfiler::resetDataById ( s32  id)
inline

Reset profile data for the given id.

Definition at line 423 of file IProfiler.h.

424 {
425  s32 idx = ProfileDatas.binary_search(SProfileData(id));
426  if ( idx >= 0 )
427  {
428  resetDataByIndex((u32)idx);
429  }
430 }
signed int s32
32 bit signed variable.
Definition: irrTypes.h:70
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
void resetDataByIndex(u32 index)
Reset profile data for the given index.
Definition: IProfiler.h:432
core::array< SProfileData > ProfileDatas
Definition: IProfiler.h:215

◆ resetDataByIndex()

void irr::IProfiler::resetDataByIndex ( u32  index)
inline

Reset profile data for the given index.

Definition at line 432 of file IProfiler.h.

433 {
434  SProfileData &data = ProfileDatas[index];
435 
436  SProfileData & group = ProfileGroups[data.GroupIndex];
437  group.CountCalls -= data.CountCalls;
438  group.TimeSum -= data.TimeSum;
439 
440  data.reset();
441 }
GLboolean GLuint group
core::array< SProfileData > ProfileGroups
Definition: IProfiler.h:216
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
GLuint index
core::array< SProfileData > ProfileDatas
Definition: IProfiler.h:215

◆ resetGroup()

void irr::IProfiler::resetGroup ( u32  index)
inline

Reset profile data for a whole group.

Definition at line 444 of file IProfiler.h.

445 {
446  for ( u32 i=0; i<ProfileDatas.size(); ++i )
447  {
448  if ( ProfileDatas[i].GroupIndex == index )
449  ProfileDatas[i].reset();
450  }
451  if ( index < ProfileGroups.size() )
453 }
core::array< SProfileData > ProfileGroups
Definition: IProfiler.h:216
GLboolean reset
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLuint index
core::array< SProfileData > ProfileDatas
Definition: IProfiler.h:215

◆ start()

void irr::IProfiler::start ( s32  id)
inline

Start profile-timing for the given id.

This increases an internal run-counter for the given id. It will profile as long as that counter is > 0. NOTE: you have to add the id first with one of the ::add functions

Definition at line 281 of file IProfiler.h.

282 {
283  s32 idx = ProfileDatas.binary_search(SProfileData(id));
284  if ( idx >= 0 && Timer )
285  {
286  ++ProfileDatas[idx].StartStopCounter;
287  if (ProfileDatas[idx].StartStopCounter == 1 )
288  ProfileDatas[idx].LastTimeStarted = Timer->getRealTime();
289  }
290 }
ITimer * Timer
Definition: IProfiler.h:214
signed int s32
32 bit signed variable.
Definition: irrTypes.h:70
virtual u32 getRealTime() const =0
Returns current real time in milliseconds of the system.
core::array< SProfileData > ProfileDatas
Definition: IProfiler.h:215

◆ stop()

void irr::IProfiler::stop ( s32  id)
inline

Stop profile-timing for the given id.

This increases an internal run-counter for the given id. If it reaches 0 the time since start is recorded. You should have the same amount of start and stop calls. If stop is called more often than start then the additional stop calls will be ignored (counter never goes below 0)

Definition at line 292 of file IProfiler.h.

293 {
294  if ( Timer )
295  {
296  u32 timeNow = Timer->getRealTime();
297  s32 idx = ProfileDatas.binary_search(SProfileData(id));
298  if ( idx >= 0 )
299  {
300  SProfileData &data = ProfileDatas[idx];
301  --ProfileDatas[idx].StartStopCounter;
302  if ( data.LastTimeStarted != 0 && ProfileDatas[idx].StartStopCounter == 0)
303  {
304  // update data for this id
305  ++data.CountCalls;
306  u32 diffTime = timeNow - data.LastTimeStarted;
307  data.TimeSum += diffTime;
308  if ( diffTime > data.LongestTime )
309  data.LongestTime = diffTime;
310  data.LastTimeStarted = 0;
311 
312  // update data of it's group
313  SProfileData & group = ProfileGroups[data.GroupIndex];
314  ++group.CountCalls;
315  group.TimeSum += diffTime;
316  if ( diffTime > group.LongestTime )
317  group.LongestTime = diffTime;
318  group.LastTimeStarted = 0;
319  }
320  else if ( ProfileDatas[idx].StartStopCounter < 0 )
321  {
322  // ignore additional stop calls
323  ProfileDatas[idx].StartStopCounter = 0;
324  }
325  }
326  }
327 }
GLboolean GLuint group
core::array< SProfileData > ProfileGroups
Definition: IProfiler.h:216
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
ITimer * Timer
Definition: IProfiler.h:214
signed int s32
32 bit signed variable.
Definition: irrTypes.h:70
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
virtual u32 getRealTime() const =0
Returns current real time in milliseconds of the system.
core::array< SProfileData > ProfileDatas
Definition: IProfiler.h:215

Member Data Documentation

◆ ProfileDatas

core::array<SProfileData> irr::IProfiler::ProfileDatas
protected

Definition at line 215 of file IProfiler.h.

◆ ProfileGroups

core::array<SProfileData> irr::IProfiler::ProfileGroups
protected

Definition at line 216 of file IProfiler.h.

◆ Timer

ITimer* irr::IProfiler::Timer
protected

Definition at line 214 of file IProfiler.h.


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