summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2023-06-21 20:02:25 -0700
committerDave Barach <vpp@barachs.net>2023-06-22 20:14:49 +0000
commit6052f4b9d8b7f7668649e9a0d3a8a09506465ed8 (patch)
tree5b0c6ce1e09bab177b706d80ba3640dabd258b5a /src
parent1c95e12b0dd2b4902a289328e8e54fde6eed0623 (diff)
tcp: add simple stats collector
Type: feature Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: I435ff10fa3af15b0bed83607aca508a1c087a159
Diffstat (limited to 'src')
-rw-r--r--src/vnet/tcp/tcp.c44
-rw-r--r--src/vnet/tcp/tcp.h7
2 files changed, 51 insertions, 0 deletions
diff --git a/src/vnet/tcp/tcp.c b/src/vnet/tcp/tcp.c
index 977eda3bc65..2f90d9add81 100644
--- a/src/vnet/tcp/tcp.c
+++ b/src/vnet/tcp/tcp.c
@@ -25,6 +25,8 @@
#include <vnet/dpo/load_balance.h>
#include <math.h>
+#include <vlib/stats/stats.h>
+
tcp_main_t tcp_main;
typedef struct
@@ -1458,6 +1460,46 @@ tcp_initialize_iss_seed (tcp_main_t * tm)
tm->iss_seed.second = random_u64 (&time_now);
}
+static void
+tcp_stats_collector_fn (vlib_stats_collector_data_t *d)
+{
+ tcp_main_t *tm = vnet_get_tcp_main ();
+ counter_t **counters = d->entry->data;
+ counter_t *cb = counters[0];
+ tcp_wrk_stats_t acc = {};
+ tcp_worker_ctx_t *wrk;
+
+ vec_foreach (wrk, tm->wrk_ctx)
+ {
+#define _(name, type, str) acc.name += wrk->stats.name;
+ foreach_tcp_wrk_stat
+#undef _
+ }
+
+#define _(name, type, str) cb[TCP_STAT_##name] = acc.name;
+ foreach_tcp_wrk_stat
+#undef _
+}
+
+static void
+tcp_counters_init (void)
+{
+ vlib_stats_collector_reg_t r = {};
+ u32 idx;
+
+ r.entry_index = idx = vlib_stats_add_counter_vector ("/sys/tcp");
+ r.collect_fn = tcp_stats_collector_fn;
+ vlib_stats_validate (idx, 0, TCP_STAT_no_buffer);
+
+#define _(name, type, str) \
+ vlib_stats_add_symlink (idx, TCP_STAT_##name, "/sys/tcp/%s", \
+ CLIB_STRING_MACRO (name));
+ foreach_tcp_wrk_stat
+#undef _
+
+ vlib_stats_register_collector_fn (&r);
+}
+
static clib_error_t *
tcp_main_enable (vlib_main_t * vm)
{
@@ -1534,6 +1576,8 @@ tcp_main_enable (vlib_main_t * vm)
tm->bytes_per_buffer = vlib_buffer_get_default_data_size (vm);
tm->cc_last_type = TCP_CC_LAST;
+ tcp_counters_init ();
+
return error;
}
diff --git a/src/vnet/tcp/tcp.h b/src/vnet/tcp/tcp.h
index 75ae9275165..962324e2eaf 100644
--- a/src/vnet/tcp/tcp.h
+++ b/src/vnet/tcp/tcp.h
@@ -66,6 +66,13 @@ typedef struct tcp_wrk_stats_
#undef _
} tcp_wrk_stats_t;
+typedef enum
+{
+#define _(name, type, str) TCP_STAT_##name,
+ foreach_tcp_wrk_stat
+#undef _
+} tcp_wrk_stats_e;
+
typedef struct tcp_free_req_
{
clib_time_type_t free_time;