[sysprof/wip/visualizers] wip on visualizers prototype



commit 81c98be9f604f245ef80e653b31b656c6506689c
Author: Christian Hergert <chergert redhat com>
Date:   Thu Apr 14 22:13:52 2016 -0700

    wip on visualizers prototype

 lib/Makefile.am                |    6 +
 lib/sp-capture-reader.c        |    4 +-
 lib/sp-capture-types.h         |   26 ++-
 lib/sp-capture-writer.c        |   14 +-
 lib/sp-capture-writer.h        |    2 +-
 lib/sp-column-visualizer-row.c |  102 ++++++++++++
 lib/sp-column-visualizer-row.h |   34 ++++
 lib/sp-hostinfo-source.c       |  343 ++++++++++++++++++++++++++++++++++++++++
 lib/sp-hostinfo-source.h       |   35 ++++
 lib/sp-visualizer-row.c        |   41 +++++
 lib/sp-visualizer-row.h        |   52 ++++++
 lib/sysprof-ui.h               |    2 +
 lib/sysprof.h                  |    1 +
 src/resources/theme/shared.css |    2 +
 src/resources/ui/sp-window.ui  |   34 ++++-
 src/sp-window.c                |    4 +
 tests/test-capture.c           |   24 ++--
 17 files changed, 694 insertions(+), 32 deletions(-)
---
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 1af68f8..0a4f1d5 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -53,6 +53,7 @@ headers_DATA = \
        sp-elf-symbol-resolver.h \
        sp-error.h \
        sp-gjs-source.h \
+       sp-hostinfo-source.h \
        sp-jitmap-symbol-resolver.h \
        sp-kernel-symbol.h \
        sp-kernel-symbol-resolver.h \
@@ -77,6 +78,7 @@ libsysprof_ API_VERSION@_la_SOURCES = \
        sp-elf-symbol-resolver.c \
        sp-error.c \
        sp-gjs-source.c \
+       sp-hostinfo-source.c \
        sp-jitmap-symbol-resolver.c \
        sp-kernel-symbol.c \
        sp-kernel-symbol-resolver.c \
@@ -130,6 +132,7 @@ uiheadersdir = $(includedir)/sysprof- API_VERSION@
 uiheaders_DATA = \
        sp-callgraph-view.h \
        sp-cell-renderer-percent.h \
+       sp-column-visualizer-row.h \
        sp-empty-state-view.h \
        sp-failed-state-view.h \
        sp-model-filter.h \
@@ -139,6 +142,7 @@ uiheaders_DATA = \
        sp-profiler-menu-button.h \
        sp-recording-state-view.h \
        sp-scrolled-window.h \
+       sp-visualizer-row.h \
        sysprof-ui.h \
        $(NULL)
 
@@ -146,6 +150,7 @@ libsysprof_ui_ API_VERSION@_la_SOURCES = \
        $(uiheaders_DATA) \
        sp-callgraph-view.c \
        sp-cell-renderer-percent.c \
+       sp-column-visualizer-row.c \
        sp-empty-state-view.c \
        sp-failed-state-view.c \
        sp-model-filter.c \
@@ -155,6 +160,7 @@ libsysprof_ui_ API_VERSION@_la_SOURCES = \
        sp-profiler-menu-button.c \
        sp-recording-state-view.c \
        sp-scrolled-window.c \
+       sp-visualizer-row.c \
        $(NULL)
 
 libsysprof_ui_ API_VERSION@_la_CFLAGS = \
diff --git a/lib/sp-capture-reader.c b/lib/sp-capture-reader.c
index 69582b7..8df0138 100644
--- a/lib/sp-capture-reader.c
+++ b/lib/sp-capture-reader.c
@@ -590,7 +590,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);
         }
     }
 
