Skip to content

Commit

Permalink
debug fps: log number of frames rendered in each second
Browse files Browse the repository at this point in the history
  • Loading branch information
ringlej committed Mar 19, 2024
1 parent 75a7e0a commit 4a2073b
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions c_src/scenic/comms.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,14 @@ void receive_crash()
//---------------------------------------------------------
void render(driver_data_t* p_data)
{
// Setup FPS calc
static int64_t start_real = 0;
static int64_t time_remaining = -1;
static clock_t render_fps = 0;
static uint32_t frames = 0;

clock_t begin_frame = clock();

// prep the id to the root scene
sid_t id;
id.p_data = "_root_";
Expand All @@ -420,6 +428,27 @@ void render(driver_data_t* p_data)
}

device_end_render(p_data);
clock_t end_frame = clock();
clock_t delta_ticks = end_frame - begin_frame;

if (delta_ticks > 0) {
render_fps = CLOCKS_PER_SEC / delta_ticks;
// log_debug("render_fps (cpu time): %d", render_fps);
}

frames++;

int64_t end_real = monotonic_time();
int64_t delta_real = (end_real - start_real);
start_real = end_real;
time_remaining -= delta_real;

if (time_remaining <= 0) {
log_debug("real_fps: %d", frames);
start_real = monotonic_time();
time_remaining = 1000;
frames = 0;
}

// all done
send_ready();
Expand Down

0 comments on commit 4a2073b

Please sign in to comment.