Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
CProfiler2 Class Reference

#include <Profiler2.h>

Collaboration diagram for CProfiler2:

Classes

struct  SItem_dt_id
 An item with a relative time and an ID string pointer. More...
 
class  ThreadStorage
 Class instantiated in every registered thread. More...
 

Public Types

enum  EItem {
  ITEM_NOP = 0 , ITEM_SYNC = 1 , ITEM_EVENT = 2 , ITEM_ENTER = 3 ,
  ITEM_LEAVE = 4 , ITEM_ATTRIBUTE = 5
}
 Item type identifiers. More...
 

Public Member Functions

 CProfiler2 ()
 
 ~CProfiler2 ()
 
void Initialise ()
 Call in main thread to set up the profiler, before calling any other profiler functions. More...
 
void EnableHTTP ()
 Call in main thread to enable the HTTP server. More...
 
void EnableGPU ()
 Call in main thread to enable the GPU profiling support, after OpenGL has been initialised. More...
 
void ShutdownGPU ()
 Call in main thread to shut down the GPU profiling support, before shutting down OpenGL. More...
 
void ShutDownHTTP ()
 Call in main thread to shut down the profiler's HTTP server. More...
 
void Toggle ()
 Call in main thread to enable/disable the profiler. More...
 
void Shutdown ()
 Call in main thread to shut everything down. More...
 
void RegisterCurrentThread (const std::string &name)
 Call in any thread to enable the profiler in that thread. More...
 
void RecordSyncMarker ()
 Non-main threads should call this occasionally, especially if it's been a long time since their last call to the profiler, or if they've made thousands of calls since the last sync marker. More...
 
void RecordFrameStart ()
 Call in main thread at the start of a frame. More...
 
void RecordEvent (const char *id)
 
void RecordRegionEnter (const char *id)
 
void RecordRegionEnter (const char *id, double time)
 
void RecordRegionLeave ()
 
void RecordAttribute (const char *fmt,...) PRINTF_ARGS(2)
 
void RecordGPUFrameStart ()
 
void RecordGPUFrameEnd ()
 
void RecordGPURegionEnter (const char *id)
 
void RecordGPURegionLeave (const char *id)
 
size_t HoldLevel ()
 Hold onto messages until a call to release or write the held messages. More...
 
u8 HoldType ()
 
void HoldMessages (u8 type)
 
void StopHoldingMessages (bool writeToBuffer, bool condensed=false)
 
void ConstructJSONOverview (std::ostream &stream)
 Call in any thread to produce a JSON representation of the general state of the application. More...
 
const char * ConstructJSONResponse (std::ostream &stream, const std::string &thread)
 Call in any thread to produce a JSON representation of the buffer for a given thread. More...
 
void SaveToFile ()
 Call in any thread to save a JSONP representation of the buffers for all threads, to a file named profile2.jsonp in the logs directory. More...
 
double GetTime ()
 
int GetFrameNumber ()
 
void IncrementFrameNumber ()
 
void AddThreadStorage (ThreadStorage *storage)
 
void RemoveThreadStorage (ThreadStorage *storage)
 

Static Public Attributes

static const size_t MAX_ATTRIBUTE_LENGTH = 256
 
static const u8 RESYNC_MAGIC [8] = {0x11, 0x22, 0x33, 0x44, 0xf4, 0x93, 0xbe, 0x15}
 An arbitrary number to help resyncing with the item stream when parsing. More...
 

Private Member Functions

void InitialiseGPU ()
 
ThreadStorageGetThreadStorage ()
 

Private Attributes

bool m_Initialised
 
int m_FrameNumber
 
mg_context * m_MgContext
 
CProfiler2GPUm_GPU
 
std::mutex m_Mutex
 
std::vector< std::unique_ptr< ThreadStorage > > m_Threads
 

Static Private Attributes

static const size_t BUFFER_SIZE = 4 * 1024 * 1024
 
static const size_t HOLD_BUFFER_SIZE = 128 * 1024
 
static thread_local ThreadStoragem_CurrentStorage = nullptr
 

Friends

class CProfiler2GPUARB
 
class CProfile2SpikeRegion
 
class CProfile2AggregatedRegion
 

Member Enumeration Documentation

◆ EItem

Item type identifiers.

Enumerator
ITEM_NOP 
ITEM_SYNC 
ITEM_EVENT 
ITEM_ENTER 
ITEM_LEAVE 
ITEM_ATTRIBUTE 

Constructor & Destructor Documentation

◆ CProfiler2()

CProfiler2::CProfiler2 ( )

◆ ~CProfiler2()

CProfiler2::~CProfiler2 ( )

Member Function Documentation

◆ AddThreadStorage()

void CProfiler2::AddThreadStorage ( ThreadStorage storage)

◆ ConstructJSONOverview()

void CProfiler2::ConstructJSONOverview ( std::ostream &  stream)

Call in any thread to produce a JSON representation of the general state of the application.

◆ ConstructJSONResponse()

const char * CProfiler2::ConstructJSONResponse ( std::ostream &  stream,
const std::string &  thread 
)

Call in any thread to produce a JSON representation of the buffer for a given thread.

Returns NULL on success, or an error string.

◆ EnableGPU()

void CProfiler2::EnableGPU ( )

Call in main thread to enable the GPU profiling support, after OpenGL has been initialised.

◆ EnableHTTP()

