libsysprof-capture: add raw frame helper

This helps when shuffling data between sources so that you can simply
memcpy() into the destination buffer.
This commit is contained in:
Christian Hergert
2020-02-13 14:29:10 -08:00
parent 1d44282edb
commit 6cb55f4d71
2 changed files with 30 additions and 0 deletions

View File

@ -1609,3 +1609,30 @@ sysprof_capture_writer_add_allocation_copy (SysprofCaptureWriter *self,
return TRUE;
}
gboolean
_sysprof_capture_writer_add_raw (SysprofCaptureWriter *self,
const SysprofCaptureFrame *fr)
{
gpointer begin;
gsize len;
g_assert (self != NULL);
g_assert ((fr->len & 0x7) == 0);
g_assert (fr->type < SYSPROF_CAPTURE_FRAME_LAST);
len = fr->len;
if (!(begin = sysprof_capture_writer_allocate (self, &len)))
return FALSE;
g_assert (fr->len == len);
g_assert (fr->type < 16);
memcpy (begin, fr, fr->len);
if (fr->type < G_N_ELEMENTS (self->stat.frame_count))
self->stat.frame_count[fr->type]++;
return TRUE;
}

View File

@ -237,6 +237,9 @@ gboolean sysprof_capture_writer_cat (Sy
SysprofCaptureReader *reader,
GError **error);
G_GNUC_INTERNAL
gboolean _sysprof_capture_writer_add_raw (SysprofCaptureWriter *self,
const SysprofCaptureFrame *frame);
G_GNUC_INTERNAL
gboolean _sysprof_capture_writer_splice_from_fd (SysprofCaptureWriter *self,
int fd,
GError **error) G_GNUC_INTERNAL;