Pyrogenesis  trunk
Classes | Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
CProfiler2 Class Reference

#include <Profiler2.h>

Collaboration diagram for CProfiler2:
Collaboration graph
[legend]

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 ()
 

Static Private Member Functions

static void TLSDtor (void *data)
 Called by pthreads when a registered thread is destroyed. More...
 

Private Attributes

bool m_Initialised
 
int m_FrameNumber
 
mg_contextm_MgContext
 
pthread_key_t m_TLS
 
CProfiler2GPUm_GPU
 
CMutex m_Mutex
 
std::vector< ThreadStorage * > m_Threads
 

Static Private Attributes

static const size_t BUFFER_SIZE = 4*1024*1024
 
static const size_t HOLD_BUFFER_SIZE = 128 * 1024
 

Friends

class CProfiler2GPU_base
 
class CProfile2SpikeRegion
 
class CProfile2AggregatedRegion
 

Member Enumeration Documentation

Item type identifiers.

Enumerator
ITEM_NOP 
ITEM_SYNC 
ITEM_EVENT 
ITEM_ENTER 
ITEM_LEAVE 
ITEM_ATTRIBUTE 

Constructor & Destructor Documentation

CProfiler2::CProfiler2 ( )
CProfiler2::~CProfiler2 ( )

Member Function Documentation

void CProfiler2::AddThreadStorage ( ThreadStorage storage)
void CProfiler2::ConstructJSONOverview ( std::ostream &  stream)

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

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.

void CProfiler2::EnableGPU ( )

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

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.)

int CProfiler2::GetFrameNumber ( )
inline
ThreadStorage& CProfiler2::GetThreadStorage ( )
inlineprivate
double CProfiler2::GetTime ( )
inline
size_t CProfiler2::HoldLevel ( )
inline

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

void CProfiler2::HoldMessages ( u8  type)
inline
u8 CProfiler2::HoldType ( )
inline
void CProfiler2::IncrementFrameNumber ( )
inline
void CProfiler2::Initialise ( )

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

void CProfiler2::InitialiseGPU ( )
private
void CProfiler2::RecordAttribute ( const char *  fmt,
  ... 
)
inline
void CProfiler2::RecordEvent ( const char *  id)
inline
void CProfiler2::RecordFrameStart ( )
inline

Call in main thread at the start of a frame.

void CProfiler2::RecordGPUFrameEnd ( )
void CProfiler2::RecordGPUFrameStart ( )
void CProfiler2::RecordGPURegionEnter ( const char *  id)
void CProfiler2::RecordGPURegionLeave ( const char *  id)
void CProfiler2::RecordRegionEnter ( const char *  id)
inline
void CProfiler2::RecordRegionEnter ( const char *  id,
double  time 
)
inline
void CProfiler2::RecordRegionLeave ( )
inline
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.

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.

void CProfiler2::RemoveThreadStorage ( ThreadStorage storage)
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.

void CProfiler2::Shutdown ( void  )

Call in main thread to shut everything down.

All other profiled threads should have been terminated already.

void CProfiler2::ShutdownGPU ( )

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

void CProfiler2::ShutDownHTTP ( )

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

void CProfiler2::StopHoldingMessages ( bool  writeToBuffer,
bool  condensed = false 
)
inline
void CProfiler2::TLSDtor ( void *  data)
staticprivate

Called by pthreads when a registered thread is destroyed.

void CProfiler2::Toggle ( )

Call in main thread to enable/disable the profiler.

Friends And Related Function Documentation

friend class CProfile2AggregatedRegion
friend
friend class CProfile2SpikeRegion
friend
friend class CProfiler2GPU_base
friend

Member Data Documentation

const size_t CProfiler2::BUFFER_SIZE = 4*1024*1024
staticprivate
const size_t CProfiler2::HOLD_BUFFER_SIZE = 128 * 1024
staticprivate
int CProfiler2::m_FrameNumber
private
CProfiler2GPU* CProfiler2::m_GPU
private
bool CProfiler2::m_Initialised
private
mg_context* CProfiler2::m_MgContext
private
CMutex CProfiler2::m_Mutex
private
std::vector<ThreadStorage*> CProfiler2::m_Threads
private
pthread_key_t CProfiler2::m_TLS
private
const size_t CProfiler2::MAX_ATTRIBUTE_LENGTH = 256
static
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: