Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / client / src / profiling.cpp
blobee8f24d310f6ccddd1271208c863d2853726179f
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013-2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "stdpch.h"
21 #include "profiling.h"
23 // NeL includes
24 #include <nel/3d/u_driver.h>
26 // Project includes
27 #include "misc.h"
28 #include "sound_manager.h"
30 ///////////
31 // USING //
32 ///////////
33 using namespace NLMISC;
34 using namespace NL3D;
36 ////////////
37 // EXTERN //
38 ////////////
39 extern UDriver *Driver;
41 /////////////
42 // GLOBALS //
43 /////////////
44 bool Profiling = false; // Are we in Profile mode?
45 uint ProfileNumFrame = 0;
46 bool WantProfiling = false;
47 bool ProfilingVBLock = false;
48 bool WantProfilingVBLock = false;
50 // ********************************************************************
52 /// Test Profiling and run?
53 void testLaunchProfile()
55 if(!WantProfiling)
56 return;
58 // comes from ActionHandler
59 WantProfiling= false;
61 #ifdef _PROFILE_ON_
62 if( !Profiling )
64 // start the bench.
65 NLMISC::CHTimer::startBench();
66 ProfileNumFrame = 0;
67 Driver->startBench();
68 if (SoundMngr)
69 SoundMngr->getMixer()->startDriverBench();
70 // state
71 Profiling= true;
73 else
75 // end the bench.
76 if (SoundMngr)
77 SoundMngr->getMixer()->endDriverBench();
78 NLMISC::CHTimer::endBench();
79 Driver->endBench();
82 // Display and save profile to a File.
83 CLog log;
84 CFileDisplayer fileDisplayer(NLMISC::CFile::findNewFile(getLogDirectory() + "profile.log"));
85 CStdDisplayer stdDisplayer;
86 log.addDisplayer(&fileDisplayer);
87 log.addDisplayer(&stdDisplayer);
88 // diplay
89 NLMISC::CHTimer::displayHierarchicalByExecutionPathSorted(&log, CHTimer::TotalTime, true, 48, 2);
90 NLMISC::CHTimer::displayHierarchical(&log, true, 48, 2);
91 NLMISC::CHTimer::displayByExecutionPath(&log, CHTimer::TotalTime);
92 NLMISC::CHTimer::display(&log, CHTimer::TotalTime);
93 NLMISC::CHTimer::display(&log, CHTimer::TotalTimeWithoutSons);
94 Driver->displayBench(&log);
96 if (SoundMngr)
97 SoundMngr->getMixer()->displayDriverBench(&log);
99 // state
100 Profiling= false;
102 #endif // #ifdef _PROFILE_ON_
105 // ********************************************************************
107 /// Test ProfilingVBLock and run?
108 void testLaunchProfileVBLock()
110 // If running, must stop for this frame.
111 if(ProfilingVBLock)
113 std::vector<string> strs;
114 Driver->endProfileVBHardLock(strs);
115 nlinfo("Profile VBLock");
116 nlinfo("**************");
117 for(uint i=0;i<strs.size();i++)
119 nlinfo(strs[i].c_str());
121 ProfilingVBLock= false;
123 // Display additional info on allocated VBHards
124 nlinfo("VBHard list");
125 nlinfo("**************");
126 Driver->profileVBHardAllocation(strs);
127 for(uint i=0;i<strs.size();i++)
129 nlinfo(strs[i].c_str());
131 strs.clear();
132 Driver->endProfileIBLock(strs);
133 nlinfo("Profile Index Buffer Lock");
134 nlinfo("**************");
135 for(uint i=0;i<strs.size();i++)
137 nlinfo(strs[i].c_str());
139 ProfilingVBLock= false;
141 // Display additional info on allocated VBHards
143 nlinfo("Index Buffer list");
144 nlinfo("**************");
145 Driver->profileIBAllocation(strs);
146 for(uint i=0;i<strs.size();i++)
148 nlinfo(strs[i].c_str());
153 // comes from ActionHandler
154 if(WantProfilingVBLock)
156 WantProfilingVBLock= false;
157 ProfilingVBLock= true;
158 Driver->startProfileVBHardLock();
159 Driver->startProfileIBLock();
163 /* end of file */