From 53457e3ab329eb944579ffe55ddc4435e0bca0a1 Mon Sep 17 00:00:00 2001
From: hantwofish <hankangkang5@huawei.com>
Date: Wed, 10 Jan 2024 09:12:34 +0800
Subject: [PATCH] add socket accept fail cnt

---
 src/common/gazelle_dfx_msg.h            | 1 +
 src/lstack/core/lstack_protocol_stack.c | 2 ++
 src/ltran/ltran_dfx.c                   | 1 +
 3 files changed, 4 insertions(+)

diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h
index 478c440..1d3249d 100644
--- a/src/common/gazelle_dfx_msg.h
+++ b/src/common/gazelle_dfx_msg.h
@@ -72,6 +72,7 @@ struct gazelle_stack_stat {
     uint64_t tx_drop;
     uint64_t tx;
     uint64_t tx_prepare_fail;
+    uint64_t accept_fail;
 };
 
 struct gazelle_wakeup_stat {
diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c
index f849bcd..0d845dd 100644
--- a/src/lstack/core/lstack_protocol_stack.c
+++ b/src/lstack/core/lstack_protocol_stack.c
@@ -792,9 +792,11 @@ void stack_accept(struct rpc_msg *msg)
 {
     int32_t fd = msg->args[MSG_ARG_0].i;
     msg->result = -1;
+    struct protocol_stack *stack = get_protocol_stack();
 
     int32_t accept_fd = lwip_accept4(fd, msg->args[MSG_ARG_1].p, msg->args[MSG_ARG_2].p, msg->args[MSG_ARG_3].i);
     if (accept_fd < 0) {
+        stack->stats.accept_fail++;
         LSTACK_LOG(ERR, LSTACK, "fd %d ret %d\n", fd, accept_fd);
         return;
     }
diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c
index 5e22e20..461912f 100644
--- a/src/ltran/ltran_dfx.c
+++ b/src/ltran/ltran_dfx.c
@@ -646,6 +646,7 @@ static void show_lstack_stats(struct gazelle_stack_dfx_data *lstack_stat)
     printf("send_pkts_fail: %-13"PRIu64" ", lstack_stat->data.pkts.stack_stat.send_pkts_fail);
     printf("mbuf_pool_freecnt: %-10"PRIu32" ", lstack_stat->data.pkts.mbufpool_avail_cnt);
     printf("rpc_pool_freecnt: %-12"PRIu32" \n", lstack_stat->data.pkts.rpcpool_avail_cnt);
+    printf("accpet_fail: %-12"PRIu64" \n", lstack_stat->data.pkts.stack_stat.accept_fail);
 }
 
 static void gazelle_print_lstack_stat_detail(struct gazelle_stack_dfx_data *lstack_stat,
-- 
2.33.0

