Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/ps/Profile.h
Show All 19 Lines | |||||
*/ | */ | ||||
#ifndef INCLUDED_PROFILE | #ifndef INCLUDED_PROFILE | ||||
#define INCLUDED_PROFILE | #define INCLUDED_PROFILE | ||||
#include <vector> | #include <vector> | ||||
#include "lib/adts/ring_buf.h" | #include "lib/adts/ring_buf.h" | ||||
#include "lib/posix/posix_pthread.h" | |||||
#include "ps/Profiler2.h" | #include "ps/Profiler2.h" | ||||
#include "ps/Singleton.h" | #include "ps/Singleton.h" | ||||
#include "ps/ThreadUtil.h" | |||||
#include <boost/flyweight.hpp> | #include <boost/flyweight.hpp> | ||||
#include <boost/flyweight/key_value.hpp> | #include <boost/flyweight/key_value.hpp> | ||||
#include <boost/flyweight/no_locking.hpp> | #include <boost/flyweight/no_locking.hpp> | ||||
#include <boost/flyweight/no_tracking.hpp> | #include <boost/flyweight/no_tracking.hpp> | ||||
#define PROFILE_AMORTIZE_FRAMES 30 | #define PROFILE_AMORTIZE_FRAMES 30 | ||||
#define PROFILE_AMORTIZE_TURNS 1 | #define PROFILE_AMORTIZE_TURNS 1 | ||||
▲ Show 20 Lines • Show All 130 Lines • ▼ Show 20 Lines | private: | ||||
void PerformStructuralReset(); | void PerformStructuralReset(); | ||||
}; | }; | ||||
#define g_Profiler CProfileManager::GetSingleton() | #define g_Profiler CProfileManager::GetSingleton() | ||||
class CProfileSample | class CProfileSample | ||||
{ | { | ||||
public: | public: | ||||
CProfileSample(const char* name) | CProfileSample(const char* name); | ||||
{ | ~CProfileSample(); | ||||
if (CProfileManager::IsInitialised()) | |||||
{ | |||||
// The profiler is only safe to use on the main thread | |||||
if(ThreadUtil::IsMainThread()) | |||||
g_Profiler.Start(name); | |||||
} | |||||
} | |||||
~CProfileSample() | |||||
{ | |||||
if (CProfileManager::IsInitialised()) | |||||
if(ThreadUtil::IsMainThread()) | |||||
g_Profiler.Stop(); | |||||
} | |||||
}; | |||||
class CProfileSampleScript | |||||
{ | |||||
public: | |||||
CProfileSampleScript( const char* name ) | |||||
{ | |||||
if (CProfileManager::IsInitialised()) | |||||
{ | |||||
// The profiler is only safe to use on the main thread, | |||||
// but scripts get run on other threads too so we need to | |||||
// conditionally enable the profiler. | |||||
// (This usually only gets used in debug mode so performance | |||||
// doesn't matter much.) | |||||
if (ThreadUtil::IsMainThread()) | |||||
g_Profiler.StartScript( name ); | |||||
} | |||||
} | |||||
~CProfileSampleScript() | |||||
{ | |||||
if (CProfileManager::IsInitialised()) | |||||
if (ThreadUtil::IsMainThread()) | |||||
g_Profiler.Stop(); | |||||
} | |||||
}; | }; | ||||
// Put a PROFILE("xyz") block at the start of all code to be profiled. | // Put a PROFILE("xyz") block at the start of all code to be profiled. | ||||
// Profile blocks last until the end of the containing scope. | // Profile blocks last until the end of the containing scope. | ||||
#define PROFILE(name) CProfileSample __profile(name) | #define PROFILE(name) CProfileSample __profile(name) | ||||
// Cheat a bit to make things slightly easier on the user | // Cheat a bit to make things slightly easier on the user | ||||
#define PROFILE_START(name) { CProfileSample __profile(name) | #define PROFILE_START(name) { CProfileSample __profile(name) | ||||
#define PROFILE_END(name) } | #define PROFILE_END(name) } | ||||
// Do both old and new profilers simultaneously (1+2=3), for convenience. | // Do both old and new profilers simultaneously (1+2=3), for convenience. | ||||
#define PROFILE3(name) PROFILE(name); PROFILE2(name) | #define PROFILE3(name) PROFILE(name); PROFILE2(name) | ||||
// Also do GPU | // Also do GPU | ||||
#define PROFILE3_GPU(name) PROFILE(name); PROFILE2(name); PROFILE2_GPU(name) | #define PROFILE3_GPU(name) PROFILE(name); PROFILE2(name); PROFILE2_GPU(name) | ||||
#endif // INCLUDED_PROFILE | #endif // INCLUDED_PROFILE |
Wildfire Games · Phabricator