[sysprof] capture: make counter value a union of int64 and double



commit 49e9ad9db8f2d333810c54945129f60b196a1277
Author: Christian Hergert <chergert redhat com>
Date:   Fri Apr 15 04:54:55 2016 -0700

    capture: make counter value a union of int64 and double
    
    This allows us to use the type field of the counter to specify if the
    counter is a double or a 64-bit integer.

 lib/sp-capture-reader.c |    4 ++--
 lib/sp-capture-types.h  |   26 +++++++++++++++++---------
 lib/sp-capture-writer.c |   14 +++++++-------
 lib/sp-capture-writer.h |    2 +-
 tests/test-capture.c    |   24 ++++++++++++------------
 5 files changed, 39 insertions(+), 31 deletions(-)
---
diff --git a/lib/sp-capture-reader.c b/lib/sp-capture-reader.c
index 70ce4bc..67144b6 100644
--- a/lib/sp-capture-reader.c
+++ b/lib/sp-capture-reader.c
@@ -606,7 +606,7 @@ sp_capture_reader_read_counter_define (SpCaptureReader *self)
       for (i = 0; i < def->n_counters; i++)
         {
           def->counters[i].id = GUINT32_SWAP_LE_BE (def->counters[i].id);
-          def->counters[i].value = GUINT64_SWAP_LE_BE (def->counters[i].value);
+          def->counters[i].value.v64 = GUINT64_SWAP_LE_BE (def->counters[i].value.v64);
         }
     }
 
@@ -657,7 +657,7 @@ sp_capture_reader_read_counter_set (SpCaptureReader *self)
           for (j = 0; j < G_N_ELEMENTS (set->values[0].values); i++)
             {
               set->values[i].ids[j] = GUINT32_SWAP_LE_BE (set->values[i].ids[j]);
-              set->values[i].values[j] = GUINT64_SWAP_LE_BE (set->values[i].values[j]);
+              set->values[i].values[j].v64 = GUINT64_SWAP_LE_BE (set->values[i].values[j].v64);
             }
         }
     }
diff --git a/lib/sp-capture-types.h b/lib/sp-capture-types.h
index 1c040d9..c0dd2b2 100644
--- a/lib/sp-capture-types.h
+++ b/lib/sp-capture-types.h
@@ -38,13 +38,21 @@ G_BEGIN_DECLS
 # define SP_CAPTURE_ADDRESS_FORMAT "0x%016llx"
 #endif
 
-#define SP_CAPTURE_CURRENT_TIME (g_get_monotonic_time() * 1000L)
+#define SP_CAPTURE_CURRENT_TIME   (g_get_monotonic_time() * 1000L)
+#define SP_CAPTURE_COUNTER_INT64  0
+#define SP_CAPTURE_COUNTER_DOUBLE 1
 
 typedef struct _SpCaptureReader SpCaptureReader;
 typedef struct _SpCaptureWriter SpCaptureWriter;
 
 typedef guint64 SpCaptureAddress;
 
+typedef union
+{
+  gint64  v64;
+  gdouble vdbl;
+} SpCaptureCounterValue;
+
 typedef enum
 {
   SP_CAPTURE_FRAME_TIMESTAMP = 1,
@@ -131,12 +139,12 @@ typedef struct
 
 typedef struct
 {
-  gchar   category[32];
-  gchar   name[32];
-  gchar   description[52];
-  guint32 id : 24;
-  guint8  type;
-  gint64  value;
+  gchar                 category[32];
+  gchar                 name[32];
+  gchar                 description[52];
+  guint32               id : 24;
+  guint8                type;
+  SpCaptureCounterValue value;
 } SpCaptureCounter;
 
 typedef struct
@@ -154,8 +162,8 @@ typedef struct
    * bytes.  So this makes a nice 2-cacheline aligned size which is
    * useful when the number of counters is rather small.
    */
-  guint32 ids[8];
-  gint64  values[8];
+  guint32               ids[8];
+  SpCaptureCounterValue values[8];
 } SpCaptureCounterValues;
 
 typedef struct
diff --git a/lib/sp-capture-writer.c b/lib/sp-capture-writer.c
index 4bd8bfd..4570aea 100644
--- a/lib/sp-capture-writer.c
+++ b/lib/sp-capture-writer.c
@@ -1022,13 +1022,13 @@ sp_capture_writer_define_counters (SpCaptureWriter        *self,
 }
 
 gboolean
