78#ifndef INCLUDED_PROFILER2
79#define INCLUDED_PROFILER2
98namespace httplib {
class Server; }
166 Write(type, &item,
sizeof(item));
212 void Write(
EItem type,
const void* item, std::uint32_t itemSize);
234 std::atomic<std::uint32_t>
begin{0};
235 std::atomic<std::uint32_t>
end{0};
452#define PROFILE2(region) CProfile2Region profile2__(region)
454#define PROFILE2_GPU(deviceCommandContext, region) CProfile2GPURegion profile2gpu__(deviceCommandContext, region)
459#define PROFILE2_EVENT(name) g_Profiler2.RecordEvent(name)
467#define PROFILE2_ATTR g_Profiler2.RecordAttribute
CProfiler2 g_Profiler2
Definition: Profiler2.cpp:54
Scope-based GPU enter/leave helper.
Definition: Profiler2.h:429
Renderer::Backend::IDeviceCommandContext * m_DeviceCommandContext
Definition: Profiler2.h:441
const char * m_Name
Definition: Profiler2.h:442
~CProfile2GPURegion()
Definition: Profiler2.h:436
CProfile2GPURegion(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, const char *name)
Definition: Profiler2.h:431
Scope-based enter/leave helper.
Definition: Profiler2.h:411
~CProfile2Region()
Definition: Profiler2.h:417
CProfile2Region(const char *name)
Definition: Profiler2.h:413
const char * m_Name
Definition: Profiler2.h:422
At each enter/leave-region event, we do an async GPU timestamp query.
Definition: Profiler2GPU.cpp:47
Used by CProfiler2 for GPU profiling support.
Definition: Profiler2GPU.h:35
Class instantiated in every registered thread.
Definition: Profiler2.h:143
void RecordAttributePrintf(const char *fmt,...) PRINTF_ARGS(2)
Definition: Profiler2.h:183
const std::string & GetName()
Definition: Profiler2.h:196
double m_LastTime
Definition: Profiler2.h:219
~ThreadStorage()
Definition: Profiler2.cpp:264
void Record(EItem type, double t, const char *id)
Definition: Profiler2.h:161
void WriteHold(EItem type, const void *item, std::uint32_t itemSize)
std::string m_Name
Definition: Profiler2.h:217
CProfiler2 & m_Profiler
Definition: Profiler2.h:216
std::string GetBuffer()
Returns a copy of a subset of the thread's buffer.
Definition: Profiler2.cpp:297
void Write(EItem type, const void *item, std::uint32_t itemSize)
Store an item into the buffer.
Definition: Profiler2.cpp:269
RingBufferSpan m_ValidRange
Definition: Profiler2.h:237
void RecordSyncMarker(double t)
Definition: Profiler2.h:149
std::uint8_t * m_Buffer
Definition: Profiler2.h:221
CProfiler2 & GetProfiler()
Definition: Profiler2.h:191
void RecordAttribute(const char *fmt, va_list argp) VPRINTF_ARGS(2)
Definition: Profiler2.cpp:319
NONCOPYABLE(ThreadStorage)
void RecordLeave(double t)
Definition: Profiler2.h:175
ThreadStorage(CProfiler2 &profiler, const std::string &name)
Definition: Profiler2.cpp:257
void RecordFrameStart(double t)
Definition: Profiler2.h:169
Definition: Profiler2.h:104
void RegisterCurrentThread(const std::string &name)
Call in any thread to enable the profiler in that thread.
Definition: Profiler2.cpp:231
void EnableHTTP()
Call in main thread to enable the HTTP server.
Definition: Profiler2.cpp:91
void AddThreadStorage(ThreadStorage *storage)
Definition: Profiler2.cpp:245
void RemoveThreadStorage(ThreadStorage *storage)
Definition: Profiler2.cpp:251
void ConstructJSONOverview(std::ostream &stream)
Call in any thread to produce a JSON representation of the general state of the application.
Definition: Profiler2.cpp:579
bool m_Initialised
Definition: Profiler2.h:390
static const size_t BUFFER_SIZE
Definition: Profiler2.h:136
static thread_local ThreadStorage * m_CurrentStorage
Definition: Profiler2.h:401
static const size_t MAX_ATTRIBUTE_LENGTH
Definition: Profiler2.h:120
void Shutdown()
Call in main thread to shut everything down.
Definition: Profiler2.cpp:194
void RecordGPUFrameStart(Renderer::Backend::IDeviceCommandContext *deviceCommandContext)
Definition: Profiler2.cpp:207
int m_FrameNumber
Definition: Profiler2.h:392
~CProfiler2()
Definition: Profiler2.cpp:71
void RecordRegionEnter(const char *id)
Definition: Profiler2.h:316
void RecordFrameStart()
Call in main thread at the start of a frame.
Definition: Profiler2.h:305
void ShutdownGPU()
Call in main thread to shut down the GPU profiling support, before shutting down OpenGL.
Definition: Profiler2.cpp:155
void EnableGPU()
Call in main thread to enable the GPU profiling support, after OpenGL has been initialised.
Definition: Profiler2.cpp:145
CProfiler2()
Definition: Profiler2.cpp:66
void RecordRegionEnter(const char *id, double time)
Definition: Profiler2.h:321
static const size_t HOLD_BUFFER_SIZE
Definition: Profiler2.h:137
void IncrementFrameNumber()
Definition: Profiler2.h:373
std::vector< std::unique_ptr< ThreadStorage > > m_Threads
Definition: Profiler2.h:402
static const std::uint8_t RESYNC_MAGIC[8]
An arbitrary number to help resyncing with the item stream when parsing.
Definition: Profiler2.h:123
void ShutDownHTTP()
Call in main thread to shut down the profiler's HTTP server.
Definition: Profiler2.cpp:161
void RecordAttribute(const char *fmt,...) PRINTF_ARGS(2)
Definition: Profiler2.h:331
int GetFrameNumber()
Definition: Profiler2.h:368
double GetTime()
Definition: Profiler2.h:363
ThreadStorage & GetThreadStorage()
Definition: Profiler2.h:384
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:788
void RecordGPUFrameEnd(Renderer::Backend::IDeviceCommandContext *deviceCommandContext)
Definition: Profiler2.cpp:213
void Toggle()
Call in main thread to enable/disable the profiler.
Definition: Profiler2.cpp:175
void Initialise()
Call in main thread to set up the profiler, before calling any other profiler functions.
Definition: Profiler2.cpp:77
std::thread m_HttpServerThread
Definition: Profiler2.h:395
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:755
void RecordSyncMarker()
Non-main threads should call this occasionally, especially if it's been a long time since their last ...
Definition: Profiler2.h:297
void RecordEvent(const char *id)
Definition: Profiler2.h:311
void RecordGPURegionEnter(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, const char *id)
Definition: Profiler2.cpp:219
void RecordRegionLeave()
Definition: Profiler2.h:326
EItem
Item type identifiers.
Definition: Profiler2.h:111
@ ITEM_SYNC
Definition: Profiler2.h:113
@ ITEM_ENTER
Definition: Profiler2.h:115
@ ITEM_EVENT
Definition: Profiler2.h:114
@ ITEM_LEAVE
Definition: Profiler2.h:116
@ ITEM_NOP
Definition: Profiler2.h:112
@ ITEM_ATTRIBUTE
Definition: Profiler2.h:117
void InitialiseGPU()
Definition: Profiler2.cpp:85
std::unique_ptr< httplib::Server > m_HttpServer
Definition: Profiler2.h:394
std::mutex m_Mutex
Definition: Profiler2.h:399
CProfiler2GPU * m_GPU
Definition: Profiler2.h:397
void RecordGPURegionLeave(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, const char *id)
Definition: Profiler2.cpp:225
Definition: IDeviceCommandContext.h:46
#define PRINTF_ARGS(fmtpos)
Definition: code_annotation.h:213
#define VPRINTF_ARGS(fmtpos)
Definition: code_annotation.h:214
#define ARRAY_SIZE(name)
Definition: code_annotation.h:283
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
Definition: debug.h:222
Definition: Canvas2D.h:30
bool IsMainThread()
Returns whether the current thread is the 'main' thread (i.e.
Definition: Threading.cpp:29
Definition: HttpServer.h:23
An item with a relative time and an ID string pointer.
Definition: Profiler2.h:129
const char * id
Definition: Profiler2.h:131
float dt
Definition: Profiler2.h:130
Definition: Profiler2.h:233
std::atomic< std::uint32_t > end
Definition: Profiler2.h:235
std::atomic< std::uint32_t > begin
Definition: Profiler2.h:234
double timer_Time()
Definition: timer.cpp:132