[sysprof] writer: add helper to replace time range



commit 7c034994849f0b03cdfe6700e46fd2bd1ec538d3
Author: Christian Hergert <chergert redhat com>
Date:   Fri May 18 11:28:15 2018 +0100

    writer: add helper to replace time range
    
    This is useful so that we can overwrite the time range in the file when
    muxing together multiple streams.

 lib/capture/sp-capture-writer.c |   30 ++++++++++++++++++++++++++++++
 lib/capture/sp-capture-writer.h |    3 +++
 2 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/lib/capture/sp-capture-writer.c b/lib/capture/sp-capture-writer.c
index f29bfb7..d362544 100644
--- a/lib/capture/sp-capture-writer.c
+++ b/lib/capture/sp-capture-writer.c
@@ -1188,3 +1188,33 @@ sp_capture_writer_request_counter (SpCaptureWriter *self,
 
   return ret;
 }
+
+gboolean
+_sp_capture_writer_set_time_range (SpCaptureWriter *self,
+                                   gint64           start_time,
+                                   gint64           end_time)
+{
+  ssize_t ret;
+
+  g_assert (self != NULL);
+
+do_start:
+  ret = pwrite (self->fd,
+                &start_time,
+                sizeof (start_time),
+                G_STRUCT_OFFSET (SpCaptureFileHeader, time));
+
+  if (ret < 0 && errno == EAGAIN)
+    goto do_start;
+
+do_end:
+  ret = pwrite (self->fd,
+                &end_time,
+                sizeof (end_time),
+                G_STRUCT_OFFSET (SpCaptureFileHeader, end_time));
+
+  if (ret < 0 && errno == EAGAIN)
+    goto do_end;
+
+  return TRUE;
+}
diff --git a/lib/capture/sp-capture-writer.h b/lib/capture/sp-capture-writer.h
index c2d2ae9..305b603 100644
--- a/lib/capture/sp-capture-writer.h
+++ b/lib/capture/sp-capture-writer.h
@@ -116,6 +116,9 @@ gboolean            sp_capture_writer_splice          (SpCaptureWriter         *
 gboolean            _sp_capture_writer_splice_from_fd (SpCaptureWriter         *self,
                                                        int                      fd,
                                                        GError                 **error) G_GNUC_INTERNAL;
+gboolean            _sp_capture_writer_set_time_range (SpCaptureWriter         *self,
+                                                       gint64                   start_time,
+                                                       gint64                   end_time) G_GNUC_INTERNAL;
 
 #ifndef SP_DISABLE_GOBJECT
 # define SP_TYPE_CAPTURE_WRITER (sp_capture_writer_get_type())


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