From 25f504e6e7c78353367236fdc948c35e864e4f60 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Tue, 25 Jul 2023 17:28:58 -0700 Subject: [PATCH] sysprof: start on storage section --- src/sysprof/meson.build | 1 + src/sysprof/sysprof-storage-section.c | 168 ++++++++++++++++ src/sysprof/sysprof-storage-section.h | 33 ++++ src/sysprof/sysprof-storage-section.ui | 261 +++++++++++++++++++++++++ src/sysprof/sysprof-window.c | 2 + src/sysprof/sysprof-window.ui | 2 +- src/sysprof/sysprof.gresource.xml | 1 + 7 files changed, 467 insertions(+), 1 deletion(-) create mode 100644 src/sysprof/sysprof-storage-section.c create mode 100644 src/sysprof/sysprof-storage-section.h create mode 100644 src/sysprof/sysprof-storage-section.ui diff --git a/src/sysprof/meson.build b/src/sysprof/meson.build index 63cea579..f11c28cc 100644 --- a/src/sysprof/meson.build +++ b/src/sysprof/meson.build @@ -46,6 +46,7 @@ sysprof_sources = [ 'sysprof-sidebar.c', 'sysprof-single-model.c', 'sysprof-split-layer.c', + 'sysprof-storage-section.c', 'sysprof-symbol-label.c', 'sysprof-time-filter-model.c', 'sysprof-time-label.c', diff --git a/src/sysprof/sysprof-storage-section.c b/src/sysprof/sysprof-storage-section.c new file mode 100644 index 00000000..8867f0e6 --- /dev/null +++ b/src/sysprof/sysprof-storage-section.c @@ -0,0 +1,168 @@ +/* sysprof-storage-section.c + * + * Copyright 2023 Christian Hergert + * + * 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 + */ + +#include "config.h" + +#include "sysprof-chart.h" +#include "sysprof-duplex-layer.h" +#include "sysprof-storage-section.h" +#include "sysprof-line-layer.h" +#include "sysprof-pair.h" +#include "sysprof-time-series.h" +#include "sysprof-time-span-layer.h" +#include "sysprof-xy-series.h" + +struct _SysprofStorageSection +{ + SysprofSection parent_instance; + GListStore *pairs; +}; + +G_DEFINE_FINAL_TYPE (SysprofStorageSection, sysprof_storage_section, SYSPROF_TYPE_SECTION) + +enum { + PROP_0, + PROP_PAIRS, + N_PROPS +}; + +static GParamSpec *properties[N_PROPS]; + +static void +sysprof_storage_section_add_pair (SysprofStorageSection *self, + SysprofDocumentCounter *rx, + SysprofDocumentCounter *tx) +{ + g_autoptr(SysprofPair) pair = NULL; + + g_assert (SYSPROF_IS_STORAGE_SECTION (self)); + g_assert (SYSPROF_IS_DOCUMENT_COUNTER (rx)); + g_assert (SYSPROF_IS_DOCUMENT_COUNTER (tx)); + + pair = g_object_new (SYSPROF_TYPE_PAIR, + "first", rx, + "second", tx, + NULL); + g_list_store_append (self->pairs, pair); +} + +static void +sysprof_storage_section_session_set (SysprofSection *section, + SysprofSession *session) +{ + SysprofStorageSection *self = (SysprofStorageSection *)section; + g_autoptr(GListModel) counters = NULL; + SysprofDocument *document; + guint n_items; + + g_assert (SYSPROF_IS_STORAGE_SECTION (self)); + g_assert (!session || SYSPROF_IS_SESSION (session)); + + if (session == NULL) + { + g_list_store_remove_all (self->pairs); + return; + } + + document = sysprof_session_get_document (session); + counters = sysprof_document_list_counters (document); + n_items = g_list_model_get_n_items (counters); + + for (guint i = 0; i < n_items; i++) + { + g_autoptr(SysprofDocumentCounter) counter = g_list_model_get_item (counters, i); + const char *category = sysprof_document_counter_get_category (counter); + const char *name = sysprof_document_counter_get_name (counter); + + if (g_strcmp0 (category, "Disk") == 0 && g_str_has_prefix (name, "Total Reads (")) + { + g_autoptr(SysprofDocumentCounter) writes = NULL; + g_autofree char *alt_name = g_strdup_printf ("Total Writes %s", strchr (name, '(')); + + if ((writes = sysprof_document_find_counter (document, "Disk", alt_name))) + sysprof_storage_section_add_pair (self, counter, writes); + } + } +} + +static void +sysprof_storage_section_dispose (GObject *object) +{ + SysprofStorageSection *self = (SysprofStorageSection *)object; + + gtk_widget_dispose_template (GTK_WIDGET (self), SYSPROF_TYPE_STORAGE_SECTION); + + g_clear_object (&self->pairs); + + G_OBJECT_CLASS (sysprof_storage_section_parent_class)->dispose (object); +} + +static void +sysprof_storage_section_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + SysprofStorageSection *self = SYSPROF_STORAGE_SECTION (object); + + switch (prop_id) + { + case PROP_PAIRS: + g_value_set_object (value, self->pairs); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +sysprof_storage_section_class_init (SysprofStorageSectionClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + SysprofSectionClass *section_class = SYSPROF_SECTION_CLASS (klass); + + object_class->dispose = sysprof_storage_section_dispose; + object_class->get_property = sysprof_storage_section_get_property; + + section_class->session_set = sysprof_storage_section_session_set; + + properties [PROP_PAIRS] = + g_param_spec_object ("pairs", NULL, NULL, + G_TYPE_LIST_MODEL, + (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_properties (object_class, N_PROPS, properties); + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/sysprof-storage-section.ui"); + + g_type_ensure (SYSPROF_TYPE_CHART); + g_type_ensure (SYSPROF_TYPE_DUPLEX_LAYER); + g_type_ensure (SYSPROF_TYPE_PAIR); +} + +static void +sysprof_storage_section_init (SysprofStorageSection *self) +{ + self->pairs = g_list_store_new (SYSPROF_TYPE_PAIR); + + gtk_widget_init_template (GTK_WIDGET (self)); +} diff --git a/src/sysprof/sysprof-storage-section.h b/src/sysprof/sysprof-storage-section.h new file mode 100644 index 00000000..4691d714 --- /dev/null +++ b/src/sysprof/sysprof-storage-section.h @@ -0,0 +1,33 @@ +/* sysprof-storage-section.h + * + * Copyright 2023 Christian Hergert + * + * 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 "sysprof-section.h" + +G_BEGIN_DECLS + +#define SYSPROF_TYPE_STORAGE_SECTION (sysprof_storage_section_get_type()) + +G_DECLARE_FINAL_TYPE (SysprofStorageSection, sysprof_storage_section, SYSPROF, STORAGE_SECTION, SysprofSection) + +G_END_DECLS + + diff --git a/src/sysprof/sysprof-storage-section.ui b/src/sysprof/sysprof-storage-section.ui new file mode 100644 index 00000000..036e283c --- /dev/null +++ b/src/sysprof/sysprof-storage-section.ui @@ -0,0 +1,261 @@ + + + + + + + + diff --git a/src/sysprof/sysprof-window.c b/src/sysprof/sysprof-window.c index 7f681b96..59479887 100644 --- a/src/sysprof/sysprof-window.c +++ b/src/sysprof/sysprof-window.c @@ -34,6 +34,7 @@ #include "sysprof-processes-section.h" #include "sysprof-samples-section.h" #include "sysprof-sidebar.h" +#include "sysprof-storage-section.h" #include "sysprof-window.h" struct _SysprofWindow @@ -420,6 +421,7 @@ sysprof_window_class_init (SysprofWindowClass *klass) g_type_ensure (SYSPROF_TYPE_NETWORK_SECTION); g_type_ensure (SYSPROF_TYPE_PROCESSES_SECTION); g_type_ensure (SYSPROF_TYPE_SAMPLES_SECTION); + g_type_ensure (SYSPROF_TYPE_STORAGE_SECTION); g_type_ensure (SYSPROF_TYPE_SESSION); g_type_ensure (SYSPROF_TYPE_SIDEBAR); } diff --git a/src/sysprof/sysprof-window.ui b/src/sysprof/sysprof-window.ui index d6e68a05..85085bb5 100644 --- a/src/sysprof/sysprof-window.ui +++ b/src/sysprof/sysprof-window.ui @@ -227,7 +227,7 @@ - + Storage counters storage-symbolic diff --git a/src/sysprof/sysprof.gresource.xml b/src/sysprof/sysprof.gresource.xml index 1151bc8f..40b84d1f 100644 --- a/src/sysprof/sysprof.gresource.xml +++ b/src/sysprof/sysprof.gresource.xml @@ -35,6 +35,7 @@ sysprof-recording-pad.ui sysprof-samples-section.ui sysprof-sidebar.ui + sysprof-storage-section.ui sysprof-time-scrubber.ui sysprof-traceables-utility.ui sysprof-weighted-callgraph-view.ui