| 
									
										
										
										
											2014-11-19 19:57:12 +01:00
										 |  |  | // Copyright 2014 Dolphin Emulator Project
 | 
					
						
							|  |  |  | // Licensed under GPLv2+
 | 
					
						
							|  |  |  | // Refer to the license.txt file included.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <list>
 | 
					
						
							| 
									
										
										
										
											2015-08-20 11:41:49 +02:00
										 |  |  | #include <mutex>
 | 
					
						
							| 
									
										
										
										
											2014-11-19 19:57:12 +01:00
										 |  |  | #include <string>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "CommonTypes.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-20 11:41:49 +02:00
										 |  |  | namespace Common | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-11-19 19:57:12 +01:00
										 |  |  | class Profiler | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   Profiler(const std::string& name); | 
					
						
							|  |  |  |   ~Profiler(); | 
					
						
							| 
									
										
										
										
											2014-11-19 19:57:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   static std::string ToString(); | 
					
						
							| 
									
										
										
										
											2014-11-19 19:57:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   void Start(); | 
					
						
							|  |  |  |   void Stop(); | 
					
						
							|  |  |  |   std::string Read(); | 
					
						
							| 
									
										
										
										
											2014-11-19 19:57:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   bool operator<(const Profiler& b) const; | 
					
						
							| 
									
										
										
										
											2015-08-20 11:41:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-19 19:57:12 +01:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   static std::list<Profiler*> s_all_profilers; | 
					
						
							|  |  |  |   static std::mutex s_mutex; | 
					
						
							|  |  |  |   static u32 s_max_length; | 
					
						
							|  |  |  |   static u64 s_frame_time; | 
					
						
							|  |  |  |   static u64 s_usecs_frame; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static std::string s_lazy_result; | 
					
						
							|  |  |  |   static int s_lazy_delay; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   std::string m_name; | 
					
						
							|  |  |  |   u64 m_usecs; | 
					
						
							|  |  |  |   u64 m_usecs_min; | 
					
						
							|  |  |  |   u64 m_usecs_max; | 
					
						
							|  |  |  |   u64 m_usecs_quad; | 
					
						
							|  |  |  |   u64 m_calls; | 
					
						
							|  |  |  |   u64 m_time; | 
					
						
							|  |  |  |   int m_depth; | 
					
						
							| 
									
										
										
										
											2014-11-19 19:57:12 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ProfilerExecuter | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   ProfilerExecuter(Profiler* _p) : m_p(_p) { m_p->Start(); } | 
					
						
							|  |  |  |   ~ProfilerExecuter() { m_p->Stop(); } | 
					
						
							| 
									
										
										
										
											2018-04-12 14:18:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-19 19:57:12 +01:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   Profiler* m_p; | 
					
						
							| 
									
										
										
										
											2014-11-19 19:57:12 +01:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2015-08-20 11:41:49 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-19 19:57:12 +01:00
										 |  |  | // Warning: This profiler isn't thread safe. Only profile functions which doesn't run simultaneously
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | #define PROFILE(name)                                                                              \
 | 
					
						
							|  |  |  |   static Common::Profiler prof_gen(name);                                                          \ | 
					
						
							|  |  |  |   Common::ProfilerExecuter prof_e(&prof_gen); |