From 8cc7bc8bcbb11ac43305f82d24eb835d1ebffae9 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Tue, 25 Jul 2023 17:03:51 -0700 Subject: [PATCH] sysprof: start on network section --- src/sysprof/meson.build | 1 + src/sysprof/sysprof-network-section.c | 170 +++++++++++++++++ src/sysprof/sysprof-network-section.h | 32 ++++ src/sysprof/sysprof-network-section.ui | 254 +++++++++++++++++++++++++ src/sysprof/sysprof-window.c | 2 + src/sysprof/sysprof-window.ui | 2 +- src/sysprof/sysprof.gresource.xml | 1 + 7 files changed, 461 insertions(+), 1 deletion(-) create mode 100644 src/sysprof/sysprof-network-section.c create mode 100644 src/sysprof/sysprof-network-section.h create mode 100644 src/sysprof/sysprof-network-section.ui diff --git a/src/sysprof/meson.build b/src/sysprof/meson.build index eb451a6b..63cea579 100644 --- a/src/sysprof/meson.build +++ b/src/sysprof/meson.build @@ -28,6 +28,7 @@ sysprof_sources = [ 'sysprof-memory-callgraph-view.c', 'sysprof-memory-section.c', 'sysprof-metadata-section.c', + 'sysprof-network-section.c', 'sysprof-normalized-series-item.c', 'sysprof-normalized-series.c', 'sysprof-pair.c', diff --git a/src/sysprof/sysprof-network-section.c b/src/sysprof/sysprof-network-section.c new file mode 100644 index 00000000..2ee044c7 --- /dev/null +++ b/src/sysprof/sysprof-network-section.c @@ -0,0 +1,170 @@ +/* sysprof-network-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-network-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 _SysprofNetworkSection +{ + SysprofSection parent_instance; + GListStore *pairs; +}; + +G_DEFINE_FINAL_TYPE (SysprofNetworkSection, sysprof_network_section, SYSPROF_TYPE_SECTION) + +enum { + PROP_0, + PROP_PAIRS, + N_PROPS +}; + +static GParamSpec *properties[N_PROPS]; + +static void +sysprof_network_section_add_pair (SysprofNetworkSection *self, + SysprofDocumentCounter *rx, + SysprofDocumentCounter *tx) +{ + g_autoptr(SysprofPair) pair = NULL; + + g_assert (SYSPROF_IS_NETWORK_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_network_section_session_set (SysprofSection *section, + SysprofSession *session) +{ + SysprofNetworkSection *self = (SysprofNetworkSection *)section; + g_autoptr(GListModel) counters = NULL; + SysprofDocument *document; + guint n_items; + + g_assert (SYSPROF_IS_NETWORK_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, "Network") == 0 && g_str_has_prefix (name, "RX ")) + { + g_autoptr(SysprofDocumentCounter) tx = NULL; + g_autofree char *alt_name = g_strdup (name); + + alt_name[0] = 'T'; + + if ((tx = sysprof_document_find_counter (document, "Network", alt_name))) + sysprof_network_section_add_pair (self, counter, tx); + } + } +} + +static void +sysprof_network_section_dispose (GObject *object) +{ + SysprofNetworkSection *self = (SysprofNetworkSection *)object; + + gtk_widget_dispose_template (GTK_WIDGET (self), SYSPROF_TYPE_NETWORK_SECTION); + + g_clear_object (&self->pairs); + + G_OBJECT_CLASS (sysprof_network_section_parent_class)->dispose (object); +} + +static void +sysprof_network_section_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + SysprofNetworkSection *self = SYSPROF_NETWORK_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_network_section_class_init (SysprofNetworkSectionClass *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_network_section_dispose; + object_class->get_property = sysprof_network_section_get_property; + + section_class->session_set = sysprof_network_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-network-section.ui"); + + g_type_ensure (SYSPROF_TYPE_CHART); + g_type_ensure (SYSPROF_TYPE_DUPLEX_LAYER); + g_type_ensure (SYSPROF_TYPE_PAIR); +} + +static void +sysprof_network_section_init (SysprofNetworkSection *self) +{ + self->pairs = g_list_store_new (SYSPROF_TYPE_PAIR); + + gtk_widget_init_template (GTK_WIDGET (self)); +} diff --git a/src/sysprof/sysprof-network-section.h b/src/sysprof/sysprof-network-section.h new file mode 100644 index 00000000..0dd09223 --- /dev/null +++ b/src/sysprof/sysprof-network-section.h @@ -0,0 +1,32 @@ +/* sysprof-network-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_NETWORK_SECTION (sysprof_network_section_get_type()) + +G_DECLARE_FINAL_TYPE (SysprofNetworkSection, sysprof_network_section, SYSPROF, NETWORK_SECTION, SysprofSection) + +G_END_DECLS + diff --git a/src/sysprof/sysprof-network-section.ui b/src/sysprof/sysprof-network-section.ui new file mode 100644 index 00000000..08c5ff60 --- /dev/null +++ b/src/sysprof/sysprof-network-section.ui @@ -0,0 +1,254 @@ + + + + + + + diff --git a/src/sysprof/sysprof-window.c b/src/sysprof/sysprof-window.c index e58613e2..7f681b96 100644 --- a/src/sysprof/sysprof-window.c +++ b/src/sysprof/sysprof-window.c @@ -30,6 +30,7 @@ #include "sysprof-marks-section.h" #include "sysprof-memory-section.h" #include "sysprof-metadata-section.h" +#include "sysprof-network-section.h" #include "sysprof-processes-section.h" #include "sysprof-samples-section.h" #include "sysprof-sidebar.h" @@ -416,6 +417,7 @@ sysprof_window_class_init (SysprofWindowClass *klass) g_type_ensure (SYSPROF_TYPE_MARKS_SECTION); g_type_ensure (SYSPROF_TYPE_MEMORY_SECTION); g_type_ensure (SYSPROF_TYPE_METADATA_SECTION); + 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_SESSION); diff --git a/src/sysprof/sysprof-window.ui b/src/sysprof/sysprof-window.ui index f34b1a79..d6e68a05 100644 --- a/src/sysprof/sysprof-window.ui +++ b/src/sysprof/sysprof-window.ui @@ -217,7 +217,7 @@ - + Network counters network-transmit-receive-symbolic diff --git a/src/sysprof/sysprof.gresource.xml b/src/sysprof/sysprof.gresource.xml index c7ba1cdd..1151bc8f 100644 --- a/src/sysprof/sysprof.gresource.xml +++ b/src/sysprof/sysprof.gresource.xml @@ -29,6 +29,7 @@ sysprof-memory-callgraph-view.ui sysprof-memory-section.ui sysprof-metadata-section.ui + sysprof-network-section.ui sysprof-process-dialog.ui sysprof-processes-section.ui sysprof-recording-pad.ui