void CProfiler2::EnableHTTP ( )

Call in main thread to enable the HTTP server.

(Disabled by default for security and performance and to avoid annoying a firewall.)

◆ GetFrameNumber()

int CProfiler2::GetFrameNumber ( )
inline

◆ GetThreadStorage()

ThreadStorage & CProfiler2::GetThreadStorage ( )
inlineprivate

◆ GetTime()

double CProfiler2::GetTime ( )
inline

◆ HoldLevel()

size_t CProfiler2::HoldLevel ( )
inline

Hold onto messages until a call to release or write the held messages.

◆ HoldMessages()

void CProfiler2::HoldMessages ( u8  type)
inline

◆ HoldType()

u8 CProfiler2::HoldType ( )
inline

◆ IncrementFrameNumber()

void CProfiler2::IncrementFrameNumber ( )
inline

◆ Initialise()

void CProfiler2::Initialise ( )

Call in main thread to set up the profiler, before calling any other profiler functions.

◆ InitialiseGPU()

void CProfiler2::InitialiseGPU ( )
private

◆ RecordAttribute()

void CProfiler2::RecordAttribute ( const char *  fmt,
  ... 
)
inline

◆ RecordEvent()

void CProfiler2::RecordEvent ( const char *  id)
inline

◆ RecordFrameStart()

void CProfiler2::RecordFrameStart ( )
inline

Call in main thread at the start of a frame.

◆ RecordGPUFrameEnd()

void CProfiler2::RecordGPUFrameEnd ( )

◆ RecordGPUFrameStart()

void CProfiler2::RecordGPUFrameStart ( )

◆ RecordGPURegionEnter()

void CProfiler2::RecordGPURegionEnter ( const char *  id)

◆ RecordGPURegionLeave()

void CProfiler2::RecordGPURegionLeave ( const char *  id)

◆ RecordRegionEnter() [1/2]

void CProfiler2::RecordRegionEnter ( const char *  id)
inline

◆ RecordRegionEnter() [2/2]

void CProfiler2::RecordRegionEnter ( const char *  id,
double  time 
)
inline

◆ RecordRegionLeave()

void CProfiler2::RecordRegionLeave ( )
inline

◆ RecordSyncMarker()

void CProfiler2::RecordSyncMarker ( )
inline

Non-main threads should call this occasionally, especially if it's been a long time since their last call to the profiler, or if they've made thousands of calls since the last sync marker.

◆ RegisterCurrentThread()

void CProfiler2::RegisterCurrentThread ( const std::string &  name)

Call in any thread to enable the profiler in that thread.

name should be unique, and is used by the visualiser to identify this thread.

◆ RemoveThreadStorage()

void CProfiler2::RemoveThreadStorage ( ThreadStorage storage)

◆ SaveToFile()

void CProfiler2::SaveToFile ( )

Call in any thread to save a JSONP representation of the buffers for all threads, to a file named profile2.jsonp in the logs directory.

◆ Shutdown()

void CProfiler2::Shutdown ( )

Call in main thread to shut everything down.

All other profiled threads should have been terminated already.

◆ ShutdownGPU()

void CProfiler2::ShutdownGPU ( )

Call in main thread to shut down the GPU profiling support, before shutting down OpenGL.

◆ ShutDownHTTP()

void CProfiler2::ShutDownHTTP ( )

Call in main thread to shut down the profiler's HTTP server.

◆ StopHoldingMessages()

void CProfiler2::StopHoldingMessages ( bool  writeToBuffer,
bool  condensed = false 
)
inline

◆ Toggle()

void CProfiler2::Toggle ( )

Call in main thread to enable/disable the profiler.

Friends And Related Function Documentation

◆ CProfile2AggregatedRegion

friend class CProfile2AggregatedRegion
friend

◆ CProfile2SpikeRegion

friend class CProfile2SpikeRegion
friend

◆ CProfiler2GPUARB

friend class CProfiler2GPUARB
friend

Member Data Documentation

◆ BUFFER_SIZE

const size_t CProfiler2::BUFFER_SIZE = 4 * 1024 * 1024
staticprivate

◆ HOLD_BUFFER_SIZE

const size_t CProfiler2::HOLD_BUFFER_SIZE = 128 * 1024
staticprivate

◆ m_CurrentStorage

thread_local CProfiler2::ThreadStorage * CProfiler2::m_CurrentStorage = nullptr
staticprivate

◆ m_FrameNumber

int CProfiler2::m_FrameNumber
private

◆ m_GPU

CProfiler2GPU* CProfiler2::m_GPU
private

◆ m_Initialised

bool CProfiler2::m_Initialised
private

◆ m_MgContext

mg_context* CProfiler2::m_MgContext
private

◆ m_Mutex

std::mutex CProfiler2::m_Mutex
private

◆ m_Threads

std::vector<std::unique_ptr<ThreadStorage> > CProfiler2::m_Threads
private

◆ MAX_ATTRIBUTE_LENGTH

const size_t CProfiler2::MAX_ATTRIBUTE_LENGTH = 256
static

◆ RESYNC_MAGIC

const u8 CProfiler2::RESYNC_MAGIC = {0x11, 0x22, 0x33, 0x44, 0xf4, 0x93, 0xbe, 0x15}
static

An arbitrary number to help resyncing with the item stream when parsing.


The documentation for this class was generated from the following files: