Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jringle/fps debug #63

Merged
merged 3 commits into from
Apr 30, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions c_src/scenic/comms.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,11 @@ The caller will typically be erlang, so use the 2-byte length indicator
#include "script.h"
#include "utils.h"

// handy time definitions in microseconds
#define MILLISECONDS_8 8000
#define MILLISECONDS_16 16000
#define MILLISECONDS_20 20000
#define MILLISECONDS_32 32000
#define MILLISECONDS_64 64000
#define MILLISECONDS_128 128000

// Setting the timeout too high means input will be laggy as you
// are starving the input polling. Setting it too low means using
// energy for no purpose. Probably best if set similar to the
// frame rate of the application
#define STDIO_TIMEOUT MILLISECONDS_32
#define STDIO_TIMEOUT 32

extern device_info_t g_device_info;

Expand Down Expand Up @@ -407,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 @@ -428,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
Loading