[sysprof] netdev: add combined counter for all devices (cooked) together
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sysprof] netdev: add combined counter for all devices (cooked) together
- Date: Thu, 27 Jun 2019 02:24:46 +0000 (UTC)
commit 22ce2875d118cf1e218d5bb05d149851fe0b4b8d
Author: Christian Hergert <chergert redhat com>
Date: Wed Jun 26 19:24:38 2019 -0700
netdev: add combined counter for all devices (cooked) together
src/libsysprof-ui/sysprof-netdev-aid.c | 13 ++++++--
src/libsysprof/sysprof-netdev-source.c | 55 +++++++++++++++++++++++++++-------
2 files changed, 55 insertions(+), 13 deletions(-)
---
diff --git a/src/libsysprof-ui/sysprof-netdev-aid.c b/src/libsysprof-ui/sysprof-netdev-aid.c
index fe19895..f4a75a7 100644
--- a/src/libsysprof-ui/sysprof-netdev-aid.c
+++ b/src/libsysprof-ui/sysprof-netdev-aid.c
@@ -212,6 +212,7 @@ sysprof_netdev_aid_present_finish (SysprofAid *aid,
if (g_str_has_prefix (ctr->name, "RX Bytes"))
{
g_autofree gchar *title = NULL;
+ gboolean is_combined;
GtkWidget *row;
GdkRGBA rgba;
guint other_id;
@@ -219,16 +220,22 @@ sysprof_netdev_aid_present_finish (SysprofAid *aid,
if (!(other_id = find_other_id (counters, ctr->name)))
continue;
- title = g_strdup_printf ("Network Bytes%s", ctr->name + strlen ("RX Bytes"));
+ is_combined = g_str_equal (ctr->description, "Combined");
+
+ if (is_combined)
+ title = g_strdup ("Network Bytes (All)");
+ else
+ title = g_strdup_printf ("Network Bytes%s", ctr->name + strlen ("RX Bytes"));
+
row = g_object_new (SYSPROF_TYPE_DUPLEX_VISUALIZER,
"title", title,
"height-request", 35,
- "visible", TRUE,
+ "visible", is_combined,
NULL);
sysprof_color_cycle_next (cycle, &rgba);
sysprof_duplex_visualizer_set_counters (SYSPROF_DUPLEX_VISUALIZER (row), ctr->id, other_id);
sysprof_duplex_visualizer_set_colors (SYSPROF_DUPLEX_VISUALIZER (row), &rgba, &rgba);
- sysprof_visualizer_group_insert (group, SYSPROF_VISUALIZER (row), -1, TRUE);
+ sysprof_visualizer_group_insert (group, SYSPROF_VISUALIZER (row), is_combined ? 0 : -1,
!is_combined);
}
}
diff --git a/src/libsysprof/sysprof-netdev-source.c b/src/libsysprof/sysprof-netdev-source.c
index 68dcf7b..364fbd7 100644
--- a/src/libsysprof/sysprof-netdev-source.c
+++ b/src/libsysprof/sysprof-netdev-source.c
@@ -41,6 +41,10 @@ struct _SysprofNetdevSource
SysprofCaptureWriter *writer;
GArray *netdevs;
+ /* Combined (all devices) rx/tx counters */
+ guint combined_rx_id;
+ guint combined_tx_id;
+
/* FD for /proc/net/dev contents */
gint netdev_fd;
@@ -150,8 +154,8 @@ static void
sysprof_netdev_source_prepare (SysprofSource *source)
{
SysprofNetdevSource *self = (SysprofNetdevSource *)source;
- g_autoptr(GArray) counters = NULL;
g_autoptr(GError) error = NULL;
+ SysprofCaptureCounter ctr[2] = {0};
g_assert (SYSPROF_IS_NETDEV_SOURCE (self));
@@ -168,7 +172,28 @@ sysprof_netdev_source_prepare (SysprofSource *source)
return;
}
- counters = g_array_new (FALSE, FALSE, sizeof (SysprofCaptureCounter));
+ self->combined_rx_id = sysprof_capture_writer_request_counter (self->writer, 1);
+ self->combined_tx_id = sysprof_capture_writer_request_counter (self->writer, 1);
+
+ g_strlcpy (ctr[0].category, "Network", sizeof ctr[0].category);
+ g_strlcpy (ctr[0].name, "RX Bytes", sizeof ctr[0].name);
+ g_strlcpy (ctr[0].description, "Combined", sizeof ctr[0].description);
+ ctr[0].id = self->combined_rx_id;
+ ctr[0].type = SYSPROF_CAPTURE_COUNTER_INT64;
+ ctr[0].value.v64 = 0;
+
+ g_strlcpy (ctr[1].category, "Network", sizeof ctr[1].category);
+ g_strlcpy (ctr[1].name, "TX Bytes", sizeof ctr[1].name);
+ g_strlcpy (ctr[1].description, "Combined", sizeof ctr[1].description);
+ ctr[1].id = self->combined_tx_id;
+ ctr[1].type = SYSPROF_CAPTURE_COUNTER_INT64;
+ ctr[1].value.v64 = 0;
+
+ sysprof_capture_writer_define_counters (self->writer,
+ SYSPROF_CAPTURE_CURRENT_TIME,
+ -1,
+ -1,
+ ctr, G_N_ELEMENTS (ctr));
sysprof_source_emit_ready (source);
}
@@ -181,6 +206,8 @@ sysprof_netdev_source_poll_cb (gpointer data)
g_autoptr(GArray) counters = NULL;
g_autoptr(GArray) values = NULL;
gchar buf[4096*4];
+ gint64 combined_rx = 0;
+ gint64 combined_tx = 0;
gssize len;
gsize line_len;
gchar *line;
@@ -277,6 +304,9 @@ Inter-| Receive | Transmit
&nd->tx_carrier,
&nd->tx_compressed);
+ combined_rx += nd->rx_bytes;
+ combined_tx += nd->tx_bytes;
+
g_array_append_val (counters, nd->rx_bytes_id);
g_array_append_val (values, nd->rx_bytes);
@@ -284,14 +314,19 @@ Inter-| Receive | Transmit
g_array_append_val (values, nd->tx_bytes);
}
- if (counters->len)
- sysprof_capture_writer_set_counters (self->writer,
- SYSPROF_CAPTURE_CURRENT_TIME,
- -1,
- -1,
- (const guint *)(gpointer)counters->data,
- (const SysprofCaptureCounterValue *)(gpointer)values->data,
- counters->len);
+ g_array_append_val (counters, self->combined_rx_id);
+ g_array_append_val (values, combined_rx);
+
+ g_array_append_val (counters, self->combined_tx_id);
+ g_array_append_val (values, combined_tx);
+
+ sysprof_capture_writer_set_counters (self->writer,
+ SYSPROF_CAPTURE_CURRENT_TIME,
+ -1,
+ -1,
+ (const guint *)(gpointer)counters->data,
+ (const SysprofCaptureCounterValue *)(gpointer)values->data,
+ counters->len);
return G_SOURCE_CONTINUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]