5#ifndef NIRT_I_PROFILER_HPP_INCLUDED
6#define NIRT_I_PROFILER_HPP_INCLUDED
8#include <nirtcpp/core/engine/NirtCompileConfig.hpp>
9#include <nirtcpp/core/engine/irrString.hpp>
10#include <nirtcpp/core/engine/irrArray.hpp>
11#include <nirtcpp/core/engine/ITimer.hpp>
43 u32 getGroupIndex()
const
132 return ProfileDatas.size();
145 return ProfileDatas[index];
157 return ProfileGroups.size();
164 return ProfileGroups[index];
256 Profiler.
add(Id, name, groupName);
267 Id = Profiler.
add(name, groupName);
287 if ( idx >= 0 && Timer )
289 ++ProfileDatas[idx].StartStopCounter;
290 if (ProfileDatas[idx].StartStopCounter == 1 )
291 ProfileDatas[idx].LastTimeStarted = Timer->
getRealTime();
304 --ProfileDatas[idx].StartStopCounter;
305 if ( data.LastTimeStarted != 0 && ProfileDatas[idx].StartStopCounter == 0)
309 const u32 diffTime = timeNow - data.LastTimeStarted;
310 data.TimeSum += diffTime;
311 if ( diffTime > data.LongestTime )
312 data.LongestTime = diffTime;
313 data.LastTimeStarted = 0;
318 group.TimeSum += diffTime;
319 if ( diffTime > group.LongestTime )
320 group.LongestTime = diffTime;
321 group.LastTimeStarted = 0;
323 else if ( ProfileDatas[idx].StartStopCounter < 0 )
326 ProfileDatas[idx].StartStopCounter = 0;
337 add( ProfileDatas[index].Id, name, groupName );
338 return ProfileDatas[index].Id;
342 const s32 id = NextAutoId;
344 add(
id, name, groupName );
354 groupIdx = addGroup(groupName);
358 s32 idx = ProfileDatas.binary_search(data);
362 data.GroupIndex = groupIdx;
365 ProfileDatas.push_back(data);
371 if ( groupIdx != ProfileDatas[idx].GroupIndex )
374 ProfileDatas[idx].GroupIndex = groupIdx;
376 ProfileDatas[idx].Name = name;
385 ProfileGroups.push_back(group);
386 return ProfileGroups.size()-1;
391 for (
u32 i=0; i < ProfileDatas.size(); ++i )
393 if ( ProfileDatas[i].Name == name )
406 const s32 idx = ProfileDatas.binary_search(data);
408 return &ProfileDatas[idx];
414 for (
u32 i=0; i < ProfileGroups.size(); ++i )
416 if ( ProfileGroups[i].Name == name )
440 group.CountCalls -= data.CountCalls;
441 group.TimeSum -= data.TimeSum;
449 for (
u32 i=0; i<ProfileDatas.size(); ++i )
451 if ( ProfileDatas[i].GroupIndex == index )
452 ProfileDatas[i].
reset();
454 if ( index < ProfileGroups.size() )
455 ProfileGroups[index].
reset();
460 for (
u32 i=0; i<ProfileDatas.size(); ++i )
462 ProfileDatas[i].
reset();
465 for (
u32 i=0; i<ProfileGroups.size(); ++i )
467 ProfileGroups[i].
reset();
475#ifdef _NIRT_COMPILE_WITH_PROFILING_
476 #define NIRT_PROFILE(X) X
478 #define NIRT_PROFILE(X)
Class where the objects profile their own life-time.
Definition IProfiler.hpp:237
CProfileScope(s32 id)
Construct with an known id.
Definition IProfiler.hpp:242
CProfileScope(s32 id, const core::stringw &name, const core::stringw &groupName)
Object will create the given name, groupName combination for the id if it doesn't exist already.
Definition IProfiler.hpp:253
CProfileScope(const core::stringw &name, const core::stringw &groupName)
Object will create an id for the given name, groupName combination if they don't exist already.
Definition IProfiler.hpp:264
Code-profiler. Please check the example in the Nirtcpp examples folder about how to use it.
Definition IProfiler.hpp:105
const SProfileData & getGroupData(u32 index) const
Get profile data for a group.
Definition IProfiler.hpp:162
void resetGroup(u32 index)
Reset profile data for a whole group.
Definition IProfiler.hpp:447
u32 getProfileDataCount() const
Return the number of profile data blocks. There is one for each id.
Definition IProfiler.hpp:130
bool findGroupIndex(u32 &result, const core::stringw &name) const
Find the group index by the group-name.
Definition IProfiler.hpp:412
const SProfileData * getProfileDataById(u32 id)
Get the profile data.
Definition IProfiler.hpp:403
void stop(s32 id)
Stop profile-timing for the given id.
Definition IProfiler.hpp:295
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.hpp:349
void start(s32 id)
Start profile-timing for the given id.
Definition IProfiler.hpp:284
bool findDataIndex(u32 &result, const core::stringw &name) const
Search for the index of the profile data by name.
Definition IProfiler.hpp:389
const SProfileData & getProfileDataByIndex(u32 index) const
Get the profile data.
Definition IProfiler.hpp:143
IProfiler()
Constructor. You could use this to create a new profiler, but usually getProfiler() is used to access...
Definition IProfiler.hpp:108
void resetAll()
Reset all profile data.
Definition IProfiler.hpp:458
void resetDataByIndex(u32 index)
Reset profile data for the given index.
Definition IProfiler.hpp:435
virtual void printGroup(core::stringw &result, u32 groupIndex, bool suppressUncalled) const =0
Write the profile data of one group into a string.
void resetDataById(s32 id)
Reset profile data for the given id.
Definition IProfiler.hpp:426
u32 getGroupCount() const
Get the number of profile groups. Will be at least 1.
Definition IProfiler.hpp:155
virtual void printAll(core::stringw &result, bool includeOverview=false, bool suppressUncalled=true) const =0
Write all profile-data into a string.
Interface for getting and manipulating the virtual time.
Definition ITimer.hpp:15
virtual u32 getRealTime() const =0
Returns current real time in milliseconds of the system.
Used to store the profile data (and also used for profile group data).
Definition IProfiler.hpp:21
u32 getLongestTime() const
Longest time a profile call for this id took from start until it was stopped again.
Definition IProfiler.hpp:60
u32 getCallsCounter() const
Each time profiling for this data is stopped it increases the counter by 1.
Definition IProfiler.hpp:54
u32 getTimeSum() const
Time spend between start/stop.
Definition IProfiler.hpp:66
Axis aligned bounding box in 3d dimensional space.
Definition aabbox3d.hpp:22
void reset(T x, T y, T z)
Resets the bounding box to a one-point box.
Definition aabbox3d.hpp:50
Very simple string class with some useful features.
Definition irrString.hpp:94
string< wchar_t > stringw
using type alias for wide character strings
Definition irrString.hpp:1460
As of Nirtcpp 1.6, position2d is a synonym for vector2d.
Definition vector3d.hpp:11
signed int s32
32 bit signed variable.
Definition irrTypes.hpp:72
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.hpp:64
NIRTCPP_API IProfiler &IRRCALLCONV getProfiler()
Access the Nirtcpp profiler object.