add RAII style profiling (#910)
This commit is contained in:
@@ -3,6 +3,20 @@
|
||||
#include "wiCanvas.h"
|
||||
#include "wiColor.h"
|
||||
|
||||
|
||||
// QoL macros, allows writing just ScopedXxxProfiling without needing to declare a variable manually
|
||||
#define ScopedCPUProfiling(name) wi::profiler::ScopedRangeCPU WI_PROFILER_CONCAT(_wi_profiler_cpu_range,__LINE__)(name)
|
||||
#define ScopedGPUProfiling(name, cmd) wi::profiler::ScopedRangeGPU WI_PROFILER_CONCAT(_wi_profiler_gpu_range,__LINE__)(name, cmd)
|
||||
|
||||
// same as ScopedXxxProfiling, just will automatically use the function name as name, should only be used at the beginning of a function
|
||||
#define ScopedCPUProfilingF ScopedCPUProfiling(__FUNCTION__)
|
||||
#define ScopedGPUProfilingF(cmd) ScopedGPUProfiling(__FUNCTION__, cmd)
|
||||
|
||||
// internal helper macros to make somewhat unique variable names based on line numbers to prevent some compilers
|
||||
// warning about shadowed variables
|
||||
#define WI_PROFILER_CONCAT(x,y) WI_PROFILER_CONCAT_INDIRECT(x,y)
|
||||
#define WI_PROFILER_CONCAT_INDIRECT(x,y) x##y
|
||||
|
||||
namespace wi::profiler
|
||||
{
|
||||
typedef size_t range_id;
|
||||
@@ -22,6 +36,22 @@ namespace wi::profiler
|
||||
// End a profiling range
|
||||
void EndRange(range_id id);
|
||||
|
||||
// helper using RAII to avoid having to manually call BeginRangeCPU/EndRange at beginning/end
|
||||
struct ScopedRangeCPU
|
||||
{
|
||||
range_id id;
|
||||
inline ScopedRangeCPU(const char* name) { id = BeginRangeCPU(name); }
|
||||
inline ~ScopedRangeCPU() { EndRange(id); }
|
||||
};
|
||||
|
||||
// same for BeginRangeGPU
|
||||
struct ScopedRangeGPU
|
||||
{
|
||||
range_id id;
|
||||
inline ScopedRangeGPU(const char* name, wi::graphics::CommandList cmd) { id = BeginRangeGPU(name, cmd); }
|
||||
inline ~ScopedRangeGPU() { EndRange(id); }
|
||||
};
|
||||
|
||||
// Renders a basic text of the Profiling results to the (x,y) screen coordinate
|
||||
void DrawData(
|
||||
const wi::Canvas& canvas,
|
||||
|
||||
Reference in New Issue
Block a user