25 struct timespec start;
42#include <tracy/TracyC.h>
53 TracyCZoneCtx tracy_ctx;
54 TracyCZoneCtx host_ctx;
165#define PERF_MEASURE_MS(var_name) \
166 double var_name = 0.0; \
168 _timer##var_name = {0}, \
169 *_run = (perf_timer_start(&_timer##var_name), (PerfTimer*)1); \
171 var_name = perf_timer_elapsed_ms(&_timer##var_name), _run = NULL)
176#define PERF_MEASURE_LOG(label) \
177 for (PerfTimer _timer = {0}, \
178 *_run = (perf_timer_start(&_timer), (PerfTimer*)1); \
179 _run; LOG_INFO("perf", "%s: %.2f ms", label, \
180 perf_timer_elapsed_ms(&_timer)), \
186#define GPU_MEASURE_MS(var_name) \
187 double var_name = 0.0; \
188 for (GPUTimer _gpu_timer##var_name = {0}, \
189 *_gpu_run = (gpu_timer_start(&_gpu_timer##var_name), \
192 var_name = gpu_timer_elapsed_ms(&_gpu_timer##var_name, 1), \
193 gpu_timer_cleanup(&_gpu_timer##var_name), \
199#define GPU_MEASURE_LOG(label) \
202 *_gpu_run = (gpu_timer_start(&_gpu_timer), (GPUTimer*)1); \
203 _gpu_run; LOG_INFO("perf.gpu", "%s: %.2f ms", label, \
204 gpu_timer_elapsed_ms(&_gpu_timer, 1)), \
205 gpu_timer_cleanup(&_gpu_timer), _gpu_run = NULL)
211#define HYBRID_MEASURE_LOG(label) \
212 for (HybridTimer _h = perf_hybrid_start(), *_h_run = (HybridTimer*)1; \
213 _h_run; perf_hybrid_stop(&_h, label), _h_run = NULL)
229#define HYBRID_MEASURE_DEBUG_MS(var_name, label) \
230 double var_name = 0.0; \
231 for (HybridTimer _h##var_name = perf_hybrid_start(), \
232 *_h_run = (HybridTimer*)1; \
233 _h_run; var_name = perf_hybrid_stop_debug(&_h##var_name, label), \
262#define HYBRID_FUNC_TIMER(label) \
263 HybridTimerRAII _h_raii \
264 __attribute__((cleanup(hybrid_timer_cleanup_raii))) \
265 __attribute__((unused)) = {perf_hybrid_start(), label}
Common OpenGL definitions, RAII helpers, and utilities.
double perf_timer_elapsed_ms(PerfTimer *timer)
Stops the timer and returns elapsed time in milliseconds.
Definition perf_timer.c:39
void perf_hybrid_stop(HybridTimer *timer, const char *label)
Stops both measurements and logs the results to the console.
Definition perf_timer.c:288
double perf_timer_elapsed_s(PerfTimer *timer)
Stops the timer and returns elapsed time in seconds.
Definition perf_timer.c:69
double perf_timer_elapsed_us(PerfTimer *timer)
Stops the timer and returns elapsed time in microseconds.
Definition perf_timer.c:54
double gpu_timer_elapsed_ms(GPUTimer *timer, int wait_for_result)
Stops the GPU timer and retrieves the result.
Definition perf_timer.c:107
void perf_timer_start(PerfTimer *timer)
Starts the CPU timer.
Definition perf_timer.c:31
HybridTimer perf_hybrid_start(void)
Starts both CPU and GPU measurement simultaneously.
Definition perf_timer.c:210
void gpu_timer_stop(GPUTimer *timer)
Explicitly stops the GPU timer (records end timestamp).
static void hybrid_timer_cleanup_raii(HybridTimerRAII *timer_raii)
Internal cleanup function for HybridTimerRAII.
Definition perf_timer.h:246
void gpu_timer_start(GPUTimer *timer)
Initializes and starts a GPU measurement.
Definition perf_timer.c:88
void gpu_timer_cleanup(GPUTimer *timer)
Releases OpenGL resources associated with the GPU timer.
Definition perf_timer.c:161
double perf_hybrid_stop_debug(HybridTimer *timer, const char *label)
Like perf_hybrid_stop, but logs at DEBUG level instead of INFO.
Definition perf_timer.c:297
GPU performance timer using OpenGL Query Objects.
Definition perf_timer.h:35
bool active
Definition perf_timer.h:38
GLuint query_end
Definition perf_timer.h:37
GLuint query_start
Definition perf_timer.h:36
Internal helper for scope-based timing.
Definition perf_timer.h:240
const char * label
Definition perf_timer.h:242
HybridTimer timer
Definition perf_timer.h:241
Hybrid timer combining CPU and GPU measurements.
Definition perf_timer.h:49
PerfTimer cpu
Definition perf_timer.h:50
GPUTimer gpu
Definition perf_timer.h:51
CPU high-precision timer.
Definition perf_timer.h:24