$darkmode
Suckless OGL 1.0.0
A lean, high-performance C11 PBR Renderer
perf_timer.c File Reference
#include "perf_timer.h"
#include "log.h"
#include <string.h>
#include <time.h>
Include dependency graph for perf_timer.c:

Macros

#define HYBRID_STOP_BODY(log_fn)
 
#define TRACY_HYBRID_STOP_PREAMBLE(timer)   ((void)0)
 
#define TRACY_HYBRID_STOP_SYNC_END()   ((void)0)
 
#define TRACY_HYBRID_STOP_POSTAMBLE(timer, label, cpu_ms, gpu_ms)   ((void)0)
 

Enumerations

enum  TimeConversionFactors {
  NS_PER_MS = 1000000 , NS_PER_US = 1000 , NS_PER_S = 1000000000 , US_PER_S = 1000000 ,
  MS_PER_S = 1000 , LABEL_BUFFER_SIZE = 128
}
 

Functions

void perf_timer_start (PerfTimer *timer)
 Starts the CPU timer. More...
 
double perf_timer_elapsed_ms (PerfTimer *timer)
 Stops the timer and returns elapsed time in milliseconds. More...
 
double perf_timer_elapsed_us (PerfTimer *timer)
 Stops the timer and returns elapsed time in microseconds. More...
 
double perf_timer_elapsed_s (PerfTimer *timer)
 Stops the timer and returns elapsed time in seconds. More...
 
void gpu_timer_start (GPUTimer *timer)
 Initializes and starts a GPU measurement. More...
 
double gpu_timer_elapsed_ms (GPUTimer *timer, int wait_for_result)
 Stops the GPU timer and retrieves the result. More...
 
void gpu_timer_cleanup (GPUTimer *timer)
 Releases OpenGL resources associated with the GPU timer. More...
 
HybridTimer perf_hybrid_start (void)
 Starts both CPU and GPU measurement simultaneously. More...
 
void perf_hybrid_stop (HybridTimer *timer, const char *label)
 Stops both measurements and logs the results to the console. More...
 
double perf_hybrid_stop_debug (HybridTimer *timer, const char *label)
 Like perf_hybrid_stop, but logs at DEBUG level instead of INFO. More...
 

Variables

static const double NS_TO_MS = 1.0 / (double)NS_PER_MS
 
static const double NS_TO_US = 1.0 / (double)NS_PER_US
 
static const double NS_TO_S = 1.0 / (double)NS_PER_S
 
static const double S_TO_MS = (double)MS_PER_S
 
static const double S_TO_US = (double)US_PER_S
 

Macro Definition Documentation

◆ HYBRID_STOP_BODY

#define HYBRID_STOP_BODY (   log_fn)
Value:
double _cpu_ms = perf_timer_elapsed_ms(&timer->cpu); \
double _gpu_ms = gpu_timer_elapsed_ms(&timer->gpu, 1); \
TRACY_HYBRID_STOP_SYNC_END(); \
log_fn("perf.hybrid", "%s: [CPU: %.2f ms] [GPU: %.3f ms]", \
label, _cpu_ms, _gpu_ms); \
TRACY_HYBRID_STOP_POSTAMBLE(timer, label, _cpu_ms, _gpu_ms); \
gpu_timer_cleanup(&timer->gpu)
double perf_timer_elapsed_ms(PerfTimer *timer)
Stops the timer and returns elapsed time in milliseconds.
Definition: perf_timer.c:39
double gpu_timer_elapsed_ms(GPUTimer *timer, int wait_for_result)
Stops the GPU timer and retrieves the result.
Definition: perf_timer.c:110
#define TRACY_HYBRID_STOP_PREAMBLE(timer)
Definition: perf_timer.c:281

◆ TRACY_HYBRID_STOP_POSTAMBLE

#define TRACY_HYBRID_STOP_POSTAMBLE (   timer,
  label,
  cpu_ms,
  gpu_ms 
)    ((void)0)

◆ TRACY_HYBRID_STOP_PREAMBLE

#define TRACY_HYBRID_STOP_PREAMBLE (   timer)    ((void)0)

◆ TRACY_HYBRID_STOP_SYNC_END

#define TRACY_HYBRID_STOP_SYNC_END ( )    ((void)0)

Enumeration Type Documentation

◆ TimeConversionFactors

Enumerator
NS_PER_MS 
NS_PER_US 
NS_PER_S 
US_PER_S 
MS_PER_S 
LABEL_BUFFER_SIZE 

Function Documentation

◆ gpu_timer_cleanup()

void gpu_timer_cleanup ( GPUTimer timer)

Releases OpenGL resources associated with the GPU timer.

Parameters
timerPointer to the timer.

◆ gpu_timer_elapsed_ms()

double gpu_timer_elapsed_ms ( GPUTimer timer,
int  wait_for_result 
)

Stops the GPU timer and retrieves the result.

Parameters
timerPointer to the timer.
wait_for_resultIf true, blocks until the GPU is finished and result is ready.
Returns
Elapsed time in milliseconds, or -1.0 if not ready and wait_for_result is false.

◆ gpu_timer_start()

void gpu_timer_start ( GPUTimer timer)

Initializes and starts a GPU measurement.

Parameters
timerPointer to the timer.

◆ perf_hybrid_start()

HybridTimer perf_hybrid_start ( void  )

Starts both CPU and GPU measurement simultaneously.

Returns
Initialized and started HybridTimer structure.
Here is the call graph for this function:

◆ perf_hybrid_stop()

void perf_hybrid_stop ( HybridTimer timer,
const char *  label 
)

Stops both measurements and logs the results to the console.

Parameters
timerPointer to the timer.
labelDescriptive string for the log entry.

◆ perf_hybrid_stop_debug()

double perf_hybrid_stop_debug ( HybridTimer timer,
const char *  label 
)

Like perf_hybrid_stop, but logs at DEBUG level instead of INFO.

Tracy zones are still emitted at full detail. Only the console output is demoted to reduce noise in production. Returns GPU elapsed ms.

Parameters
timerPointer to the timer.
labelDescriptive string for the log entry.
Returns
GPU elapsed time in milliseconds.

◆ perf_timer_elapsed_ms()

double perf_timer_elapsed_ms ( PerfTimer timer)

Stops the timer and returns elapsed time in milliseconds.

Parameters
timerPointer to the timer.
Returns
Elapsed time (double precision).

◆ perf_timer_elapsed_s()

double perf_timer_elapsed_s ( PerfTimer timer)

Stops the timer and returns elapsed time in seconds.

Parameters
timerPointer to the timer.
Returns
Elapsed time (double precision).

◆ perf_timer_elapsed_us()

double perf_timer_elapsed_us ( PerfTimer timer)

Stops the timer and returns elapsed time in microseconds.

Parameters
timerPointer to the timer.
Returns
Elapsed time (double precision).

◆ perf_timer_start()

void perf_timer_start ( PerfTimer timer)

Starts the CPU timer.

Parameters
timerPointer to the timer.

Variable Documentation

◆ NS_TO_MS

const double NS_TO_MS = 1.0 / (double)NS_PER_MS
static

◆ NS_TO_S

const double NS_TO_S = 1.0 / (double)NS_PER_S
static

◆ NS_TO_US

const double NS_TO_US = 1.0 / (double)NS_PER_US
static

◆ S_TO_MS

const double S_TO_MS = (double)MS_PER_S
static

◆ S_TO_US

const double S_TO_US = (double)US_PER_S
static