capture: add SpCaptureCursor and associated types

This API helps us simplify some of the tooling to iterate
through a capture. In particular, we might want to setup a
bunch of matches and then just iterate through the items.

This can also allow delaying the iteration until the future
which might be handy for visualizers which won't want to block
the main loop.

I'm not jazzed about the 64k buffer created for every cursor
due to the SpCaptureReader copy, but it's probably not a big
deal in practice until we start doing more exotic things.
This commit is contained in:
Christian Hergert
2016-09-25 00:25:08 -07:00
parent b8f465659b
commit c19d0635aa
8 changed files with 560 additions and 2 deletions

View File

@ -0,0 +1,58 @@
#include <glib/gstdio.h>
#include <sysprof.h>
static gboolean
increment (const SpCaptureFrame *frame,
gpointer user_data)
{
gint *count= user_data;
(*count)++;
return TRUE;
}
static void
test_cursor_basic (void)
{
SpCaptureReader *reader;
SpCaptureWriter *writer;
SpCaptureCursor *cursor;
GError *error = NULL;
gint64 t = SP_CAPTURE_CURRENT_TIME;
guint i;
gint r;
gint count = 0;
writer = sp_capture_writer_new ("capture-file", 0);
g_assert (writer != NULL);
reader = sp_capture_reader_new ("capture-file", &error);
g_assert_no_error (error);
g_assert (reader != NULL);
for (i = 0; i < 100; i++)
{
r = sp_capture_writer_add_timestamp (writer, t, i, -1);
g_assert_cmpint (r, ==, TRUE);
}
sp_capture_writer_flush (writer);
cursor = sp_capture_cursor_new (reader);
sp_capture_cursor_foreach (cursor, increment, &count);
g_assert_cmpint (count, ==, 100);
g_clear_object (&cursor);
sp_capture_reader_unref (reader);
sp_capture_writer_unref (writer);
g_unlink ("capture-file");
}
int
main (int argc,
char *argv[])
{
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/SpCaptureCursor/basic", test_cursor_basic);
return g_test_run ();
}