@@ -641,7 +641,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 0e33da2..7c985ee 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,
@@ -130,12 +138,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
@@ -153,8 +161,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 55c4503..99f80dc 100644
--- a/lib/sp-capture-writer.c
+++ b/lib/sp-capture-writer.c
@@ -1021,13 +1021,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/lib/sp-column-visualizer-row.c b/lib/sp-column-visualizer-row.c
new file mode 100644
index 0000000..f6b1369
--- /dev/null
+++ b/lib/sp-column-visualizer-row.c
@@ -0,0 +1,102 @@
+/* sp-column-visualizer-row.c
+ *
+ * Copyright (C) 2016 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdlib.h>
+
+#include "sp-column-visualizer-row.h"
+
+struct _SpColumnVisualizerRow
+{
+  SpVisualizerRow  parent_instance;
+  SpCaptureReader *reader;
+};
+
+G_DEFINE_TYPE (SpColumnVisualizerRow, sp_column_visualizer_row, SP_TYPE_VISUALIZER_ROW)
+
+static gboolean
+sp_column_visualizer_row_draw (GtkWidget *widget,
+                               cairo_t   *cr)
+{
+  GtkAllocation alloc;
+  gboolean ret;
+  gint i;
+
+  g_assert (SP_IS_COLUMN_VISUALIZER_ROW (widget));
+  g_assert (cr != NULL);
+
+  gtk_widget_get_allocation (widget, &alloc);
+
+  ret = GTK_WIDGET_CLASS (sp_column_visualizer_row_parent_class)->draw (widget, cr);
+
+  cairo_save (cr);
+
+#define WIDTH 10
+#define SPACING 6
+
+  for (i = 10; i < alloc.width; i += WIDTH + SPACING)
+    {
+      GdkRectangle rect;
+
+      rect.x = i;
+      rect.y = alloc.height;
+      rect.width = WIDTH;
+      rect.height = -(rand() % alloc.height);
+
+      gdk_cairo_rectangle (cr, &rect);
+    }
+
+  cairo_set_source_rgba (cr, 0, 0, 0, 0.4);
+  cairo_fill (cr);
+
+  cairo_restore (cr);
+
+  return ret;
+}
+
+static void
+sp_column_visualizer_row_set_reader (SpVisualizerRow *row,
+                                     SpCaptureReader *reader)
+{
+  SpColumnVisualizerRow *self = (SpColumnVisualizerRow *)row;
+
+  g_assert (SP_IS_COLUMN_VISUALIZER_ROW (self));
+
+  if (self->reader != reader)
+    {
+      g_clear_pointer (&self->reader, sp_capture_reader_unref);
+      if (reader)
+        self->reader = sp_capture_reader_ref (reader);
+      gtk_widget_queue_draw (GTK_WIDGET (self));
+    }
+}
+
+static void
+sp_column_visualizer_row_class_init (SpColumnVisualizerRowClass *klass)
+{
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+  SpVisualizerRowClass *visualizer_class = SP_VISUALIZER_ROW_CLASS (klass);
+
+  widget_class->draw = sp_column_visualizer_row_draw;
+
+  visualizer_class->set_reader = sp_column_visualizer_row_set_reader;
+}
+
+static void
+sp_column_visualizer_row_init (SpColumnVisualizerRow *self)
+{
+}
diff --git a/lib/sp-column-visualizer-row.h b/lib/sp-column-visualizer-row.h
new file mode 100644
index 0000000..ce08834
--- /dev/null
+++ b/lib/sp-column-visualizer-row.h
@@ -0,0 +1,34 @@
+/* sp-column-visualizer-row.h
+ *
+ * Copyright (C) 2016 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef SP_COLUMN_VISUALIZER_ROW_H
+#define SP_COLUMN_VISUALIZER_ROW_H
+
+#include "sp-visualizer-row.h"
+
+G_BEGIN_DECLS
+
+#define SP_TYPE_COLUMN_VISUALIZER_ROW (sp_column_visualizer_row_get_type())
+
+G_DECLARE_FINAL_TYPE (SpColumnVisualizerRow, sp_column_visualizer_row, SP, COLUMN_VISUALIZER_ROW, 
SpVisualizerRow)
+
+GtkWidget *sp_column_visualizer_row_new (void);
+
+G_END_DECLS
+
+#endif /* SP_COLUMN_VISUALIZER_ROW_H */
diff --git a/lib/sp-hostinfo-source.c b/lib/sp-hostinfo-source.c
new file mode 100644
index 0000000..ea40d9d
--- /dev/null
+++ b/lib/sp-hostinfo-source.c
@@ -0,0 +1,343 @@
+/* sp-hostinfo-source.c
+ *
+ * Copyright (C) 2016 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <ctype.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "sp-hostinfo-source.h"
+
+struct _SpHostinfoSource
+{
+  GObject          parent_instance;
+
+  guint            handler;
+  gint             n_cpu;
+
+  SpCaptureWriter *writer;
+  GArray          *cpu_info;
+};
+
+typedef struct
+{
+  gint    counter_base;
+  gdouble total;
+  gdouble freq;
+  glong   last_user;
+  glong   last_idle;
+  glong   last_system;
+  glong   last_nice;
+  glong   last_iowait;
+  glong   last_irq;
+  glong   last_softirq;
+  glong   last_steal;
+  glong   last_guest;
+  glong   last_guest_nice;
+} CpuInfo;
+
+static void source_iface_init (SpSourceInterface *iface);
+
+G_DEFINE_TYPE_EXTENDED (SpHostinfoSource, sp_hostinfo_source, G_TYPE_OBJECT, 0,
+                        G_IMPLEMENT_INTERFACE (SP_TYPE_SOURCE, source_iface_init))
+
+SpSource *
+sp_hostinfo_source_new (void)
+{
+  return g_object_new (SP_TYPE_HOSTINFO_SOURCE, NULL);
+}
+
+static void
+poll_cpu (SpHostinfoSource *self)
+{
+  gchar cpu[64] = { 0 };
+  glong user;
+  glong sys;
+  glong nice;
+  glong idle;
+  glong iowait;
+  glong irq;
+  glong softirq;
+  glong steal;
+  glong guest;
+  glong guest_nice;
+  glong user_calc;
+  glong system_calc;
+  glong nice_calc;
+  glong idle_calc;
+  glong iowait_calc;
+  glong irq_calc;
+  glong softirq_calc;
+  glong steal_calc;
+  glong guest_calc;
+  glong guest_nice_calc;
+  gchar *buf = NULL;
+  glong total;
+  gchar *line;
+  gint ret;
+  gint id;
+  gint i;
+
+  if (g_file_get_contents("/proc/stat", &buf, NULL, NULL))
+    {
+      line = buf;
+      for (i = 0; buf[i]; i++)
+        {
+          if (buf[i] == '\n') {
+            buf[i] = '\0';
+            if (g_str_has_prefix(line, "cpu"))
+              {
+                if (isdigit(line[3]))
+                  {
+                    CpuInfo *cpu_info;
+
+                    user = nice = sys = idle = id = 0;
+                    ret = sscanf (line, "%s %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld",
+                                  cpu, &user, &nice, &sys, &idle,
+                                  &iowait, &irq, &softirq, &steal, &guest, &guest_nice);
+                    if (ret != 11)
+                      goto next;
+
+                    ret = sscanf(cpu, "cpu%d", &id);
+
+                    if (ret != 1 || id < 0 || id >= self->n_cpu)
+                      goto next;
+
+                    cpu_info = &g_array_index (self->cpu_info, CpuInfo, id);
+
+                    user_calc = user - cpu_info->last_user;
+                    nice_calc = nice - cpu_info->last_nice;
+                    system_calc = sys - cpu_info->last_system;
+                    idle_calc = idle - cpu_info->last_idle;
+                    iowait_calc = iowait - cpu_info->last_iowait;
+                    irq_calc = irq - cpu_info->last_irq;
+                    softirq_calc = softirq - cpu_info->last_softirq;
+                    steal_calc = steal - cpu_info->last_steal;
+                    guest_calc = guest - cpu_info->last_guest;
+                    guest_nice_calc = guest_nice - cpu_info->last_guest_nice;
+
+                    total = user_calc + nice_calc + system_calc + idle_calc + iowait_calc + irq_calc + 
softirq_calc + steal_calc + guest_calc + guest_nice_calc;
+                    cpu_info->total = ((total - idle_calc) / (gdouble)total) * 100.0;
+
+                    cpu_info->last_user = user;
+                    cpu_info->last_nice = nice;
+                    cpu_info->last_idle = idle;
+                    cpu_info->last_system = sys;
+                    cpu_info->last_iowait = iowait;
+                    cpu_info->last_irq = irq;
+                    cpu_info->last_softirq = softirq;
+                    cpu_info->last_steal = steal;
+                    cpu_info->last_guest = guest;
+                    cpu_info->last_guest_nice = guest_nice;
+                  }
+              } else {
+                /* CPU info comes first. Skip further lines. */
+                break;
+              }
+
+          next:
+            line = &buf[i + 1];
+          }
+      }
+  }
+
+  g_free (buf);
+}
+
+static void
+publish_cpu (SpHostinfoSource *self)
+{
+  SpCaptureCounterValue *counter_values;
+  guint *counter_ids;
+  gint i;
+
+  counter_ids = alloca (sizeof *counter_ids * self->n_cpu * 2);
+  counter_values = alloca (sizeof *counter_values * self->n_cpu * 2);
+
+  for (i = 0; i < self->n_cpu; i++)
+    {
+      CpuInfo *info = &g_array_index (self->cpu_info, CpuInfo, i);
+      SpCaptureCounterValue *value = &counter_values[i*2];
+      guint *id = &counter_ids[i*2];
+
+      *id = info->counter_base;
+      value->vdbl = info->total;
+
+      id++;
+      value++;
+
+      *id = info->counter_base + 1;
+      value->vdbl = info->freq;
+    }
+
+  sp_capture_writer_set_counters (self->writer,
+                                  SP_CAPTURE_CURRENT_TIME,
+                                  getpid (),
+                                  -1,
+                                  counter_ids,
+                                  counter_values,
+                                  self->n_cpu * 2);
+}
+
+static gboolean
+collect_hostinfo_cb (gpointer data)
+{
+  SpHostinfoSource *self = data;
+
+  g_assert (SP_IS_HOSTINFO_SOURCE (self));
+
+  poll_cpu (self);
+  publish_cpu (self);
+
+  return G_SOURCE_CONTINUE;
+}
+
+static void
+sp_hostinfo_source_finalize (GObject *object)
+{
+  SpHostinfoSource *self = (SpHostinfoSource *)object;
+
+  if (self->handler)
+    {
+      g_source_remove (self->handler);
+      self->handler = 0;
+    }
+
+  g_clear_pointer (&self->writer, sp_capture_writer_unref);
+  g_clear_pointer (&self->cpu_info, g_array_unref);
+
+  G_OBJECT_CLASS (sp_hostinfo_source_parent_class)->finalize (object);
+}
+
+static void
+sp_hostinfo_source_class_init (SpHostinfoSourceClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = sp_hostinfo_source_finalize;
+}
+
+static void
+sp_hostinfo_source_init (SpHostinfoSource *self)
+{
+  self->cpu_info = g_array_new (FALSE, TRUE, sizeof (CpuInfo));
+}
+
+static void
+sp_hostinfo_source_set_writer (SpSource        *source,
+                               SpCaptureWriter *writer)
+{
+  SpHostinfoSource *self = (SpHostinfoSource *)source;
+
+  g_assert (SP_IS_HOSTINFO_SOURCE (self));
+  g_assert (writer != NULL);
+
+  g_clear_pointer (&self->writer, sp_capture_writer_unref);
+  self->writer = sp_capture_writer_ref (writer);
+}
+
+static void
+sp_hostinfo_source_start (SpSource *source)
+{
+  SpHostinfoSource *self = (SpHostinfoSource *)source;
+
+  g_assert (SP_IS_HOSTINFO_SOURCE (self));
+
+  self->handler = g_timeout_add (500, collect_hostinfo_cb, self);
+}
+
+static void
+sp_hostinfo_source_stop (SpSource *source)
+{
+  SpHostinfoSource *self = (SpHostinfoSource *)source;
+
+  g_assert (SP_IS_HOSTINFO_SOURCE (self));
+
+  g_source_remove (self->handler);
+  self->handler = 0;
+
+  sp_source_emit_finished (SP_SOURCE (self));
+}
+
+static void
+sp_hostinfo_source_prepare (SpSource *source)
+{
+  SpHostinfoSource *self = (SpHostinfoSource *)source;
+  SpCaptureCounter *counters;
+  gint i;
+
+  g_assert (SP_IS_HOSTINFO_SOURCE (self));
+
+  self->n_cpu = g_get_num_processors ();
+
+  g_array_set_size (self->cpu_info, 0);
+
+  counters = alloca (sizeof *counters * self->n_cpu * 2);
+
+  for (i = 0; i < self->n_cpu; i++)
+    {
+      SpCaptureCounter *ctr = &counters[i*2];
+      CpuInfo info = { 0 };
+
+      /*
+       * Request 2 counter values.
+       * One for CPU and one for Frequency.
+       */
+      info.counter_base = sp_capture_writer_request_counter (self->writer, 2);
+
+      /*
+       * Define counters for capture file.
+       */
+      ctr->id = info.counter_base;
+      ctr->type = SP_CAPTURE_COUNTER_DOUBLE;
+      ctr->value.vdbl = 0;
+      g_strlcpy (ctr->category, "CPU Percent", sizeof ctr->category);
+      g_snprintf (ctr->name, sizeof ctr->name, "Total CPU %d", i);
+      g_snprintf (ctr->description, sizeof ctr->description,
+                  "Total CPU usage %d", i);
+
+      ctr++;
+
+      ctr->id = info.counter_base + 1;
+      ctr->type = SP_CAPTURE_COUNTER_DOUBLE;
+      ctr->value.vdbl = 0;
+      g_strlcpy (ctr->category, "CPU Frequency", sizeof ctr->category);
+      g_snprintf (ctr->name, sizeof ctr->name, "CPU %d", i);
+      g_snprintf (ctr->description, sizeof ctr->description,
+                  "Frequency of CPU %d", i);
+
+      g_array_append_val (self->cpu_info, info);
+    }
+
+  sp_capture_writer_define_counters (self->writer,
+                                     SP_CAPTURE_CURRENT_TIME,
+                                     getpid (),
+                                     -1,
+                                     counters,
+                                     self->n_cpu * 2);
+
+  sp_source_emit_ready (SP_SOURCE (self));
+}
+
+static void
+source_iface_init (SpSourceInterface *iface)
+{
+  iface->set_writer = sp_hostinfo_source_set_writer;
+  iface->prepare = sp_hostinfo_source_prepare;
+  iface->start = sp_hostinfo_source_start;
+  iface->stop = sp_hostinfo_source_stop;
+}
diff --git a/lib/sp-hostinfo-source.h b/lib/sp-hostinfo-source.h
new file mode 100644
index 0000000..873dd11
--- /dev/null
+++ b/lib/sp-hostinfo-source.h
@@ -0,0 +1,35 @@
+/* sp-hostinfo-source.h
+ *
+ * Copyright (C) 2016 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef SP_HOSTINFO_SOURCE_H
+#define SP_HOSTINFO_SOURCE_H
+
+#include "sp-source.h"
+
+G_BEGIN_DECLS
+
+#define SP_TYPE_HOSTINFO_SOURCE (sp_hostinfo_source_get_type())
+
+G_DECLARE_FINAL_TYPE (SpHostinfoSource, sp_hostinfo_source, SP, HOSTINFO_SOURCE, GObject)
+
+SpSource *sp_hostinfo_source_new (void);
+
+G_END_DECLS
+
+#endif /* SP_HOSTINFO_SOURCE_H */
+
diff --git a/lib/sp-visualizer-row.c b/lib/sp-visualizer-row.c
new file mode 100644
index 0000000..c601888
--- /dev/null
+++ b/lib/sp-visualizer-row.c
@@ -0,0 +1,41 @@
+/* sp-visualizer-row.c
+ *
+ * Copyright (C) 2016 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "sp-visualizer-row.h"
+
+G_DEFINE_ABSTRACT_TYPE (SpVisualizerRow, sp_visualizer_row, GTK_TYPE_LIST_BOX_ROW)
+
+static void
+sp_visualizer_row_class_init (SpVisualizerRowClass *klass)
+{
+}
+
+static void
+sp_visualizer_row_init (SpVisualizerRow *self)
+{
+}
+
+void
+sp_visualizer_row_set_reader (SpVisualizerRow *self,
+                              SpCaptureReader *reader)
+{
+  g_return_if_fail (SP_IS_VISUALIZER_ROW (self));
+
+  if (SP_VISUALIZER_ROW_GET_CLASS (self)->set_reader)
+    SP_VISUALIZER_ROW_GET_CLASS (self)->set_reader (self, reader);
+}
diff --git a/lib/sp-visualizer-row.h b/lib/sp-visualizer-row.h
new file mode 100644
index 0000000..137fdd8
--- /dev/null
+++ b/lib/sp-visualizer-row.h
@@ -0,0 +1,52 @@
+/* sp-visualizer-row.h
+ *
+ * Copyright (C) 2016 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef SP_VISUALIZER_ROW_H
+#define SP_VISUALIZER_ROW_H
+
+#include <gtk/gtk.h>
+
+#include "sp-capture-reader.h"
+
+G_BEGIN_DECLS
+
+#define SP_TYPE_VISUALIZER_ROW (sp_visualizer_row_get_type())
+
+G_DECLARE_DERIVABLE_TYPE (SpVisualizerRow, sp_visualizer_row, SP, VISUALIZER_ROW, GtkListBoxRow)
+
+struct _SpVisualizerRowClass
+{
+  GtkListBoxRowClass parent_class;
+
+  /**
+   * SpVisualizerRow::set_reader:
+   *
+   * Sets the reader that the row should use to extract counters.
+   * This reader is private to the row and should be freed when
+   * no longer in use with sp_capture_reader_unref().
+   */
+  void (*set_reader) (SpVisualizerRow *self,
+                      SpCaptureReader *reader);
+};
+
+void sp_visualizer_row_set_reader (SpVisualizerRow *self,
+                                   SpCaptureReader *reader);
+
+G_END_DECLS
+
+#endif /* SP_VISUALIZER_ROW_H */
diff --git a/lib/sysprof-ui.h b/lib/sysprof-ui.h
index 6212ece..569249f 100644
--- a/lib/sysprof-ui.h
+++ b/lib/sysprof-ui.h
@@ -26,6 +26,7 @@ G_BEGIN_DECLS
 #define SYSPROF_INSIDE
 # include "sp-callgraph-view.h"
 # include "sp-cell-renderer-percent.h"
