From 36d2ddc58cd0f467d6d7682689cc10947a8a1973 Mon Sep 17 00:00:00 2001
From: yangchen <yangchen145@huawei.com>
Date: Tue, 6 Feb 2024 11:29:26 +0800
Subject: [PATCH] add observable method of data aggregation

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

diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h
index d465efa..1ca210b 100644
--- a/src/common/gazelle_dfx_msg.h
+++ b/src/common/gazelle_dfx_msg.h
@@ -73,6 +73,8 @@ struct gazelle_stack_stat {
     uint64_t tx;
     uint64_t tx_prepare_fail;
     uint64_t accept_fail;
+    uint64_t sock_rx_drop;
+    uint64_t sock_tx_merge;
 };
 
 struct gazelle_wakeup_stat {
diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c
index 63044c2..4523907 100644
--- a/src/lstack/core/lstack_lwip.c
+++ b/src/lstack/core/lstack_lwip.c
@@ -541,6 +541,7 @@ static ssize_t do_lwip_fill_sendring(struct lwip_sock *sock, const void *buf, si
 
     /* merge data into last pbuf */
     if (!NETCONN_IS_UDP(sock) && sock->remain_len) {
+        sock->stack->stats.sock_tx_merge++;
         send_len = merge_data_lastpbuf(sock, (char *)buf, len);
         if (send_len >= len) {
             send_len = len;
@@ -1039,6 +1040,7 @@ ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags
 
             /* in udp, if pbuf remaining len less than copy_len, discard these packets */
             if (recvd > 0 && NETCONN_IS_UDP(sock)) {
+                sock->stack->stats.sock_rx_drop++;
                 break;
             }
         }
diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c
index 4b246a1..9f12096 100644
--- a/src/ltran/ltran_dfx.c
+++ b/src/ltran/ltran_dfx.c
@@ -648,7 +648,9 @@ 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);
+    printf("accpet_fail: %-16"PRIu64" ", lstack_stat->data.pkts.stack_stat.accept_fail);
+    printf("sock_rx_drop: %-15"PRIu64" ", lstack_stat->data.pkts.stack_stat.sock_rx_drop);
+    printf("sock_tx_merge: %-16"PRIu64" \n", lstack_stat->data.pkts.stack_stat.sock_tx_merge);
 }
 
 static void gazelle_print_lstack_stat_detail(struct gazelle_stack_dfx_data *lstack_stat,
-- 
2.27.0

