[sysprof] libsysprof-capture: add raw frame helper



commit 6cb55f4d713aa34b11a22980ecfa809d65b13b63
Author: Christian Hergert <chergert redhat com>
Date:   Thu Feb 13 14:29:10 2020 -0800

    libsysprof-capture: add raw frame helper
    
    This helps when shuffling data between sources so that you can simply
    memcpy() into the destination buffer.

 src/libsysprof-capture/sysprof-capture-writer.c | 27 +++++++++++++++++++++++++
 src/libsysprof-capture/sysprof-capture-writer.h |  3 +++
 2 files changed, 30 insertions(+)
---
diff --git a/src/libsysprof-capture/sysprof-capture-writer.c b/src/libsysprof-capture/sysprof-capture-writer.c
index 5e206af..c83dbc0 100644
--- a/src/libsysprof-capture/sysprof-capture-writer.c
+++ b/src/libsysprof-capture/sysprof-capture-writer.c
@@ -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;
+}
diff --git a/src/libsysprof-capture/sysprof-capture-writer.h b/src/libsysprof-capture/sysprof-capture-writer.h
index 657e726..07120ba 100644
--- a/src/libsysprof-capture/sysprof-capture-writer.h
+++ b/src/libsysprof-capture/sysprof-capture-writer.h
@@ -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;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]