[sysprof] libsysprof-ui: add timing info to marks display



commit e9728ad7b6b819cca5a2e72670d87c51c2b80bd6
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jun 14 13:21:24 2019 -0700

    libsysprof-ui: add timing info to marks display

 src/libsysprof-ui/sysprof-marks-view.c     | 65 ++++++++++++++++++++++++++++++
 src/libsysprof-ui/ui/sysprof-marks-view.ui |  1 +
 2 files changed, 66 insertions(+)
---
diff --git a/src/libsysprof-ui/sysprof-marks-view.c b/src/libsysprof-ui/sysprof-marks-view.c
index 54248f8..c09d71d 100644
--- a/src/libsysprof-ui/sysprof-marks-view.c
+++ b/src/libsysprof-ui/sysprof-marks-view.c
@@ -25,8 +25,11 @@
 #include "sysprof-cell-renderer-duration.h"
 #include "sysprof-marks-model.h"
 #include "sysprof-marks-view.h"
+#include "sysprof-ui-private.h"
 #include "sysprof-zoom-manager.h"
 
+#define NSEC_PER_SEC (G_USEC_PER_SEC * 1000L)
+
 typedef struct
 {
   SysprofMarksModelKind        kind;
@@ -169,6 +172,62 @@ sysprof_marks_view_selection_changed_cb (SysprofMarksView *self,
     }
 }
 
+static gboolean
+sysprof_marks_view_tree_view_query_tooltip_cb (SysprofMarksView *self,
+                                               gint              x,
+                                               gint              y,
+                                               gboolean          keyboard_mode,
+                                               GtkTooltip       *tooltip,
+                                               GtkTreeView      *tree_view)
+{
+  SysprofMarksViewPrivate *priv = sysprof_marks_view_get_instance_private (self);
+  g_autoptr(GtkTreePath) path = NULL;
+  GtkTreeViewColumn *column;
+  gint cell_x, cell_y;
+
+  g_assert (SYSPROF_IS_MARKS_VIEW (self));
+  g_assert (GTK_IS_TOOLTIP (tooltip));
+  g_assert (GTK_IS_TREE_VIEW (tree_view));
+
+  if (gtk_tree_view_get_path_at_pos (tree_view, x, y, &path, &column, &cell_x, &cell_y))
+    {
+      GtkTreeModel *model = gtk_tree_view_get_model (tree_view);
+      GtkTreeIter iter;
+
+      if (gtk_tree_model_get_iter (model, &iter, path))
+        {
+          g_autofree gchar *text = NULL;
+          g_autofree gchar *timestr = NULL;
+          g_autofree gchar *tooltip_text = NULL;
+          g_autofree gchar *durationstr = NULL;
+          gint64 begin_time;
+          gint64 duration;
+
+          gtk_tree_model_get (model, &iter,
+                              SYSPROF_MARKS_MODEL_COLUMN_BEGIN_TIME, &begin_time,
+                              SYSPROF_MARKS_MODEL_COLUMN_DURATION, &duration,
+                              SYSPROF_MARKS_MODEL_COLUMN_TEXT, &text,
+                              -1);
+
+          begin_time -= priv->capture_begin_time;
+          durationstr = _sysprof_format_duration (duration);
+
+          if (duration != 0)
+            timestr = g_strdup_printf ("%0.4lf (%s)", begin_time / (gdouble)NSEC_PER_SEC, durationstr);
+          else
+            timestr = g_strdup_printf ("%0.4lf", begin_time / (gdouble)NSEC_PER_SEC);
+
+          tooltip_text = g_strdup_printf ("%s: %s", timestr, text);
+
+          gtk_tooltip_set_text (tooltip, tooltip_text);
+
+          return TRUE;
+        }
+    }
+
+  return FALSE;
+}
+
 static void
 sysprof_marks_view_finalize (GObject *object)
 {
@@ -290,6 +349,12 @@ sysprof_marks_view_init (SysprofMarksView *self)
                            self,
                            G_CONNECT_SWAPPED);
 
+  g_signal_connect_object (priv->tree_view,
+                           "query-tooltip",
+                           G_CALLBACK (sysprof_marks_view_tree_view_query_tooltip_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
+
   g_signal_connect_object (gtk_tree_view_get_selection (priv->tree_view),
                            "changed",
                            G_CALLBACK (sysprof_marks_view_selection_changed_cb),
diff --git a/src/libsysprof-ui/ui/sysprof-marks-view.ui b/src/libsysprof-ui/ui/sysprof-marks-view.ui
index 2c72d9e..5adb71b 100644
--- a/src/libsysprof-ui/ui/sysprof-marks-view.ui
+++ b/src/libsysprof-ui/ui/sysprof-marks-view.ui
@@ -11,6 +11,7 @@
               <object class="GtkTreeView" id="tree_view">
                 <property name="headers-visible">false</property>
                 <property name="enable-grid-lines">horizontal</property>
+                <property name="has-tooltip">true</property>
                 <property name="visible">true</property>
                 <child>
                   <object class="GtkTreeViewColumn" id="duration_column">


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