[sysprof/wip/visualizers] wip: visualizers
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sysprof/wip/visualizers] wip: visualizers
- Date: Fri, 15 Apr 2016 13:24:14 +0000 (UTC)
commit 7530a0ecf2479102e9821c9002770d13dc02b0fb
Author: Christian Hergert <chergert redhat com>
Date: Fri Apr 15 06:23:53 2016 -0700
wip: visualizers
lib/Makefile.am | 6 +
lib/sp-hostinfo-source.c | 343 ++++++++++++++++++++++++++++++++++
lib/sp-hostinfo-source.h | 35 ++++
lib/sp-line-visualizer-row.c | 396 ++++++++++++++++++++++++++++++++++++++++
lib/sp-line-visualizer-row.h | 36 ++++
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 | 28 +++-
src/sp-window.c | 10 +
tools/sysprof-cli.c | 3 +
13 files changed, 954 insertions(+), 1 deletions(-)
---
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 1af68f8..14e44f0 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 \
@@ -132,6 +134,7 @@ uiheaders_DATA = \
sp-cell-renderer-percent.h \
sp-empty-state-view.h \
sp-failed-state-view.h \
+ sp-line-visualizer-row.h \
sp-model-filter.h \
sp-process-model.h \
sp-process-model-item.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)
@@ -148,6 +152,7 @@ libsysprof_ui_ API_VERSION@_la_SOURCES = \
sp-cell-renderer-percent.c \
sp-empty-state-view.c \
sp-failed-state-view.c \
+ sp-line-visualizer-row.c \
sp-model-filter.c \
sp-process-model.c \
sp-process-model-item.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-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-line-visualizer-row.c b/lib/sp-line-visualizer-row.c
new file mode 100644
index 0000000..0ae5826
--- /dev/null
+++ b/lib/sp-line-visualizer-row.c
@@ -0,0 +1,396 @@
+/* sp-line-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-line-visualizer-row.h"
+
+typedef struct
+{
+ gint64 time;
+ SpCaptureCounterValue value;
+} LineDataItem;
+
+typedef struct
+{
+ guint id;
+ guint type;
+ GArray *values;
+} LineData;
+
+struct _SpLineVisualizerRow
+{
+ SpVisualizerRow parent_instance;
+
+ SpCaptureReader *reader;
+
+ GHashTable *counters;
+
+ GtkLabel *label;
+
+ guint needs_recalc : 1;
+
+ gint64 start_time;
+ gint64 duration;
+};
+
+G_DEFINE_TYPE (SpLineVisualizerRow, sp_line_visualizer_row, SP_TYPE_VISUALIZER_ROW)
+
+enum {
+ PROP_0,
+ PROP_TITLE,
+ N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
+
+static void
+line_data_free (gpointer data)
+{
+ LineData *ld = data;
+
+ if (ld != NULL)
+ {
+ g_array_unref (ld->values);
+ g_free (ld);
+ }
+}
+
+static void
+sp_line_visualizer_row_recalc (SpLineVisualizerRow *self)
+{
+ GHashTable *new_data;
+ SpCaptureFrame frame;
+
+ g_assert (SP_IS_LINE_VISUALIZER_ROW (self));
+
+ self->needs_recalc = FALSE;
+
+ if (self->reader == NULL)
+ return;
+
+ sp_capture_reader_reset (self->reader);
+
+ self->start_time = sp_capture_reader_get_start_time (self->reader);
+ self->duration = 0;
+
+ new_data = g_hash_table_new_full (NULL, NULL, NULL, line_data_free);
+
+ while (sp_capture_reader_peek_frame (self->reader, &frame))
+ {
+ gint64 relative;
+
+ if (frame.time < self->start_time)
+ frame.time = self->start_time;
+
+ relative = frame.time - self->start_time;
+ if (relative > self->duration)
+ self->duration = relative;
+
+ if (frame.type == SP_CAPTURE_FRAME_CTRDEF)
+ {
+ const SpCaptureFrameCounterDefine *def;
+ guint i;
+
+ if (NULL == (def = sp_capture_reader_read_counter_define (self->reader)))
+ return;
+
+ for (i = 0; i < def->n_counters; i++)
+ {
+ const SpCaptureCounter *ctr = &def->counters[i];
+
+ if (g_hash_table_contains (self->counters, GSIZE_TO_POINTER (ctr->id)))
+ {
+ LineData *ld = g_hash_table_lookup (new_data, GSIZE_TO_POINTER (ctr->id));
+ LineDataItem item;
+
+ if (ld == NULL)
+ {
+ ld = g_new (LineData, 1);
+ ld->id = ctr->id;
+ ld->type = ctr->type;
+ ld->values = g_array_new (FALSE, FALSE, sizeof (LineDataItem));
+ g_hash_table_insert (new_data, GSIZE_TO_POINTER (ctr->id), ld);
+ }
+
+ item.time = MAX (self->start_time, def->frame.time) - self->start_time;
+ item.value = ctr->value;
+
+ g_array_append_val (ld->values, item);
+ }
+ }
+ }
+ else if (frame.type == SP_CAPTURE_FRAME_CTRSET)
+ {
+ const SpCaptureFrameCounterSet *set;
+ LineDataItem item;
+ guint i;
+
+ if (NULL == (set = sp_capture_reader_read_counter_set (self->reader)))
+ return;
+
+ item.time = MAX (self->start_time, set->frame.time) - self->start_time;
+
+ for (i = 0; i < set->n_values; i++)
+ {
+ const SpCaptureCounterValues *values = &set->values[i];
+ guint j;
+
+ for (j = 0; j < G_N_ELEMENTS (values->values); j++)
+ {
+ LineData *ld;
+
+ if (values->ids[j] == 0)
+ break;
+
+ ld = g_hash_table_lookup (new_data, GSIZE_TO_POINTER (values->ids[j]));
+
+ /* possible there was no matching ctrdef */
+ if (ld == NULL)
+ continue;
+
+ item.value = values->values[j];
+
+ g_array_append_val (ld->values, item);
+ }
+ }
+ }
+ else if (!sp_capture_reader_skip (self->reader))
+ return;
+ }
+
+ g_clear_pointer (&self->counters, g_hash_table_unref);
+ self->counters = new_data;
+}
+
+static inline gdouble
+calc_x (SpLineVisualizerRow *self,
+ gint64 time)
+{
+ gdouble ret = (gdouble)time / (gdouble)self->duration;
+ return ret;
+}
+
+static inline gdouble
+calc_y (SpLineVisualizerRow *self,
+ LineData *ld,
+ SpCaptureCounterValue value)
+{
+ gdouble ret = value.vdbl / 100.0;
+ return ret;
+}
+
+static gboolean
+sp_line_visualizer_row_draw (GtkWidget *widget,
+ cairo_t *cr)
+{
+ SpLineVisualizerRow *self = (SpLineVisualizerRow *)widget;
+ GtkAllocation alloc;
+ GHashTableIter iter;
+ gboolean ret;
+ gpointer key, val;
+ guint i;
+
+ g_assert (SP_IS_LINE_VISUALIZER_ROW (widget));
+ g_assert (cr != NULL);
+
+ if (self->needs_recalc)
+ sp_line_visualizer_row_recalc (self);
+
+ gtk_widget_get_allocation (widget, &alloc);
+
+ ret = GTK_WIDGET_CLASS (sp_line_visualizer_row_parent_class)->draw (widget, cr);
+
+ cairo_save (cr);
+
+ g_hash_table_iter_init (&iter, self->counters);
+
+ while (g_hash_table_iter_next (&iter, &key, &val))
+ {
+ LineData *ld = val;
+ gdouble last_x = 0;
+ gdouble last_y = 0;
+
+ cairo_move_to (cr, 0, alloc.height);
+
+ for (i = 0; i < ld->values->len; i++)
+ {
+ LineDataItem *item = &g_array_index (ld->values, LineDataItem, i);
+ gdouble x;
+ gdouble y;
+
+ x = calc_x (self, item->time) * alloc.width;
+ y = alloc.height - (calc_y (self, ld, item->value) * alloc.height);
+
+ //g_print ("x=%d y =%d\n", (int)x, (int)y);
+
+ cairo_line_to (cr, x, y);
+
+ (void)last_x;
+ (void)last_y;
+
+ last_x = x;
+ last_y = x;
+ }
+
+ cairo_line_to (cr, alloc.width, alloc.height);
+ cairo_line_to (cr, 0, alloc.height);
+ cairo_set_line_width (cr, 1.0);
+ cairo_set_source_rgba (cr, 0, 0, 0, 0.4);
+ cairo_stroke_preserve (cr);
+ cairo_set_source_rgba (cr, 0, 0, 0, 0.2);
+ cairo_fill (cr);
+ }
+
+ cairo_restore (cr);
+
+ return ret;
+}
+
+static void
+sp_line_visualizer_row_set_reader (SpVisualizerRow *row,
+ SpCaptureReader *reader)
+{
+ SpLineVisualizerRow *self = (SpLineVisualizerRow *)row;
+
+ g_assert (SP_IS_LINE_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);
+ self->start_time = 0;
+ self->duration = 0;
+ }
+
+ /* TODO */
+ sp_line_visualizer_row_add_counter (self, 1);
+ sp_line_visualizer_row_add_counter (self, 3);
+ sp_line_visualizer_row_add_counter (self, 5);
+ sp_line_visualizer_row_add_counter (self, 7);
+
+ gtk_widget_queue_draw (GTK_WIDGET (self));
+ }
+}
+
+static void
+sp_line_visualizer_row_finalize (GObject *object)
+{
+ SpLineVisualizerRow *self = (SpLineVisualizerRow *)object;
+
+ g_clear_pointer (&self->counters, g_hash_table_unref);
+ g_clear_pointer (&self->reader, sp_capture_reader_unref);
+
+ G_OBJECT_CLASS (sp_line_visualizer_row_parent_class)->finalize (object);
+}
+
+static void
+sp_line_visualizer_row_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ SpLineVisualizerRow *self = SP_LINE_VISUALIZER_ROW (object);
+
+ switch (prop_id)
+ {
+ case PROP_TITLE:
+ g_object_get_property (G_OBJECT (self->label), "label", value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+sp_line_visualizer_row_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ SpLineVisualizerRow *self = SP_LINE_VISUALIZER_ROW (object);
+
+ switch (prop_id)
+ {
+ case PROP_TITLE:
+ g_object_set_property (G_OBJECT (self->label), "label", value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+sp_line_visualizer_row_class_init (SpLineVisualizerRowClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ SpVisualizerRowClass *visualizer_class = SP_VISUALIZER_ROW_CLASS (klass);
+
+ object_class->finalize = sp_line_visualizer_row_finalize;
+ object_class->get_property = sp_line_visualizer_row_get_property;
+ object_class->set_property = sp_line_visualizer_row_set_property;
+
+ widget_class->draw = sp_line_visualizer_row_draw;
+
+ visualizer_class->set_reader = sp_line_visualizer_row_set_reader;
+
+ properties [PROP_TITLE] =
+ g_param_spec_string ("title",
+ "Title",
+ "The title of the row",
+ NULL,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+sp_line_visualizer_row_init (SpLineVisualizerRow *self)
+{
+ PangoAttrList *attrs = NULL;
+
+ self->counters = g_hash_table_new (NULL, NULL);
+
+ attrs = pango_attr_list_new ();
+ pango_attr_list_insert (attrs, pango_attr_scale_new (PANGO_SCALE_SMALL * PANGO_SCALE_SMALL));
+ self->label = g_object_new (GTK_TYPE_LABEL,
+ "attributes", attrs,
+ "visible", TRUE,
+ "xalign", 0.0f,
+ "yalign", 0.0f,
+ NULL);
+ gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (self->label));
+ pango_attr_list_unref (attrs);
+}
+
+void
+sp_line_visualizer_row_add_counter (SpLineVisualizerRow *self,
+ guint counter_id)
+{
+ g_assert (SP_IS_LINE_VISUALIZER_ROW (self));
+
+ self->needs_recalc = TRUE;
+ g_hash_table_insert (self->counters, GSIZE_TO_POINTER (counter_id), NULL);
+ gtk_widget_queue_draw (GTK_WIDGET (self));
+}
diff --git a/lib/sp-line-visualizer-row.h b/lib/sp-line-visualizer-row.h
new file mode 100644
index 0000000..bf6aef8
--- /dev/null
+++ b/lib/sp-line-visualizer-row.h
@@ -0,0 +1,36 @@
+/* sp-line-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_LINE_VISUALIZER_ROW_H
+#define SP_LINE_VISUALIZER_ROW_H
+
+#include "sp-visualizer-row.h"
+
+G_BEGIN_DECLS
+
+#define SP_TYPE_LINE_VISUALIZER_ROW (sp_line_visualizer_row_get_type())
+
+G_DECLARE_FINAL_TYPE (SpLineVisualizerRow, sp_line_visualizer_row, SP, LINE_VISUALIZER_ROW, SpVisualizerRow)
+
+GtkWidget *sp_line_visualizer_row_new (void);
+void sp_line_visualizer_row_add_counter (SpLineVisualizerRow *self,
+ guint counter_id);
+
+G_END_DECLS
+
+#endif /* SP_LINE_VISUALIZER_ROW_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..147767e 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-line-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..9704774 100644
--- a/src/resources/ui/sp-window.ui
+++ b/src/resources/ui/sp-window.ui
@@ -159,8 +159,34 @@
</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="visualizer_rows">
+ <property name="visible">true</property>
+ <child>
+ <object class="SpLineVisualizerRow" id="cpu_row">
+ <property name="title" translatable="yes">CPU</property>
+ <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..a37abc5 100644
--- a/src/sp-window.c
+++ b/src/sp-window.c
@@ -48,6 +48,7 @@ struct _SpWindow
GtkLabel *stat_label;
GtkLabel *title;
GtkStack *view_stack;
+ GtkListBox *visualizer_rows;
guint stats_handler;
@@ -212,6 +213,10 @@ sp_window_build_profile_cb (GObject *object,
sp_callgraph_view_set_profile (self->callgraph_view, SP_CALLGRAPH_PROFILE (profile));
sp_window_set_state (self, SP_WINDOW_STATE_BROWSING);
+
+ gtk_container_foreach (GTK_CONTAINER (self->visualizer_rows),
+ (GtkCallback)sp_visualizer_row_set_reader,
+ self->reader);
}
static void
@@ -356,6 +361,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 +373,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
@@ -752,6 +761,7 @@ sp_window_class_init (SpWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, SpWindow, subtitle);
gtk_widget_class_bind_template_child (widget_class, SpWindow, title);
gtk_widget_class_bind_template_child (widget_class, SpWindow, view_stack);
+ gtk_widget_class_bind_template_child (widget_class, SpWindow, visualizer_rows);
}
static void
diff --git a/tools/sysprof-cli.c b/tools/sysprof-cli.c
index 6421768..50f7e06 100644
--- a/tools/sysprof-cli.c
+++ b/tools/sysprof-cli.c
@@ -190,7 +190,10 @@ main (gint argc,
g_object_unref (source);
source = sp_perf_source_new ();
+ sp_profiler_add_source (profiler, source);
+ g_object_unref (source);
+ source = sp_hostinfo_source_new ();
sp_profiler_add_source (profiler, source);
g_object_unref (source);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]