-sp_capture_writer_set_counters (SpCaptureWriter *self,
-                                gint64           time,
-                                gint             cpu,
-                                GPid             pid,
-                                const guint     *counters_ids,
-                                const gint64    *values,
-                                guint            n_counters)
+sp_capture_writer_set_counters (SpCaptureWriter             *self,
+                                gint64                       time,
+                                gint                         cpu,
+                                GPid                         pid,
+                                const guint                 *counters_ids,
+                                const SpCaptureCounterValue *values,
+                                guint                        n_counters)
 {
   SpCaptureFrameCounterSet *set;
   gsize len;
diff --git a/lib/sp-capture-writer.h b/lib/sp-capture-writer.h
index bdc35bf..901eed5 100644
--- a/lib/sp-capture-writer.h
+++ b/lib/sp-capture-writer.h
@@ -92,7 +92,7 @@ gboolean            sp_capture_writer_set_counters    (SpCaptureWriter         *
                                                        gint                     cpu,
                                                        GPid                     pid,
                                                        const guint             *counters_ids,
-                                                       const gint64            *values,
+                                                       const SpCaptureCounterValue *values,
                                                        guint                    n_counters);
 gboolean            sp_capture_writer_flush           (SpCaptureWriter         *self);
 gboolean            sp_capture_writer_save_as         (SpCaptureWriter         *self,
diff --git a/tests/test-capture.c b/tests/test-capture.c
index a5331e9..d6bd326 100644
--- a/tests/test-capture.c
+++ b/tests/test-capture.c
@@ -195,7 +195,7 @@ test_reader_basic (void)
         g_snprintf (counters[i].description, sizeof counters[i].description, "desc%d", i);
         counters[i].id = i + 1;
         counters[i].type = 0;
-        counters[i].value = i * G_GINT64_CONSTANT (100000000000);
+        counters[i].value.v64 = i * G_GINT64_CONSTANT (100000000000);
       }
 
     r = sp_capture_writer_define_counters (writer, t, -1, -1, counters, G_N_ELEMENTS (counters));
@@ -226,7 +226,7 @@ test_reader_basic (void)
   for (i = 0; i < 1000; i++)
     {
       gint ids[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-      gint64 values[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+      SpCaptureCounterValue values[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
 
       r = sp_capture_writer_set_counters (writer, t, -1,  -1, ids, values, G_N_ELEMENTS (values));
       g_assert_cmpint (r, ==, TRUE);
@@ -254,16 +254,16 @@ test_reader_basic (void)
       g_assert_cmpint (8, ==, set->values[0].ids[7]);
       g_assert_cmpint (9, ==, set->values[1].ids[0]);
       g_assert_cmpint (10, ==, set->values[1].ids[1]);
-      g_assert_cmpint (1, ==, set->values[0].values[0]);
-      g_assert_cmpint (2, ==, set->values[0].values[1]);
-      g_assert_cmpint (3, ==, set->values[0].values[2]);
-      g_assert_cmpint (4, ==, set->values[0].values[3]);
-      g_assert_cmpint (5, ==, set->values[0].values[4]);
-      g_assert_cmpint (6, ==, set->values[0].values[5]);
-      g_assert_cmpint (7, ==, set->values[0].values[6]);
-      g_assert_cmpint (8, ==, set->values[0].values[7]);
-      g_assert_cmpint (9, ==, set->values[1].values[0]);
-      g_assert_cmpint (10, ==, set->values[1].values[1]);
+      g_assert_cmpint (1, ==, set->values[0].values[0].v64);
+      g_assert_cmpint (2, ==, set->values[0].values[1].v64);
+      g_assert_cmpint (3, ==, set->values[0].values[2].v64);
+      g_assert_cmpint (4, ==, set->values[0].values[3].v64);
+      g_assert_cmpint (5, ==, set->values[0].values[4].v64);
+      g_assert_cmpint (6, ==, set->values[0].values[5].v64);
+      g_assert_cmpint (7, ==, set->values[0].values[6].v64);
+      g_assert_cmpint (8, ==, set->values[0].values[7].v64);
+      g_assert_cmpint (9, ==, set->values[1].values[0].v64);
+      g_assert_cmpint (10, ==, set->values[1].values[1].v64);
     }
 
   for (i = 0; i < 1000; i++)


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