diff --git a/src/libsysprof-ui/meson.build b/src/libsysprof-ui/meson.build index 1f6720a9..0017eedb 100644 --- a/src/libsysprof-ui/meson.build +++ b/src/libsysprof-ui/meson.build @@ -43,6 +43,7 @@ libsysprof_ui_private_sources = [ 'sysprof-log-model.c', 'sysprof-logs-aid.c', 'sysprof-logs-page.c', + 'sysprof-mark-detail.c', 'sysprof-marks-aid.c', 'sysprof-marks-model.c', 'sysprof-marks-page.c', diff --git a/src/libsysprof-ui/sysprof-details-page.c b/src/libsysprof-ui/sysprof-details-page.c index f3227a26..0bcffa02 100644 --- a/src/libsysprof-ui/sysprof-details-page.c +++ b/src/libsysprof-ui/sysprof-details-page.c @@ -25,28 +25,30 @@ #include #include +#include "sysprof-mark-detail.h" #include "sysprof-details-page.h" #include "sysprof-ui-private.h" struct _SysprofDetailsPage { - GtkWidget parent_instance; + GtkWidget parent_instance ; /* Template Objects */ - GtkListStore *marks_store; - GtkTreeView *marks_view; - GtkLabel *counters; - GtkLabel *duration; - GtkLabel *filename; - GtkLabel *allocations; - GtkLabel *forks; - GtkLabel *marks; - GtkLabel *processes; - GtkLabel *samples; - GtkLabel *start_time; - GtkLabel *cpu_label; - guint next_row; + GListStore *marks_store; + GtkSortListModel *mark_sort_model; + GtkLabel *counters; + GtkLabel *duration; + GtkLabel *filename; + GtkLabel *allocations; + GtkLabel *forks; + GtkLabel *marks; + GtkLabel *processes; + GtkLabel *samples; + GtkLabel *start_time; + GtkLabel *cpu_label; + + guint next_row; }; G_DEFINE_TYPE (SysprofDetailsPage, sysprof_details_page, GTK_TYPE_WIDGET) @@ -74,6 +76,13 @@ _g_date_time_new_from_iso8601 (const gchar *str, } #endif +char * +format_time (GObject *unused, + gint64 time) +{ + return time ? _sysprof_format_duration (time) : g_strdup("—"); +} + static void sysprof_details_page_dispose (GObject *object) { @@ -94,6 +103,7 @@ sysprof_details_page_class_init (SysprofDetailsPageClass *klass) object_class->dispose = sysprof_details_page_dispose; + g_type_ensure (SYSPROF_TYPE_MARK_DETAIL); gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/ui/sysprof-details-page.ui"); gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, allocations); @@ -104,10 +114,11 @@ sysprof_details_page_class_init (SysprofDetailsPageClass *klass) gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, forks); gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, marks); gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, marks_store); - gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, marks_view); + gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, mark_sort_model); gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, processes); gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, samples); gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, start_time); + gtk_widget_class_bind_template_callback (widget_class, format_time); } static void @@ -115,9 +126,6 @@ sysprof_details_page_init (SysprofDetailsPage *self) { gtk_widget_init_template (GTK_WIDGET (self)); - gtk_tree_selection_set_mode (gtk_tree_view_get_selection (self->marks_view), - GTK_SELECTION_MULTIPLE); - self->next_row = 8; } @@ -273,18 +281,23 @@ sysprof_details_page_add_mark (SysprofDetailsPage *self, gint64 avg, gint64 hits) { - GtkTreeIter iter; + SysprofMarkDetail *detail; g_return_if_fail (SYSPROF_IS_DETAILS_PAGE (self)); - gtk_list_store_append (self->marks_store, &iter); + detail = sysprof_mark_detail_new (mark, min, max, avg, hits); + + g_list_store_append (self->marks_store, detail); + /*gtk_list_store_append (self->marks_store, &iter); gtk_list_store_set (self->marks_store, &iter, 0, mark, 1, min ? _sysprof_format_duration (min) : "—", 2, max ? _sysprof_format_duration (max) : "—", 3, avg ? _sysprof_format_duration (avg) : "—", 4, hits, - -1); + 5, detail, + -1);*/ + g_object_unref (detail); } void diff --git a/src/libsysprof-ui/sysprof-details-page.ui b/src/libsysprof-ui/sysprof-details-page.ui index 4869b0d4..e9de42de 100644 --- a/src/libsysprof-ui/sysprof-details-page.ui +++ b/src/libsysprof-ui/sysprof-details-page.ui @@ -163,79 +163,183 @@ Statistics - + + 500 + 100 + + + mark_sort_model + + + - - marks_store - 500 - 100 - both - - - true - Mark - - - 0.0 - - - 0 - - + + Mark + true + + + + + - - - - Hits - - - 0.0 - - - 4 - - + + + + + + + + ]]> - - - - Min - - - 0.0 - - - 1 - - + + + + + + Hits + + + + + - - - - Max - - - 0.0 - - - 2 - - + + + + + + + + ]]> - - - - Avg - - - 0.0 - - - 3 - - + + + + + + Min + + + + + - + + + + + + + + ]]> + + + + + + + Max + + + + + + + + + + + + + + ]]> + + + + + + + Avg + + + + + + + + + + + + + + ]]> + + @@ -245,18 +349,13 @@ - - - - - - - - - - - - - + + marks_store + true + + marks_view + + + diff --git a/src/libsysprof-ui/sysprof-mark-detail.c b/src/libsysprof-ui/sysprof-mark-detail.c new file mode 100644 index 00000000..d0899149 --- /dev/null +++ b/src/libsysprof-ui/sysprof-mark-detail.c @@ -0,0 +1,208 @@ +/* sysprof-mark-detail.c + * + * Copyright 2022 Corentin Noël + * + * 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#define G_LOG_DOMAIN "sysprof-mark-detail" + +#include "config.h" + +#include + +#include "sysprof-mark-detail.h" + +struct _SysprofMarkDetail +{ + GObject parent_instance; + + gchar *label; + gint64 min; + gint64 max; + gint64 average; + gint64 hits; +}; + +G_DEFINE_TYPE (SysprofMarkDetail, sysprof_mark_detail, G_TYPE_OBJECT) + +enum { + PROP_0, + PROP_LABEL, + PROP_MIN, + PROP_MAX, + PROP_AVERAGE, + PROP_HITS, + N_PROPS +}; + +static GParamSpec *properties [N_PROPS]; + +/** + * sysprof_mark_detail_new: + * + * Create a new #SysprofMarkDetail. + * + * Returns: (transfer full): a newly created #SysprofMarkDetail + */ +SysprofMarkDetail * +sysprof_mark_detail_new (const gchar *mark, + gint64 min, + gint64 max, + gint64 avg, + gint64 hits) +{ + return g_object_new (SYSPROF_TYPE_MARK_DETAIL, + "label", mark, + "min", min, + "max", max, + "average", avg, + "hits", hits, + NULL); +} + +static void +sysprof_mark_detail_finalize (GObject *object) +{ + SysprofMarkDetail *self = (SysprofMarkDetail *)object; + + g_clear_pointer (&self->label, g_free); + + G_OBJECT_CLASS (sysprof_mark_detail_parent_class)->finalize (object); +} + +static void +sysprof_mark_detail_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + SysprofMarkDetail *self = SYSPROF_MARK_DETAIL(object); + + switch (prop_id) + { + case PROP_LABEL: + g_value_set_string (value, self->label); + break; + + case PROP_MIN: + g_value_set_int64 (value, self->min); + break; + + case PROP_MAX: + g_value_set_int64 (value, self->max); + break; + + case PROP_AVERAGE: + g_value_set_int64 (value, self->average); + break; + + case PROP_HITS: + g_value_set_int64 (value, self->hits); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +sysprof_mark_detail_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + SysprofMarkDetail *self = SYSPROF_MARK_DETAIL(object); + + switch (prop_id) + { + case PROP_LABEL: + g_assert(self->label == NULL); + self->label = g_value_dup_string (value); + break; + + case PROP_MIN: + self->min = g_value_get_int64 (value); + break; + + case PROP_MAX: + self->max = g_value_get_int64 (value); + break; + + case PROP_AVERAGE: + self->average = g_value_get_int64 (value); + break; + + case PROP_HITS: + self->hits = g_value_get_int64 (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +sysprof_mark_detail_class_init (SysprofMarkDetailClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = sysprof_mark_detail_finalize; + object_class->get_property = sysprof_mark_detail_get_property; + object_class->set_property = sysprof_mark_detail_set_property; + + properties [PROP_LABEL] = + g_param_spec_string ("label", + "Label", + "The label of the mark", + NULL, + (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); + + properties [PROP_MIN] = + g_param_spec_int64 ("min", + "Min", + "The minimal timespan", + 0, G_MAXINT64, 0, + (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); + + properties [PROP_MAX] = + g_param_spec_int64 ("max", + "max", + "The maximal timespan", + 0, G_MAXINT64, 0, + (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); + + properties [PROP_AVERAGE] = + g_param_spec_int64 ("average", + "Average", + "The average timespan", + 0, G_MAXINT64, 0, + (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); + + properties [PROP_HITS] = + g_param_spec_int64 ("hits", + "Hits", + "The number of hits", + 0, G_MAXINT64, 0, + (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_properties (object_class, N_PROPS, properties); +} + +static void +sysprof_mark_detail_init (SysprofMarkDetail *self) +{ +} diff --git a/src/libsysprof-ui/sysprof-mark-detail.h b/src/libsysprof-ui/sysprof-mark-detail.h new file mode 100644 index 00000000..35b292e7 --- /dev/null +++ b/src/libsysprof-ui/sysprof-mark-detail.h @@ -0,0 +1,37 @@ +/* sysprof-mark-detail.h + * + * Copyright 2022 Corentin Noël + * + * 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +#define SYSPROF_TYPE_MARK_DETAIL (sysprof_mark_detail_get_type()) + +G_DECLARE_FINAL_TYPE (SysprofMarkDetail, sysprof_mark_detail, SYSPROF, MARK_DETAIL, GObject) + +SysprofMarkDetail *sysprof_mark_detail_new (const gchar *mark, + gint64 min, + gint64 max, + gint64 avg, + gint64 hits); + +G_END_DECLS