Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/ps/Profiler2.h
Show First 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | |||||
* The initial setup of g_Profiler2 must happen in the game's main thread. | * The initial setup of g_Profiler2 must happen in the game's main thread. | ||||
* RegisterCurrentThread and the Record functions may be called from any thread. | * RegisterCurrentThread and the Record functions may be called from any thread. | ||||
* The HTTP server runs its own threads, which may call the ConstructJSON functions. | * The HTTP server runs its own threads, which may call the ConstructJSON functions. | ||||
*/ | */ | ||||
#ifndef INCLUDED_PROFILER2 | #ifndef INCLUDED_PROFILER2 | ||||
#define INCLUDED_PROFILER2 | #define INCLUDED_PROFILER2 | ||||
#include <map> | |||||
#include <thread> | |||||
#include "lib/timer.h" | #include "lib/timer.h" | ||||
#include "ps/ThreadUtil.h" | #include "ps/ThreadUtil.h" | ||||
#include <mutex> | #include <mutex> | ||||
struct mg_context; | struct mg_context; | ||||
// Note: Lots of functions are defined inline, to hypothetically | // Note: Lots of functions are defined inline, to hypothetically | ||||
▲ Show 20 Lines • Show All 342 Lines • ▼ Show 20 Lines | public: | ||||
} | } | ||||
void AddThreadStorage(ThreadStorage* storage); | void AddThreadStorage(ThreadStorage* storage); | ||||
void RemoveThreadStorage(ThreadStorage* storage); | void RemoveThreadStorage(ThreadStorage* storage); | ||||
private: | private: | ||||
void InitialiseGPU(); | void InitialiseGPU(); | ||||
static void TLSDtor(void* data); | |||||
ThreadStorage& GetThreadStorage() | ThreadStorage& GetThreadStorage() | ||||
{ | { | ||||
ThreadStorage* storage = (ThreadStorage*)pthread_getspecific(m_TLS); | ENSURE(m_CurrentStorage); | ||||
ASSERT(storage); | return *m_CurrentStorage; | ||||
return *storage; | |||||
} | } | ||||
bool m_Initialised; | bool m_Initialised; | ||||
int m_FrameNumber; | int m_FrameNumber; | ||||
mg_context* m_MgContext; | mg_context* m_MgContext; | ||||
pthread_key_t m_TLS; | |||||
CProfiler2GPU* m_GPU; | CProfiler2GPU* m_GPU; | ||||
std::mutex m_Mutex; | std::mutex m_Mutex; | ||||
std::vector<ThreadStorage*> m_Threads; // thread-safe; protected by m_Mutex | |||||
static thread_local ThreadStorage* m_CurrentStorage; | |||||
std::vector<std::unique_ptr<ThreadStorage>> m_Threads; // thread-safe; protected by m_Mutex | |||||
}; | }; | ||||
extern CProfiler2 g_Profiler2; | extern CProfiler2 g_Profiler2; | ||||
/** | /** | ||||
* Scope-based enter/leave helper. | * Scope-based enter/leave helper. | ||||
*/ | */ | ||||
class CProfile2Region | class CProfile2Region | ||||
▲ Show 20 Lines • Show All 91 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator