diff --git a/src/libsysprof-ui/sysprof-details-view.c b/src/libsysprof-ui/sysprof-details-view.c index 0fd6f371..1f8ca447 100644 --- a/src/libsysprof-ui/sysprof-details-view.c +++ b/src/libsysprof-ui/sysprof-details-view.c @@ -18,12 +18,17 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE +#endif + #define G_LOG_DOMAIN "sysprof-details-view" #include "config.h" #include #include +#include #include "sysprof-details-view.h" #include "sysprof-ui-private.h" @@ -46,6 +51,7 @@ struct _SysprofDetailsView GtkLabel *processes; GtkLabel *samples; GtkLabel *start_time; + GtkLabel *cpu_label; guint next_row; }; @@ -91,6 +97,7 @@ sysprof_details_view_class_init (SysprofDetailsViewClass *klass) gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/ui/sysprof-details-view.ui"); gtk_widget_class_bind_template_child (widget_class, SysprofDetailsView, counters); + gtk_widget_class_bind_template_child (widget_class, SysprofDetailsView, cpu_label); gtk_widget_class_bind_template_child (widget_class, SysprofDetailsView, duration); gtk_widget_class_bind_template_child (widget_class, SysprofDetailsView, filename); gtk_widget_class_bind_template_child (widget_class, SysprofDetailsView, forks); @@ -122,6 +129,85 @@ sysprof_details_view_new (void) return g_object_new (SYSPROF_TYPE_DETAILS_VIEW, NULL); } +static void +update_cpu_info_cb (GObject *object, + GAsyncResult *result, + gpointer user_data) +{ + g_autoptr(SysprofDetailsView) self = user_data; + g_autofree gchar *str = NULL; + + g_assert (SYSPROF_IS_DETAILS_VIEW (self)); + g_assert (G_IS_TASK (result)); + + if ((str = g_task_propagate_pointer (G_TASK (result), NULL))) + gtk_label_set_label (self->cpu_label, str); +} + +static gboolean +cpu_info_cb (const SysprofCaptureFrame *frame, + gpointer user_data) +{ + const SysprofCaptureFileChunk *fc = (gpointer)frame; + const gchar *endptr; + const gchar *line; + gchar **str = user_data; + + endptr = (gchar *)fc->data + fc->len; + line = memmem ((gchar *)fc->data, fc->len, "model name", 10); + endptr = memchr (line, '\n', endptr - line); + + if (endptr) + { + gchar *tmp = *str = g_strndup (line, endptr - line); + for (; *tmp && *tmp != ':'; tmp++) + *tmp = ' '; + if (*tmp == ':') + *tmp = ' '; + g_strstrip (*str); + return FALSE; + } + + return TRUE; +} + +static void +sysprof_details_view_update_cpu_info_worker (GTask *task, + gpointer source_object, + gpointer task_data, + GCancellable *cancellable) +{ + SysprofCaptureCursor *cursor = task_data; + gchar *str = NULL; + + g_assert (G_IS_TASK (task)); + g_assert (cursor != NULL); + + sysprof_capture_cursor_foreach (cursor, cpu_info_cb, &str); + g_task_return_pointer (task, g_steal_pointer (&str), g_free); +} + +static void +sysprof_details_view_update_cpu_info (SysprofDetailsView *self, + SysprofCaptureReader *reader) +{ + g_autoptr(SysprofCaptureCursor) cursor = NULL; + g_autoptr(GTask) task = NULL; + + g_assert (SYSPROF_IS_DETAILS_VIEW (self)); + g_assert (reader != NULL); + + cursor = sysprof_capture_cursor_new (reader); + sysprof_capture_cursor_add_condition (cursor, + sysprof_capture_condition_new_where_file ("/proc/cpuinfo")); + + task = g_task_new (NULL, NULL, update_cpu_info_cb, g_object_ref (self)); + g_task_set_task_data (task, + g_steal_pointer (&cursor), + (GDestroyNotify) sysprof_capture_cursor_unref); + g_task_run_in_thread (task, sysprof_details_view_update_cpu_info_worker); +} + void sysprof_details_view_set_reader (SysprofDetailsView *self, SysprofCaptureReader *reader) @@ -137,6 +223,8 @@ sysprof_details_view_set_reader (SysprofDetailsView *self, g_return_if_fail (SYSPROF_IS_DETAILS_VIEW (self)); g_return_if_fail (reader != NULL); + sysprof_details_view_update_cpu_info (self, reader); + if (!(filename = sysprof_capture_reader_get_filename (reader))) filename = _("Memory Capture"); gtk_label_set_label (self->filename, filename); diff --git a/src/libsysprof-ui/ui/sysprof-details-view.ui b/src/libsysprof-ui/ui/sysprof-details-view.ui index f43976a6..ddd3d4cd 100644 --- a/src/libsysprof-ui/ui/sysprof-details-view.ui +++ b/src/libsysprof-ui/ui/sysprof-details-view.ui @@ -60,9 +60,9 @@ - 12 True - Samples Captured + False + CPU Model 1 + + + left + 7 + + True @@ -127,7 +142,7 @@ left - 7 + 8 @@ -167,11 +182,10 @@ - - 12 + True False - start + end 0 @@ -180,7 +194,8 @@ - + + 12 True False start @@ -192,7 +207,7 @@ - + True False start @@ -204,7 +219,7 @@ - + True False start @@ -215,6 +230,18 @@ 6 + + + True + False + start + 0 + + + center + 7 + + True @@ -225,7 +252,7 @@ center - 7 + 8 @@ -311,7 +338,7 @@ center - 8 + 9