]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/CProfiler.cpp
Fix some more problems with OSX build file.
[irrlicht.git] / source / Irrlicht / CProfiler.cpp
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
4 \r
5 #include "CProfiler.h"\r
6 #include "CTimer.h"\r
7 \r
8 namespace irr\r
9 {\r
10 IRRLICHT_API IProfiler& IRRCALLCONV getProfiler()\r
11 {\r
12         static CProfiler profiler;\r
13         return profiler;\r
14 }\r
15 \r
16 CProfiler::CProfiler()\r
17 {\r
18         Timer = new CTimer(true);\r
19 \r
20         addGroup(L"overview");\r
21 }\r
22 \r
23 CProfiler::~CProfiler()\r
24 {\r
25         if ( Timer )\r
26                 Timer->drop();\r
27 }\r
28 \r
29 void CProfiler::printAll(core::stringw &ostream, bool includeOverview, bool suppressUncalled) const\r
30 {\r
31     ostream += makeTitleString();\r
32     ostream += L"\n";\r
33         for ( u32 i=includeOverview ?0:1; i<ProfileGroups.size(); ++i )\r
34     {\r
35         printGroup( ostream, i, suppressUncalled );\r
36     }\r
37 }\r
38 \r
39 void CProfiler::printGroup(core::stringw &ostream, u32 idxGroup, bool suppressUncalled) const\r
40 {\r
41     ostream += getAsString(ProfileGroups[idxGroup]);\r
42     ostream += L"\n";\r
43 \r
44         // print overview for groups\r
45     if ( idxGroup == 0 )\r
46     {\r
47                 for ( u32 i=0; i<ProfileGroups.size(); ++i )\r
48         {\r
49                         if ( !suppressUncalled || ProfileGroups[i].getCallsCounter() > 0)\r
50             {\r
51                 ostream += getAsString(ProfileGroups[i]);\r
52                 ostream += L"\n";\r
53             }\r
54         }\r
55     }\r
56         // print all data in a group\r
57     else\r
58     {\r
59                 for ( u32 i=0; i<ProfileDatas.size(); ++i )\r
60         {\r
61                         if ( (!suppressUncalled || ProfileDatas[i].getCallsCounter() > 0)\r
62                                 && ProfileDatas[i].getGroupIndex() == idxGroup )\r
63             {\r
64                 ostream += getAsString(ProfileDatas[i]);\r
65                 ostream += L"\n";\r
66             }\r
67         }\r
68     }\r
69 }\r
70 \r
71 //! Convert the whole data into a string\r
72 core::stringw CProfiler::getAsString(const SProfileData& data) const\r
73 {\r
74         if ( data.getCallsCounter() > 0 )\r
75         {\r
76 #ifdef _MSC_VER\r
77 #pragma warning(disable:4996)   // 'sprintf' was declared deprecated\r
78 #endif\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
81                 char dummy[1023];\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
85                 dummy[1022] = 0;\r
86 \r
87                 return core::stringw(dummy);\r
88 #ifdef _MSC_VER\r
89 #pragma warning(default :4996)  // 'sprintf' was declared deprecated\r
90 #endif\r
91         }\r
92         else\r
93         {\r
94                 return data.getName();\r
95         }\r
96 }\r
97 \r
98 //! Return a string which describes the columns returned by getAsString\r
99 core::stringw CProfiler::makeTitleString() const\r
100 {\r
101         return core::stringw("name           calls       time(sum)   time(avg)   time(max)");\r
102 }\r
103 \r
104 } // namespace irr\r