1 // This file is part of the "Irrlicht Engine".
\r
2 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
3 // Written by Michael Zeilfelder
\r
5 #include "CProfiler.h"
\r
10 IRRLICHT_API IProfiler& IRRCALLCONV getProfiler()
\r
12 static CProfiler profiler;
\r
16 CProfiler::CProfiler()
\r
18 Timer = new CTimer(true);
\r
20 addGroup(L"overview");
\r
23 CProfiler::~CProfiler()
\r
29 void CProfiler::printAll(core::stringw &ostream, bool includeOverview, bool suppressUncalled) const
\r
31 ostream += makeTitleString();
\r
33 for ( u32 i=includeOverview ?0:1; i<ProfileGroups.size(); ++i )
\r
35 printGroup( ostream, i, suppressUncalled );
\r
39 void CProfiler::printGroup(core::stringw &ostream, u32 idxGroup, bool suppressUncalled) const
\r
41 ostream += getAsString(ProfileGroups[idxGroup]);
\r
44 // print overview for groups
\r
45 if ( idxGroup == 0 )
\r
47 for ( u32 i=0; i<ProfileGroups.size(); ++i )
\r
49 if ( !suppressUncalled || ProfileGroups[i].getCallsCounter() > 0)
\r
51 ostream += getAsString(ProfileGroups[i]);
\r
56 // print all data in a group
\r
59 for ( u32 i=0; i<ProfileDatas.size(); ++i )
\r
61 if ( (!suppressUncalled || ProfileDatas[i].getCallsCounter() > 0)
\r
62 && ProfileDatas[i].getGroupIndex() == idxGroup )
\r
64 ostream += getAsString(ProfileDatas[i]);
\r
71 //! Convert the whole data into a string
\r
72 core::stringw CProfiler::getAsString(const SProfileData& data) const
\r
74 if ( data.getCallsCounter() > 0 )
\r
77 #pragma warning(disable:4996) // 'sprintf' was declared deprecated
\r
79 // Can't use swprintf as it fails on some platforms (especially mobile platforms)
\r
80 // Can't use Irrlicht functions because we have no string formatting.
\r
82 sprintf(dummy, "%-15.15s%-12u%-12u%-12u%-12u",
\r
83 core::stringc(data.getName()).c_str(), data.getCallsCounter(), data.getTimeSum(),
\r
84 data.getTimeSum() / data.getCallsCounter(), data.getLongestTime());
\r
87 return core::stringw(dummy);
\r
89 #pragma warning(default :4996) // 'sprintf' was declared deprecated
\r
94 return data.getName();
\r
98 //! Return a string which describes the columns returned by getAsString
\r
99 core::stringw CProfiler::makeTitleString() const
\r
101 return core::stringw("name calls time(sum) time(avg) time(max)");
\r