From ef7ff789e9c15f4f4b8c65585de7e7fa4f9c9438 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Fri, 12 Oct 2012 14:47:07 +0200 Subject: Add ring buffer recording for assessment --- tools/gui/ring-buffer.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tools/gui/ring-buffer.c (limited to 'tools/gui/ring-buffer.c') diff --git a/tools/gui/ring-buffer.c b/tools/gui/ring-buffer.c new file mode 100644 index 0000000..56c7620 --- /dev/null +++ b/tools/gui/ring-buffer.c @@ -0,0 +1,64 @@ + +#include +#include "ring-buffer.h" + +RingBuffer * +ring_buffer_new (gsize block_size, + gsize n_blocks) +{ + RingBuffer *buffer; + + buffer = g_new0 (RingBuffer, 1); + buffer->block_size = block_size; + buffer->n_blocks_total = n_blocks; + buffer->n_blocks_used = 0; + buffer->start_index = 0; + buffer->data = g_malloc0 (n_blocks * buffer->block_size); + + return buffer; +} + +void +ring_buffer_free (RingBuffer *buffer) +{ + g_free (buffer->data); + g_free (buffer); +} + +void +ring_buffer_reset (RingBuffer *buffer) +{ + buffer->n_blocks_used = 0; + buffer->start_index = 0; +} + +gpointer +ring_buffer_get_current_pointer (RingBuffer *buffer) +{ + return ring_buffer_get_pointer (buffer, 0); +} + +gpointer +ring_buffer_get_pointer (RingBuffer *buffer, + guint index) +{ + g_assert (index < buffer->n_blocks_total); + return buffer->data + ((buffer->start_index + index) % buffer->n_blocks_total) * buffer->block_size; +} + +guint +ring_buffer_get_num_blocks (RingBuffer *buffer) +{ + return buffer->n_blocks_used; +} + +void +ring_buffer_proceed (RingBuffer *buffer) +{ + buffer->start_index++; + + if (buffer->n_blocks_used < buffer->n_blocks_total) + buffer->n_blocks_used++; + else + buffer->start_index = buffer->start_index % buffer->n_blocks_total; +} -- cgit v1.2.3 From c48496b50a72575438f87da69080a48e0878a121 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Fri, 12 Oct 2012 16:17:53 +0200 Subject: Control memory size via command line --- tools/gui/ring-buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/gui/ring-buffer.c') diff --git a/tools/gui/ring-buffer.c b/tools/gui/ring-buffer.c index 56c7620..5915d2a 100644 --- a/tools/gui/ring-buffer.c +++ b/tools/gui/ring-buffer.c @@ -13,7 +13,7 @@ ring_buffer_new (gsize block_size, buffer->n_blocks_total = n_blocks; buffer->n_blocks_used = 0; buffer->start_index = 0; - buffer->data = g_malloc0 (n_blocks * buffer->block_size); + buffer->data = g_malloc0_n (n_blocks, block_size); return buffer; } -- cgit v1.2.3 From 33a90d8dc20a513722f5fdf66a99cff91be422d5 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Mon, 15 Oct 2012 10:33:14 +0200 Subject: Fix replay feature --- tools/gui/ring-buffer.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tools/gui/ring-buffer.c') diff --git a/tools/gui/ring-buffer.c b/tools/gui/ring-buffer.c index 5915d2a..ec2638c 100644 --- a/tools/gui/ring-buffer.c +++ b/tools/gui/ring-buffer.c @@ -12,7 +12,7 @@ ring_buffer_new (gsize block_size, buffer->block_size = block_size; buffer->n_blocks_total = n_blocks; buffer->n_blocks_used = 0; - buffer->start_index = 0; + buffer->current_index = 0; buffer->data = g_malloc0_n (n_blocks, block_size); return buffer; @@ -29,13 +29,13 @@ void ring_buffer_reset (RingBuffer *buffer) { buffer->n_blocks_used = 0; - buffer->start_index = 0; + buffer->current_index = 0; } gpointer ring_buffer_get_current_pointer (RingBuffer *buffer) { - return ring_buffer_get_pointer (buffer, 0); + return buffer->data + (buffer->current_index % buffer->n_blocks_total) * buffer->block_size; } gpointer @@ -43,7 +43,7 @@ ring_buffer_get_pointer (RingBuffer *buffer, guint index) { g_assert (index < buffer->n_blocks_total); - return buffer->data + ((buffer->start_index + index) % buffer->n_blocks_total) * buffer->block_size; + return buffer->data + ((buffer->current_index - buffer->n_blocks_used + index) % buffer->n_blocks_total) * buffer->block_size; } guint @@ -55,10 +55,10 @@ ring_buffer_get_num_blocks (RingBuffer *buffer) void ring_buffer_proceed (RingBuffer *buffer) { - buffer->start_index++; + buffer->current_index++; if (buffer->n_blocks_used < buffer->n_blocks_total) buffer->n_blocks_used++; else - buffer->start_index = buffer->start_index % buffer->n_blocks_total; + buffer->current_index = buffer->current_index % buffer->n_blocks_total; } -- cgit v1.2.3