From 9797efbe7d6e16239e119e2354ddab18601b7646 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Thu, 16 May 2019 19:16:15 -0700 Subject: [PATCH] libsysprof-ui: add some mark details --- src/libsysprof-ui/sysprof-capture-view.c | 74 +++++ src/libsysprof-ui/sysprof-details-view.c | 25 ++ src/libsysprof-ui/sysprof-details-view.h | 3 + src/libsysprof-ui/ui/sysprof-capture-view.ui | 1 - src/libsysprof-ui/ui/sysprof-details-view.ui | 307 ++++++++++--------- 5 files changed, 260 insertions(+), 150 deletions(-) diff --git a/src/libsysprof-ui/sysprof-capture-view.c b/src/libsysprof-ui/sysprof-capture-view.c index a704a157..a97314f4 100644 --- a/src/libsysprof-ui/sysprof-capture-view.c +++ b/src/libsysprof-ui/sysprof-capture-view.c @@ -22,6 +22,8 @@ #include "config.h" +#include + #include "sysprof-callgraph-view.h" #include "sysprof-capture-view.h" #include "sysprof-details-view.h" @@ -29,6 +31,8 @@ #include "sysprof-ui-private.h" #include "sysprof-visualizer-view.h" +#define NSEC_PER_SEC (G_USEC_PER_SEC * 1000L) + typedef struct { gint64 begin_time; @@ -42,6 +46,7 @@ typedef struct { SysprofCaptureReader *reader; GCancellable *cancellable; + GHashTable *mark_stats; SysprofCaptureFeatures features; @@ -122,6 +127,62 @@ sysprof_capture_view_new (void) return g_object_new (SYSPROF_TYPE_CAPTURE_VIEW, NULL); } +static void +add_marks_to_details (SysprofCaptureView *self) +{ + SysprofCaptureViewPrivate *priv = sysprof_capture_view_get_instance_private (self); + GHashTableIter iter; + gpointer k, v; + guint count = 0; + + g_assert (SYSPROF_IS_CAPTURE_VIEW (self)); + + if (priv->mark_stats == NULL) + return; + + if (g_hash_table_size (priv->mark_stats) == 0) + return; + + g_hash_table_iter_init (&iter, priv->mark_stats); + while (count < 100 && g_hash_table_iter_next (&iter, &k, &v)) + { + g_autofree gchar *str = NULL; + SysprofMarkStat *st = v; + GtkLabel *left_label; + GtkLabel *center_label; + + if (st->avg == 0) + continue; + + left_label = g_object_new (GTK_TYPE_LABEL, + "visible", TRUE, + "xalign", 1.0f, + "label", st->name, + "ellipsize", PANGO_ELLIPSIZE_START, + NULL); + gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (left_label)), + GTK_STYLE_CLASS_DIM_LABEL); + str = g_strdup_printf ("Min: %.4lf " + "Max: %.4lf " + "Ø: %.4lf", + st->min / (gdouble)NSEC_PER_SEC, + st->max / (gdouble)NSEC_PER_SEC, + st->avg / (gdouble)NSEC_PER_SEC); + center_label = g_object_new (GTK_TYPE_LABEL, + "label", str, + "use-markup", TRUE, + "visible", TRUE, + "xalign", 0.0f, + NULL); + + sysprof_details_view_add_item (priv->details_view, + GTK_WIDGET (left_label), + GTK_WIDGET (center_label)); + + count++; + } +} + static void sysprof_capture_view_task_completed (SysprofCaptureView *self, GParamSpec *pspec, @@ -348,6 +409,11 @@ sysprof_capture_view_scan_worker (GTask *task, sysprof_capture_reader_set_stat (reader, &st_buf); + g_object_set_data_full (G_OBJECT (task), + "MARK_STAT", + g_steal_pointer (&mark_stats), + (GDestroyNotify) g_hash_table_unref); + if (!g_task_return_error_if_cancelled (task)) { priv->features = features; @@ -384,6 +450,7 @@ sysprof_capture_view_scan_finish (SysprofCaptureView *self, GError **error) { SysprofCaptureViewPrivate *priv = sysprof_capture_view_get_instance_private (self); + GHashTable *stats; g_assert (SYSPROF_IS_CAPTURE_VIEW (self)); g_assert (G_IS_TASK (result)); @@ -391,6 +458,12 @@ sysprof_capture_view_scan_finish (SysprofCaptureView *self, if (!priv->features.has_samples && priv->features.has_marks) gtk_stack_set_visible_child_name (priv->stack, "timings"); + g_clear_pointer (&priv->mark_stats, g_hash_table_unref); + if ((stats = g_object_get_data (G_OBJECT (result), "MARK_STAT"))) + priv->mark_stats = g_hash_table_ref (stats); + + add_marks_to_details (self); + return g_task_propagate_boolean (G_TASK (result), error); } @@ -671,6 +744,7 @@ sysprof_capture_view_finalize (GObject *object) SysprofCaptureView *self = (SysprofCaptureView *)object; SysprofCaptureViewPrivate *priv = sysprof_capture_view_get_instance_private (self); + g_clear_pointer (&priv->mark_stats, g_hash_table_unref); g_clear_pointer (&priv->reader, sysprof_capture_reader_unref); g_clear_object (&priv->cancellable); diff --git a/src/libsysprof-ui/sysprof-details-view.c b/src/libsysprof-ui/sysprof-details-view.c index 050a54f0..d09ccbb5 100644 --- a/src/libsysprof-ui/sysprof-details-view.c +++ b/src/libsysprof-ui/sysprof-details-view.c @@ -31,6 +31,10 @@ struct _SysprofDetailsView { GtkBin parent_instance; + + /* Template Objects */ + GtkBox *left_box; + GtkBox *center_box; GtkLabel *duration; GtkLabel *filename; GtkLabel *forks; @@ -38,6 +42,7 @@ struct _SysprofDetailsView GtkLabel *processes; GtkLabel *samples; GtkLabel *start_time; + GtkBox *vbox; }; G_DEFINE_TYPE (SysprofDetailsView, sysprof_details_view, GTK_TYPE_BIN) @@ -87,6 +92,9 @@ sysprof_details_view_class_init (SysprofDetailsViewClass *klass) gtk_widget_class_bind_template_child (widget_class, SysprofDetailsView, processes); gtk_widget_class_bind_template_child (widget_class, SysprofDetailsView, samples); gtk_widget_class_bind_template_child (widget_class, SysprofDetailsView, start_time); + gtk_widget_class_bind_template_child (widget_class, SysprofDetailsView, vbox); + gtk_widget_class_bind_template_child (widget_class, SysprofDetailsView, left_box); + gtk_widget_class_bind_template_child (widget_class, SysprofDetailsView, center_box); } static void @@ -150,3 +158,20 @@ sysprof_details_view_set_reader (SysprofDetailsView *self, #undef SET_FRAME_COUNT } } + +void +sysprof_details_view_add_item (SysprofDetailsView *self, + GtkWidget *left, + GtkWidget *center) +{ + g_return_if_fail (SYSPROF_IS_DETAILS_VIEW (self)); + g_return_if_fail (GTK_IS_WIDGET (left)); + g_return_if_fail (GTK_IS_WIDGET (center)); + + gtk_container_add_with_properties (GTK_CONTAINER (self->left_box), left, + "pack-type", GTK_PACK_START, + "expand", TRUE, + "fill", TRUE, + NULL); + gtk_container_add (GTK_CONTAINER (self->center_box), center); +} diff --git a/src/libsysprof-ui/sysprof-details-view.h b/src/libsysprof-ui/sysprof-details-view.h index d11d7f6d..defe8bf8 100644 --- a/src/libsysprof-ui/sysprof-details-view.h +++ b/src/libsysprof-ui/sysprof-details-view.h @@ -32,5 +32,8 @@ G_DECLARE_FINAL_TYPE (SysprofDetailsView, sysprof_details_view, SYSPROF, DETAILS GtkWidget *sysprof_details_view_new (void); void sysprof_details_view_set_reader (SysprofDetailsView *self, SysprofCaptureReader *reader); +void sysprof_details_view_add_item (SysprofDetailsView *self, + GtkWidget *left, + GtkWidget *center); G_END_DECLS diff --git a/src/libsysprof-ui/ui/sysprof-capture-view.ui b/src/libsysprof-ui/ui/sysprof-capture-view.ui index 1071cc85..4cc195b0 100644 --- a/src/libsysprof-ui/ui/sysprof-capture-view.ui +++ b/src/libsysprof-ui/ui/sysprof-capture-view.ui @@ -142,7 +142,6 @@ - 36 true diff --git a/src/libsysprof-ui/ui/sysprof-details-view.ui b/src/libsysprof-ui/ui/sysprof-details-view.ui index f4863a44..87652dd6 100644 --- a/src/libsysprof-ui/ui/sysprof-details-view.ui +++ b/src/libsysprof-ui/ui/sysprof-details-view.ui @@ -5,169 +5,178 @@