+# include "sp-column-visualizer-row.h"
 # include "sp-empty-state-view.h"
 # include "sp-model-filter.h"
 # include "sp-recording-state-view.h"
@@ -34,6 +35,7 @@ G_BEGIN_DECLS
 # include "sp-process-model-row.h"
 # include "sp-profiler-menu-button.h"
 # include "sp-scrolled-window.h"
+# include "sp-visualizer-row.h"
 #undef SYSPROF_INSIDE
 
 G_END_DECLS
diff --git a/lib/sysprof.h b/lib/sysprof.h
index 0ff7db7..30e17c9 100644
--- a/lib/sysprof.h
+++ b/lib/sysprof.h
@@ -32,6 +32,7 @@ G_BEGIN_DECLS
 # include "sp-elf-symbol-resolver.h"
 # include "sp-error.h"
 # include "sp-gjs-source.h"
+# include "sp-hostinfo-source.h"
 # include "sp-jitmap-symbol-resolver.h"
 # include "sp-kernel-symbol-resolver.h"
 # include "sp-kernel-symbol.h"
diff --git a/src/resources/theme/shared.css b/src/resources/theme/shared.css
index 3d4da45..b7c73f1 100644
--- a/src/resources/theme/shared.css
+++ b/src/resources/theme/shared.css
@@ -1,8 +1,10 @@
+paned list row,
 popover list row {
   padding: 6px 10px 6px 10px;
   border-bottom: 1px solid alpha(@borders, 0.2);
 }
 
