78#ifndef INCLUDED_PROFILER2
79#define INCLUDED_PROFILER2
163 Write(type, &item,
sizeof(item));
536#define PROFILE2(region) CProfile2Region profile2__(region)
538#define PROFILE2_IFSPIKE(region, limit) CProfile2SpikeRegion profile2__(region, limit)
540#define PROFILE2_AGGREGATED(region, limit) CProfile2AggregatedRegion profile2__(region, limit)
542#define PROFILE2_GPU(region) CProfile2GPURegion profile2gpu__(region)
547#define PROFILE2_EVENT(name) g_Profiler2.RecordEvent(name)
555#define PROFILE2_ATTR g_Profiler2.RecordAttribute
CProfiler2 g_Profiler2
Definition: Profiler2.cpp:44
Scope-based enter/leave helper.
Definition: Profiler2.h:500
const char * m_Name
Definition: Profiler2.h:505
CProfile2AggregatedRegion(const char *name, double spikeLimit)
Definition: Profiler2.cpp:980
bool m_PushedHold
Definition: Profiler2.h:508
~CProfile2AggregatedRegion()
Definition: Profiler2.cpp:991
double m_Limit
Definition: Profiler2.h:506
double m_StartTime
Definition: Profiler2.h:507
Scope-based GPU enter/leave helper.
Definition: Profiler2.h:515
const char * m_Name
Definition: Profiler2.h:526
~CProfile2GPURegion()
Definition: Profiler2.h:521
CProfile2GPURegion(const char *name)
Definition: Profiler2.h:517
Scope-based enter/leave helper.
Definition: Profiler2.h:467
~CProfile2Region()
Definition: Profiler2.h:473
CProfile2Region(const char *name)
Definition: Profiler2.h:469
const char * m_Name
Definition: Profiler2.h:478
Scope-based enter/leave helper.
Definition: Profiler2.h:485
bool m_PushedHold
Definition: Profiler2.h:493
double m_Limit
Definition: Profiler2.h:491
~CProfile2SpikeRegion()
Definition: Profiler2.cpp:970
double m_StartTime
Definition: Profiler2.h:492
const char * m_Name
Definition: Profiler2.h:490
CProfile2SpikeRegion(const char *name, double spikeLimit)
Definition: Profiler2.cpp:959
Definition: Profiler2GPU.cpp:49
Used by CProfiler2 for GPU profiling support.
Definition: Profiler2GPU.h:34
Class instantiated in every registered thread.
Definition: Profiler2.h:138
void RecordAttributePrintf(const char *fmt,...) PRINTF_ARGS(2)
Definition: Profiler2.h:180
const std::string & GetName()
Definition: Profiler2.h:199
u8 HoldType()
Definition: Profiler2.cpp:424
void Write(EItem type, const void *item, u32 itemSize)
Store an item into the buffer.
Definition: Profiler2.cpp:327
double m_LastTime
Definition: Profiler2.h:222
void HoldToBuffer(bool condensed)
Definition: Profiler2.cpp:678
~ThreadStorage()
Definition: Profiler2.cpp:322
u32 m_BufferPos0
Definition: Profiler2.h:267
void Record(EItem type, double t, const char *id)
Definition: Profiler2.h:158
size_t m_HeldDepth
Definition: Profiler2.h:254
std::string m_Name
Definition: Profiler2.h:220
CProfiler2 & m_Profiler
Definition: Profiler2.h:219
std::string GetBuffer()
Returns a copy of a subset of the thread's buffer.
Definition: Profiler2.cpp:376
void PutOnHold(u8 type)
Definition: Profiler2.cpp:430
void RecordSyncMarker(double t)
Definition: Profiler2.h:146
u32 m_BufferPos1
Definition: Profiler2.h:268
@ BUFFER_AGGREGATE
Definition: Profiler2.h:144
@ BUFFER_NORMAL
Definition: Profiler2.h:144
@ BUFFER_SPIKE
Definition: Profiler2.h:144
size_t HoldLevel()
Definition: Profiler2.cpp:419
u8 * m_Buffer
Definition: Profiler2.h:224
void ThrowawayHoldBuffer()
Definition: Profiler2.cpp:721
CProfiler2 & GetProfiler()
Definition: Profiler2.h:194
void RecordAttribute(const char *fmt, va_list argp) VPRINTF_ARGS(2)
Definition: Profiler2.cpp:400
void WriteHold(EItem type, const void *item, u32 itemSize)
Definition: Profiler2.cpp:363
NONCOPYABLE(ThreadStorage)
void RecordLeave(double t)
Definition: Profiler2.h:172
ThreadStorage(CProfiler2 &profiler, const std::string &name)
Definition: Profiler2.cpp:315
HoldBuffer m_HoldBuffers[8]
Definition: Profiler2.h:253
void RecordFrameStart(double t)
Definition: Profiler2.h:166
Definition: Profiler2.h:97
void RegisterCurrentThread(const std::string &name)
Call in any thread to enable the profiler in that thread.
Definition: Profiler2.cpp:289
void EnableHTTP()
Call in main thread to enable the HTTP server.
Definition: Profiler2.cpp:177
void AddThreadStorage(ThreadStorage *storage)
Definition: Profiler2.cpp:303
mg_context * m_MgContext
Definition: Profiler2.h:451
void RemoveThreadStorage(ThreadStorage *storage)
Definition: Profiler2.cpp:309
void ConstructJSONOverview(std::ostream &stream)
Call in any thread to produce a JSON representation of the general state of the application.
Definition: Profiler2.cpp:728
bool m_Initialised
Definition: Profiler2.h:447
static const size_t BUFFER_SIZE
Definition: Profiler2.h:131
void RecordGPURegionEnter(const char *id)
Definition: Profiler2.cpp:277
void RecordGPUFrameEnd()
Definition: Profiler2.cpp:271
static thread_local ThreadStorage * m_CurrentStorage
Definition: Profiler2.h:457
void RecordGPURegionLeave(const char *id)
Definition: Profiler2.cpp:283
static const size_t MAX_ATTRIBUTE_LENGTH
Definition: Profiler2.h:115
void Shutdown()
Call in main thread to shut everything down.
Definition: Profiler2.cpp:247
int m_FrameNumber
Definition: Profiler2.h:449
~CProfiler2()
Definition: Profiler2.cpp:62
void RecordRegionEnter(const char *id)
Definition: Profiler2.h:347
void RecordFrameStart()
Call in main thread at the start of a frame.
Definition: Profiler2.h:336
void ShutdownGPU()
Call in main thread to shut down the GPU profiling support, before shutting down OpenGL.
Definition: Profiler2.cpp:216
void StopHoldingMessages(bool writeToBuffer, bool condensed=false)
Definition: Profiler2.h:393
void EnableGPU()
Call in main thread to enable the GPU profiling support, after OpenGL has been initialised.
Definition: Profiler2.cpp:206
CProfiler2()
Definition: Profiler2.cpp:57
static const u8 RESYNC_MAGIC[8]
An arbitrary number to help resyncing with the item stream when parsing.
Definition: Profiler2.h:118
void RecordRegionEnter(const char *id, double time)
Definition: Profiler2.h:352
static const size_t HOLD_BUFFER_SIZE
Definition: Profiler2.h:132
void IncrementFrameNumber()
Definition: Profiler2.h:430
std::vector< std::unique_ptr< ThreadStorage > > m_Threads
Definition: Profiler2.h:458
void ShutDownHTTP()
Call in main thread to shut down the profiler's HTTP server.
Definition: Profiler2.cpp:222
void RecordAttribute(const char *fmt,...) PRINTF_ARGS(2)
Definition: Profiler2.h:362
void HoldMessages(u8 type)
Definition: Profiler2.h:388
int GetFrameNumber()
Definition: Profiler2.h:425
double GetTime()
Definition: Profiler2.h:420
ThreadStorage & GetThreadStorage()
Definition: Profiler2.h:441
void SaveToFile()
Call in any thread to save a JSONP representation of the buffers for all threads, to a file named pro...
Definition: Profiler2.cpp:936
u8 HoldType()
Definition: Profiler2.h:383
void Toggle()
Call in main thread to enable/disable the profiler.
Definition: Profiler2.cpp:232
size_t HoldLevel()
Hold onto messages until a call to release or write the held messages.
Definition: Profiler2.h:378
void Initialise()
Call in main thread to set up the profiler, before calling any other profiler functions.
Definition: Profiler2.cpp:163
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.
Definition: Profiler2.cpp:903
void RecordSyncMarker()
Non-main threads should call this occasionally, especially if it's been a long time since their last ...
Definition: Profiler2.h:328
void RecordEvent(const char *id)
Definition: Profiler2.h:342
void RecordRegionLeave()
Definition: Profiler2.h:357
EItem
Item type identifiers.
Definition: Profiler2.h:106
@ ITEM_SYNC
Definition: Profiler2.h:108
@ ITEM_ENTER
Definition: Profiler2.h:110
@ ITEM_EVENT
Definition: Profiler2.h:109
@ ITEM_LEAVE
Definition: Profiler2.h:111
@ ITEM_NOP
Definition: Profiler2.h:107
@ ITEM_ATTRIBUTE
Definition: Profiler2.h:112
void InitialiseGPU()
Definition: Profiler2.cpp:171
void RecordGPUFrameStart()
Definition: Profiler2.cpp:265
std::mutex m_Mutex
Definition: Profiler2.h:455
CProfiler2GPU * m_GPU
Definition: Profiler2.h:453
#define PRINTF_ARGS(fmtpos)
Definition: code_annotation.h:257
#define VPRINTF_ARGS(fmtpos)
Definition: code_annotation.h:258
#define ARRAY_SIZE(name)
Definition: code_annotation.h:350
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
Definition: debug.h:290
bool IsMainThread()
Returns whether the current thread is the 'main' thread (i.e.
Definition: Threading.cpp:27
An item with a relative time and an ID string pointer.
Definition: Profiler2.h:124
const char * id
Definition: Profiler2.h:126
float dt
Definition: Profiler2.h:125
Definition: Profiler2.h:227
u8 type
Definition: Profiler2.h:250
void setType(u8 newType)
Definition: Profiler2.h:244
u32 pos
Definition: Profiler2.h:249
void clear()
Definition: Profiler2.h:240
HoldBuffer()
Definition: Profiler2.h:230
~HoldBuffer()
Definition: Profiler2.h:236
u8 * buffer
Definition: Profiler2.h:248
Definition: mongoose.cpp:489
double timer_Time()
Definition: timer.cpp:130
uint8_t u8
Definition: types.h:37
uint32_t u32
Definition: types.h:39