[sysprof] libsysprof-capture: add stats to reader when possible



commit aed80ea51f1bfb79036e37390f312fab8721185a
Author: Christian Hergert <chergert redhat com>
Date:   Wed May 15 16:38:47 2019 -0700

    libsysprof-capture: add stats to reader when possible
    
    We can also back-fill these when reading a capture file.

 src/libsysprof-capture/sysprof-capture-reader.c | 32 +++++++++++++++++++++++++
 src/libsysprof-capture/sysprof-capture-reader.h |  6 +++++
 src/libsysprof-capture/sysprof-capture-types.h  | 13 ++++++++++
 src/libsysprof-capture/sysprof-capture-writer.c |  6 ++++-
 src/libsysprof-capture/sysprof-capture-writer.h | 13 ----------
 5 files changed, 56 insertions(+), 14 deletions(-)
---
diff --git a/src/libsysprof-capture/sysprof-capture-reader.c b/src/libsysprof-capture/sysprof-capture-reader.c
index e4dc91f..a240276 100644
--- a/src/libsysprof-capture/sysprof-capture-reader.c
+++ b/src/libsysprof-capture/sysprof-capture-reader.c
@@ -46,6 +46,8 @@ struct _SysprofCaptureReader
   gint                      endian;
   SysprofCaptureFileHeader  header;
   gint64                    end_time;
+  SysprofCaptureStat        st_buf;
+  guint                     st_buf_set : 1;
 };
 
 static gboolean
@@ -955,3 +957,33 @@ sysprof_capture_reader_copy (SysprofCaptureReader *self)
 
   return copy;
 }
+
+void
+sysprof_capture_reader_set_stat (SysprofCaptureReader     *self,
+                                 const SysprofCaptureStat *st_buf)
+{
+  g_return_if_fail (self != NULL);
+
+  if (st_buf != NULL)
+    {
+      self->st_buf = *st_buf;
+      self->st_buf_set = TRUE;
+    }
+  else
+    {
+      memset (&self->st_buf, 0, sizeof (self->st_buf));
+      self->st_buf_set = FALSE;
+    }
+}
+
+gboolean
+sysprof_capture_reader_get_stat (SysprofCaptureReader *self,
+                                 SysprofCaptureStat   *st_buf)
+{
+  g_return_val_if_fail (self != NULL, FALSE);
+
+  if (st_buf != NULL)
+    *st_buf = self->st_buf;
+
+  return self->st_buf_set;
+}
diff --git a/src/libsysprof-capture/sysprof-capture-reader.h b/src/libsysprof-capture/sysprof-capture-reader.h
index 5a03ca6..c0c8392 100644
--- a/src/libsysprof-capture/sysprof-capture-reader.h
+++ b/src/libsysprof-capture/sysprof-capture-reader.h
@@ -85,6 +85,12 @@ SYSPROF_AVAILABLE_IN_ALL
 gboolean                                sysprof_capture_reader_save_as             (SysprofCaptureReader     
*self,
                                                                                     const gchar              
*filename,
                                                                                     GError                  
**error);
+SYSPROF_AVAILABLE_IN_ALL
+gboolean                                sysprof_capture_reader_get_stat            (SysprofCaptureReader     
*self,
+                                                                                    SysprofCaptureStat       
*st_buf);
+SYSPROF_AVAILABLE_IN_ALL
+void                                    sysprof_capture_reader_set_stat            (SysprofCaptureReader     
*self,
+                                                                                    const SysprofCaptureStat 
*st_buf);
 
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofCaptureReader, sysprof_capture_reader_unref)
 
diff --git a/src/libsysprof-capture/sysprof-capture-types.h b/src/libsysprof-capture/sysprof-capture-types.h
index bd6a36e..0608e1c 100644
--- a/src/libsysprof-capture/sysprof-capture-types.h
+++ b/src/libsysprof-capture/sysprof-capture-types.h
@@ -58,6 +58,19 @@ typedef struct _SysprofCaptureCondition SysprofCaptureCondition;
 
 typedef guint64 SysprofCaptureAddress;
 
+typedef struct
+{
+  /*
+   * The number of frames indexed by SysprofCaptureFrameType
+   */
+  gsize frame_count[16];
+
+  /*
+   * Padding for future expansion.
+   */
+  gsize padding[48];
+} SysprofCaptureStat;
+
 typedef union
 {
   gint64  v64;
diff --git a/src/libsysprof-capture/sysprof-capture-writer.c b/src/libsysprof-capture/sysprof-capture-writer.c
index fae0fe0..6939cc8 100644
--- a/src/libsysprof-capture/sysprof-capture-writer.c
+++ b/src/libsysprof-capture/sysprof-capture-writer.c
@@ -1012,6 +1012,7 @@ SysprofCaptureReader *
 sysprof_capture_writer_create_reader (SysprofCaptureWriter  *self,
                                       GError               **error)
 {
+  SysprofCaptureReader *ret;
   int copy;
 
   g_return_val_if_fail (self != NULL, NULL);
@@ -1033,7 +1034,10 @@ sysprof_capture_writer_create_reader (SysprofCaptureWriter  *self,
   if (-1 == (copy = dup (self->fd)))
     return NULL;
 
-  return sysprof_capture_reader_new_from_fd (copy, error);
+  if ((ret = sysprof_capture_reader_new_from_fd (copy, error)))
+    sysprof_capture_reader_set_stat (ret, &self->stat);
+
+  return g_steal_pointer (&ret);
 }
 
 /**
diff --git a/src/libsysprof-capture/sysprof-capture-writer.h b/src/libsysprof-capture/sysprof-capture-writer.h
index 97f775c..47b3e3a 100644
--- a/src/libsysprof-capture/sysprof-capture-writer.h
+++ b/src/libsysprof-capture/sysprof-capture-writer.h
@@ -27,19 +27,6 @@ G_BEGIN_DECLS
 
 typedef struct _SysprofCaptureWriter SysprofCaptureWriter;
 
-typedef struct
-{
-  /*
-   * The number of frames indexed by SysprofCaptureFrameType
-   */
-  gsize frame_count[16];
-
-  /*
-   * Padding for future expansion.
-   */
-  gsize padding[48];
-} SysprofCaptureStat;
-
 SYSPROF_AVAILABLE_IN_ALL
 SysprofCaptureWriter *sysprof_capture_writer_new_from_env    (gsize                              
buffer_size);
 SYSPROF_AVAILABLE_IN_ALL


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