+paned list row:last-child,
 popover list row:last-child {
   border-bottom: none;
 }
diff --git a/src/resources/ui/sp-window.ui b/src/resources/ui/sp-window.ui
index 298c464..20af795 100644
--- a/src/resources/ui/sp-window.ui
+++ b/src/resources/ui/sp-window.ui
@@ -159,8 +159,40 @@
               </packing>
             </child>
             <child>
-              <object class="SpCallgraphView" id="callgraph_view">
+              <object class="GtkPaned">
+                <property name="orientation">vertical</property>
                 <property name="visible">true</property>
+                <child>
+                  <object class="SpScrolledWindow">
+                    <property name="min-content-height">75</property>
+                    <property name="max-content-height">225</property>
+                    <property name="visible">true</property>
+                    <child>
+                      <object class="GtkListBox" id="visuals_list_box">
+                        <property name="visible">true</property>
+                        <child>
+                          <object class="SpColumnVisualizerRow">
+                            <property name="height-request">75</property>
+                            <property name="selectable">false</property>
+                            <property name="visible">true</property>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="SpColumnVisualizerRow">
+                            <property name="height-request">75</property>
+                            <property name="selectable">false</property>
+                            <property name="visible">true</property>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child>
+                  <object class="SpCallgraphView" id="callgraph_view">
+                    <property name="visible">true</property>
+                  </object>
+                </child>
               </object>
               <packing>
                 <property name="name">browsing</property>
diff --git a/src/sp-window.c b/src/sp-window.c
index 36c0e8f..cd6dbca 100644
--- a/src/sp-window.c
+++ b/src/sp-window.c
@@ -356,6 +356,7 @@ static void
 sp_window_add_sources (SpWindow   *window,
                        SpProfiler *profiler)
 {
+  g_autoptr(SpSource) host_source = NULL;
   g_autoptr(SpSource) proc_source = NULL;
   g_autoptr(SpSource) perf_source = NULL;
 
@@ -367,6 +368,9 @@ sp_window_add_sources (SpWindow   *window,
 
   perf_source = sp_perf_source_new ();
   sp_profiler_add_source (profiler, perf_source);
+
+  host_source = sp_hostinfo_source_new ();
+  sp_profiler_add_source (profiler, host_source);
 }
 
 static void
diff --git a/tests/test-capture.c b/tests/test-capture.c
index f353a93..0d05d9e 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]