Skip to content

Commit

Permalink
Merge pull request #63 from gridpoint-com/jringle/fps-debug
Browse files Browse the repository at this point in the history
Jringle/fps debug
  • Loading branch information
crertel authored Apr 30, 2024
2 parents 9990524 + 9ae099b commit ca207a8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
11 changes: 6 additions & 5 deletions c_src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ int main(int argc, char **argv)
driver_data_t data = {0};

// super simple arg check
if (argc != 10) {
if (argc != 11) {
log_error("Wrong number of parameters");
return -1;
}
Expand All @@ -41,10 +41,11 @@ int main(int argc, char **argv)
g_opts.global_opacity = atoi(argv[3]);
g_opts.antialias = atoi(argv[4]);
g_opts.debug_mode = atoi(argv[5]);
g_opts.width = atoi(argv[6]);
g_opts.height = atoi(argv[7]);
g_opts.resizable = atoi(argv[8]);
g_opts.title = argv[9];
g_opts.debug_fps = atoi(argv[6]);
g_opts.width = atoi(argv[7]);
g_opts.height = atoi(argv[8]);
g_opts.resizable = atoi(argv[9]);
g_opts.title = argv[10];

// init the hashtables
init_scripts();
Expand Down
40 changes: 31 additions & 9 deletions c_src/scenic/comms.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,14 @@ 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;
extern device_opts_t g_opts;

//=============================================================================
// raw comms with host app
Expand Down Expand Up @@ -407,6 +400,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 +429,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 ((g_opts.debug_fps > 1) && (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 ((g_opts.debug_fps > 0) && (time_remaining <= 0)) {
log_info("real_fps: %d", frames);
start_real = monotonic_time();
time_remaining = 1000;
frames = 0;
}

// all done
send_ready();
Expand Down
1 change: 1 addition & 0 deletions c_src/scenic/scenic_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ typedef struct {
typedef struct {
// options from the command line
int debug_mode;
int debug_fps;
int layer;
int global_opacity;
int antialias;
Expand Down
4 changes: 3 additions & 1 deletion lib/driver.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ defmodule Scenic.Driver.Local do
opacity: [type: :integer, default: @default_opacity],
debug: [type: :boolean, default: false],
debugger: [type: :string, default: ""],
debug_fps: [type: :integer, default: 0],
antialias: [type: :boolean, default: true],
calibration: [
type: {:custom, __MODULE__, :validate_calibration, []},
Expand Down Expand Up @@ -214,6 +215,7 @@ defmodule Scenic.Driver.Local do
end

{:ok, debugger} = Keyword.fetch(opts, :debugger)
{:ok, debug_fps} = Keyword.fetch(opts, :debug_fps)
{:ok, layer} = Keyword.fetch(opts, :layer)
{:ok, opacity} = Keyword.fetch(opts, :opacity)

Expand All @@ -227,7 +229,7 @@ defmodule Scenic.Driver.Local do
end

args =
" #{internal_cursor} #{layer} #{opacity} #{antialias} #{debug_mode}" <>
" #{internal_cursor} #{layer} #{opacity} #{antialias} #{debug_mode} #{debug_fps}" <>
" #{width} #{height} #{resizeable} \"#{title}\""

# open and initialize the window
Expand Down
1 change: 1 addition & 0 deletions test/driver_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule Scenic.Driver.LocalTest do
opacity: 1,
debug: false,
debugger: "",
debug_fps: 0,
antialias: true,
calibration: [{"calibration_name", {{0, 0, 0}, {0, 0, 0}}}],
position: [
Expand Down

0 comments on commit ca207a8

Please sign in to comment.