From 1a43d75144d7fc4f052758aceadf47535ef3262e Mon Sep 17 00:00:00 2001
From: yinbin <yinbin8@huawei.com>
Date: Mon, 20 Nov 2023 21:15:51 +0800
Subject: [PATCH] gazellectl: fix gazellectl lstack show 1 -r error

---
 src/common/gazelle_dfx_msg.h        |  28 +++--
 src/lstack/core/lstack_stack_stat.c |  15 +--
 src/ltran/ltran_dfx.c               | 188 ++++++++++++++++------------
 src/ltran/ltran_monitor.c           |   5 +-
 4 files changed, 131 insertions(+), 105 deletions(-)

diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h
index bfc4992..ac6ea5e 100644
--- a/src/common/gazelle_dfx_msg.h
+++ b/src/common/gazelle_dfx_msg.h
@@ -25,6 +25,7 @@
 enum GAZELLE_STAT_MODE {
     GAZELLE_STAT_LTRAN_SHOW = 0,
     GAZELLE_STAT_LTRAN_SHOW_RATE,
+    GAZELLE_STAT_LTRAN_SHOW_LB_RATE,
     GAZELLE_STAT_LTRAN_SHOW_INSTANCE,
     GAZELLE_STAT_LTRAN_SHOW_BURST,
     GAZELLE_STAT_LTRAN_SHOW_LATENCY,
@@ -78,6 +79,18 @@ struct gazelle_wakeup_stat {
     uint64_t kernel_events;
 };
 
+struct gazelle_stack_aggregate_stats {
+    /* 0: RX, 1: TX, 2: APP_TX */
+    uint32_t size_1_64[3];
+    uint32_t size_65_512[3];
+    uint32_t size_513_1460[3];
+    uint32_t size_1461_8192[3];
+    uint32_t size_8193_max[3];
+
+    uint64_t rx_bytes;
+    uint64_t tx_bytes;
+};
+
 struct gazelle_stat_pkts {
     uint16_t conn_num;
     uint32_t mempool_freecnt;
@@ -86,6 +99,7 @@ struct gazelle_stat_pkts {
     uint64_t call_alloc_fail;
     struct gazelle_stack_stat stack_stat;
     struct gazelle_wakeup_stat wakeup_stat;
+    struct gazelle_stack_aggregate_stats aggregate_stats;
 };
 
 /* same as define in lwip/stats.h - struct stats_mib2 */
@@ -218,23 +232,12 @@ struct nic_eth_xstats {
     uint16_t port_id;
 };
 
-struct gazelle_stack_aggregate_stats {
-    /* 0: RX, 1: TX, 2: APP_TX */
-    uint32_t size_1_64[3];
-    uint32_t size_65_512[3];
-    uint32_t size_513_1460[3];
-    uint32_t size_1461_8192[3];
-    uint32_t size_8193_max[3];
-
-    uint64_t rx_bytes;
-    uint64_t tx_bytes;
-};
-
 struct gazelle_stack_dfx_data {
     /* indicates whether the current message is the last */
     uint32_t eof;
     uint32_t tid;
     int32_t loglevel;
+    uint32_t stack_id;
     struct gazelle_stat_low_power_info low_power_info;
 
     union lstack_msg {
@@ -243,7 +246,6 @@ struct gazelle_stack_dfx_data {
         struct gazelle_stat_lstack_conn conn;
         struct gazelle_stat_lstack_snmp snmp;
         struct nic_eth_xstats nic_xstats;
-        struct gazelle_stack_aggregate_stats aggregate_stats;
     } data;
 };
 
diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c
index 18548ab..3fd5903 100644
--- a/src/lstack/core/lstack_stack_stat.c
+++ b/src/lstack/core/lstack_stack_stat.c
@@ -198,6 +198,13 @@ static void get_stack_dfx_data(struct gazelle_stack_dfx_data *dfx, struct protoc
         case GAZELLE_STAT_LSTACK_SHOW:
         case GAZELLE_STAT_LSTACK_SHOW_RATE:
             get_stack_stats(dfx, stack);
+	    /* fall through */
+        case GAZELLE_STAT_LSTACK_SHOW_AGGREGATE:
+            ret = memcpy_s(&dfx->data.pkts.aggregate_stats, sizeof(dfx->data.pkts.aggregate_stats),
+                &stack->aggregate_stats, sizeof(stack->aggregate_stats));
+            if (ret != EOK) {
+                LSTACK_LOG(ERR, LSTACK, "memcpy_s err ret=%d \n", ret);
+            }
             break;
         case GAZELLE_STAT_LSTACK_SHOW_SNMP:
             ret = memcpy_s(&dfx->data.snmp, sizeof(dfx->data.snmp), &stack->lwip_stats->mib2,
@@ -218,13 +225,6 @@ static void get_stack_dfx_data(struct gazelle_stack_dfx_data *dfx, struct protoc
                 LSTACK_LOG(ERR, LSTACK, "memcpy_s err ret=%d \n", ret);
             }
             break;
-        case GAZELLE_STAT_LSTACK_SHOW_AGGREGATE:
-            ret = memcpy_s(&dfx->data.aggregate_stats, sizeof(dfx->data.aggregate_stats),
-                &stack->aggregate_stats, sizeof(stack->aggregate_stats));
-            if (ret != EOK) {
-                LSTACK_LOG(ERR, LSTACK, "memcpy_s err ret=%d \n", ret);
-            }
-            break;
         case GAZELLE_STAT_LTRAN_START_LATENCY:
             set_latency_start_flag(true);
             break;
@@ -287,6 +287,7 @@ int handle_stack_cmd(int fd, enum GAZELLE_STAT_MODE stat_mode)
         }
 
         dfx.tid = stack->tid;
+	dfx.stack_id = i;
         if (i == stack_group->stack_num - 1) {
             dfx.eof = 1;
         }
diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c
index 3bd120c..d3ff527 100644
--- a/src/ltran/ltran_dfx.c
+++ b/src/ltran/ltran_dfx.c
@@ -45,6 +45,7 @@
 #define GAZELLE_LSTACK_SET_MINNUM 6
 
 #define GAZELLE_CMD_MAX          5
+#define CMD_WAIT_TIME            1   // sec
 
 #define GAZELLE_RESULT_LEN       8291
 #define GAZELLE_MAX_LATENCY_TIME 1800    // max latency time 30mins
@@ -55,6 +56,7 @@ static int32_t g_unix_fd = -1;
 static int32_t g_ltran_rate_show_flag = GAZELLE_OFF;    // not show when first get total statistics
 static struct gazelle_stat_ltran_total g_last_ltran_total;
 static struct gazelle_stat_lstack_total g_last_lstack_total[GAZELLE_MAX_STACK_ARRAY_SIZE];
+static struct gazelle_stack_dfx_data g_last_lstack_data[GAZELLE_MAX_STACK_ARRAY_SIZE];
 
 static bool g_use_ltran = false;
 
@@ -73,6 +75,7 @@ struct gazelle_dfx_list {
 
 static void gazelle_print_ltran_stat_total(void *buf, const struct gazelle_stat_msg_request *req_msg);
 static void gazelle_print_ltran_stat_rate(void *buf, const struct gazelle_stat_msg_request *req_msg);
+static void gazelle_print_ltran_stat_lb_rate(void *buf, const struct gazelle_stat_msg_request *req_msg);
 static void gazelle_print_ltran_stat_client(void *buf, const struct gazelle_stat_msg_request *req_msg);
 static void gazelle_print_ltran_stat_burst(void *buf, const struct gazelle_stat_msg_request *req_msg);
 static void gazelle_print_ltran_stat_latency(void *buf, const struct gazelle_stat_msg_request *req_msg);
@@ -92,6 +95,7 @@ static void gazelle_print_lstack_aggregate(void *buf, const struct gazelle_stat_
 static struct gazelle_dfx_list g_gazelle_dfx_tbl[] = {
     {GAZELLE_STAT_LTRAN_SHOW,          sizeof(struct gazelle_stat_ltran_total),  gazelle_print_ltran_stat_total},
     {GAZELLE_STAT_LTRAN_SHOW_RATE,     sizeof(struct gazelle_stat_ltran_total),  gazelle_print_ltran_stat_rate},
+    {GAZELLE_STAT_LTRAN_SHOW_LB_RATE,     sizeof(struct gazelle_stat_ltran_total),  gazelle_print_ltran_stat_lb_rate},
     {GAZELLE_STAT_LTRAN_SHOW_INSTANCE, sizeof(struct gazelle_stat_ltran_client), gazelle_print_ltran_stat_client},
     {GAZELLE_STAT_LTRAN_SHOW_BURST,    sizeof(struct gazelle_stat_ltran_total),  gazelle_print_ltran_stat_burst},
     {GAZELLE_STAT_LTRAN_SHOW_LATENCY,  sizeof(struct in_addr),                  gazelle_print_ltran_stat_latency},
@@ -103,7 +107,7 @@ static struct gazelle_dfx_list g_gazelle_dfx_tbl[] = {
     {GAZELLE_STAT_LTRAN_SHOW_CONNTABLE, sizeof(struct gazelle_stat_forward_table), gazelle_print_ltran_conn},
     {GAZELLE_STAT_LSTACK_LOG_LEVEL_SET, 0,                                      gazelle_print_ltran_wait},
     {GAZELLE_STAT_LSTACK_SHOW,         sizeof(struct gazelle_stat_lstack_total), gazelle_print_lstack_stat_total},
-    {GAZELLE_STAT_LSTACK_SHOW_RATE,    sizeof(struct gazelle_stat_lstack_total), gazelle_print_lstack_stat_rate},
+    {GAZELLE_STAT_LSTACK_SHOW_RATE,    sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_stat_rate},
     {GAZELLE_STAT_LSTACK_SHOW_SNMP,    sizeof(struct gazelle_stack_dfx_data),  gazelle_print_lstack_stat_snmp},
     {GAZELLE_STAT_LSTACK_SHOW_CONN,    sizeof(struct gazelle_stack_dfx_data),  gazelle_print_lstack_stat_conn},
     {GAZELLE_STAT_LSTACK_SHOW_LATENCY, sizeof(struct gazelle_stack_dfx_data),  gazelle_print_lstack_stat_latency},
@@ -422,7 +426,7 @@ static void gazelle_print_ltran_wait(void *buf, const struct gazelle_stat_msg_re
 {
     (void)buf;
     (void)req_msg;
-    sleep(1); // give ltran time to read cmd
+    sleep(CMD_WAIT_TIME); // give ltran time to read cmd
 }
 
 static void gazelle_print_ltran_start_latency(void *buf, const struct gazelle_stat_msg_request *req_msg)
@@ -774,44 +778,39 @@ static void gazelle_print_lstack_stat_rate(void *buf, const struct gazelle_stat_
 {
     int32_t ret;
     double rate;
-    uint32_t stack_index;
+    uint32_t index;
     char *rate_type = NULL;
-    struct gazelle_stat_lstack_total *stats = (struct gazelle_stat_lstack_total *)buf;
+    uint32_t total_wait_time = g_wait_reply + CMD_WAIT_TIME;   /* STOP_LATENCY would sleep */
+    struct gazelle_stack_dfx_data *stats = (struct gazelle_stack_dfx_data *)buf;
     /* not show when first get total statistics */
     static int32_t g_lstack_rate_show_flag[GAZELLE_MAX_STACK_ARRAY_SIZE] = {0};
 
     do {
-        stack_index = stats->index;
-        if (stack_index >= GAZELLE_MAX_STACK_ARRAY_SIZE) {
+        index = stats->stack_id;
+        if (index >= GAZELLE_MAX_STACK_ARRAY_SIZE) {
             break;
         }
 
-        if (g_lstack_rate_show_flag[stack_index] == GAZELLE_ON) {
+        if (g_lstack_rate_show_flag[index] == GAZELLE_ON) {
             printf("------ Statistics of lstack rate   stack tid: %6u ------\n", stats->tid);
-            printf("rx_pkts: %-15"PRIu64" ", (stats->rx - g_last_lstack_total[stack_index].rx) /
-                   GAZELLE_DFX_REQ_INTERVAL_S);
-            rate = rate_convert_type((stats->rx_bytes - g_last_lstack_total[stack_index].rx_bytes) /
-                                     GAZELLE_DFX_REQ_INTERVAL_S, &rate_type);
+            printf("rx_pkts: %-15"PRIu64" ", (stats->data.pkts.stack_stat.rx -
+					      g_last_lstack_data[index].data.pkts.stack_stat.rx) / total_wait_time);
+            rate = rate_convert_type((stats->data.pkts.aggregate_stats.rx_bytes / g_wait_reply), &rate_type);
             printf("rx_bytes: %7.2lf%s  ", rate, rate_type);
-            printf("rx_err: %-15"PRIu64" ", (stats->rx_err - g_last_lstack_total[stack_index].rx_err) /
-                   GAZELLE_DFX_REQ_INTERVAL_S);
-            printf("rx_drop: %-15"PRIu64"\n", (stats->rx_drop - g_last_lstack_total[stack_index].rx_drop) /
-                   GAZELLE_DFX_REQ_INTERVAL_S);
-            printf("tx_pkts: %-15"PRIu64" ", (stats->tx - g_last_lstack_total[stack_index].tx) /
-                   GAZELLE_DFX_REQ_INTERVAL_S);
-            rate = rate_convert_type((stats->tx_bytes - g_last_lstack_total[stack_index].tx_bytes) /
-                                     GAZELLE_DFX_REQ_INTERVAL_S, &rate_type);
+            printf("rx_drop: %-15"PRIu64"\n", (stats->data.pkts.stack_stat.rx_drop -
+					       g_last_lstack_data[index].data.pkts.stack_stat.rx_drop) /total_wait_time);
+            printf("tx_pkts: %-15"PRIu64" ", (stats->data.pkts.stack_stat.tx -
+					      g_last_lstack_data[index].data.pkts.stack_stat.tx) / total_wait_time);
+            rate = rate_convert_type((stats->data.pkts.aggregate_stats.tx_bytes / g_wait_reply), &rate_type);
             printf("tx_bytes: %7.2lf%s  ", rate, rate_type);
-            printf("tx_err: %-15"PRIu64" ", (stats->tx_err - g_last_lstack_total[stack_index].tx_err) /
-                   GAZELLE_DFX_REQ_INTERVAL_S);
-            printf("tx_drop: %-15"PRIu64"\n\n", (stats->tx_drop - g_last_lstack_total[stack_index].tx_drop) /
-                   GAZELLE_DFX_REQ_INTERVAL_S);
+            printf("tx_drop: %-15"PRIu64"\n\n", (stats->data.pkts.stack_stat.tx_drop -
+						 g_last_lstack_data[index].data.pkts.stack_stat.tx_drop) / total_wait_time);
         } else {
-            g_lstack_rate_show_flag[stack_index] = GAZELLE_ON;
+            g_lstack_rate_show_flag[index] = GAZELLE_ON;
         }
 
-        ret = memcpy_s(&g_last_lstack_total[stack_index], sizeof(*stats), stats,
-            sizeof(struct gazelle_stat_lstack_total));
+        ret = memcpy_s(&g_last_lstack_data[index], sizeof(*stats), stats,
+            sizeof(struct gazelle_stack_dfx_data));
         if (ret != EOK) {
             printf("%s:%d memcpy_s fail ret=%d\n", __FUNCTION__, __LINE__, ret);
         }
@@ -820,7 +819,7 @@ static void gazelle_print_lstack_stat_rate(void *buf, const struct gazelle_stat_
             break;
         }
 
-        ret = dfx_stat_read_from_ltran(buf, sizeof(struct gazelle_stat_lstack_total), req_msg->stat_mode);
+        ret = dfx_stat_read_from_ltran(buf, sizeof(struct gazelle_stack_dfx_data), req_msg->stat_mode);
         if (ret != GAZELLE_OK) {
             return;
         }
@@ -846,6 +845,63 @@ static void gazelle_print_lstack_tcp_stat(const struct gazelle_stat_lstack_snmp
     printf("tcp_listen_drops: %u\n",  snmp->tcp_listen_drops);
 }
 
+static void gazelle_print_ltran_stat_lb_rate(void *buf, const struct gazelle_stat_msg_request *req_msg)
+{
+    int32_t ret;
+     double rate;
+     uint32_t stack_index;
+     char *rate_type = NULL;
+     struct gazelle_stat_lstack_total *stats = (struct gazelle_stat_lstack_total *)buf;
+     /* not show when first get total statistics */
+     static int32_t g_ltran_lb_rate_show_flag[GAZELLE_MAX_STACK_ARRAY_SIZE] = {0};
+
+     do {
+         stack_index = stats->index;
+         if (stack_index >= GAZELLE_MAX_STACK_ARRAY_SIZE) {
+	     break;
+         }
+         
+         if (g_ltran_lb_rate_show_flag[stack_index] == GAZELLE_ON) {
+       	     printf("------ Statistics of lstack rate   stack tid: %6u ------\n", stats->tid);
+       	     printf("rx_pkts: %-15"PRIu64" ", (stats->rx - g_last_lstack_total[stack_index].rx) /
+		    GAZELLE_DFX_REQ_INTERVAL_S);
+       	     rate = rate_convert_type((stats->rx_bytes - g_last_lstack_total[stack_index].rx_bytes) /
+				      GAZELLE_DFX_REQ_INTERVAL_S, &rate_type);
+       	     printf("rx_bytes: %7.2lf%s  ", rate, rate_type);
+       	     printf("rx_err: %-15"PRIu64" ", (stats->rx_err - g_last_lstack_total[stack_index].rx_err) /
+		    GAZELLE_DFX_REQ_INTERVAL_S);
+       	     printf("rx_drop: %-15"PRIu64"\n", (stats->rx_drop - g_last_lstack_total[stack_index].rx_drop) /
+		    GAZELLE_DFX_REQ_INTERVAL_S);
+       	     printf("tx_pkts: %-15"PRIu64" ", (stats->tx - g_last_lstack_total[stack_index].tx) /
+		    GAZELLE_DFX_REQ_INTERVAL_S);
+       	     rate = rate_convert_type((stats->tx_bytes - g_last_lstack_total[stack_index].tx_bytes) /
+				      GAZELLE_DFX_REQ_INTERVAL_S, &rate_type);
+       	     printf("tx_bytes: %7.2lf%s  ", rate, rate_type);
+       	     printf("tx_err: %-15"PRIu64" ", (stats->tx_err - g_last_lstack_total[stack_index].tx_err) /
+		    GAZELLE_DFX_REQ_INTERVAL_S);
+       	     printf("tx_drop: %-15"PRIu64"\n\n", (stats->tx_drop - g_last_lstack_total[stack_index].tx_drop) /
+		    GAZELLE_DFX_REQ_INTERVAL_S);
+         } else {
+	     g_ltran_lb_rate_show_flag[stack_index] = GAZELLE_ON;
+         }
+         
+         ret = memcpy_s(&g_last_lstack_total[stack_index], sizeof(*stats), stats,
+			sizeof(struct gazelle_stat_lstack_total));
+         if (ret != EOK) {
+	     printf("%s:%d memcpy_s fail ret=%d\n", __FUNCTION__, __LINE__, ret);
+         }
+         
+         if (stats->eof != 0) {
+	     break;
+         }
+       
+         ret = dfx_stat_read_from_ltran(buf, sizeof(struct gazelle_stat_lstack_total), req_msg->stat_mode);
+         if (ret != GAZELLE_OK) {
+	     return;
+         }
+     } while (true);
+}
+
 static void gazelle_print_lstack_stat_snmp_core(const struct gazelle_stack_dfx_data *stat,
                                                 const struct gazelle_stat_lstack_snmp *snmp)
 {
@@ -1048,15 +1104,12 @@ static int32_t parse_dfx_ltran_show_args(int32_t argc, char *argv[], struct gaze
     if (strcmp(param, "rate") == 0 || strcmp(param, "-r") == 0) {
         req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_SHOW_RATE;
         req_msg[cmd_index++].stat_mode = GAZELLE_STAT_MODE_MAX;
-    }
-    if (strcmp(param, "instance") == 0 || strcmp(param, "-i") == 0) {
+    } else if (strcmp(param, "instance") == 0 || strcmp(param, "-i") == 0) {
         req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_SHOW_INSTANCE;
-    }
-    if (strcmp(param, "burst") == 0 || strcmp(param, "-b") == 0) {
+    } else if (strcmp(param, "burst") == 0 || strcmp(param, "-b") == 0) {
         req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_SHOW_BURST;
         req_msg[cmd_index++].stat_mode = GAZELLE_STAT_MODE_MAX;
-    }
-    if (strcmp(param, "table") == 0 || strcmp(param, "-t") == 0) {
+    } else if (strcmp(param, "table") == 0 || strcmp(param, "-t") == 0) {
         if (argc < GAZELLE_OPT_LPM_ARG_IDX1) {
             return cmd_index;
         }
@@ -1067,8 +1120,7 @@ static int32_t parse_dfx_ltran_show_args(int32_t argc, char *argv[], struct gaze
         if (strcmp(param, "conntable") == 0) {
             req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_SHOW_CONNTABLE;
         }
-    }
-    if (strcmp(param, "latency") == 0 || strcmp(param, "-l") == 0) {
+    } else if (strcmp(param, "latency") == 0 || strcmp(param, "-l") == 0) {
         req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_START_LATENCY;
         req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_STOP_LATENCY;
         req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_SHOW_LATENCY;
@@ -1092,7 +1144,7 @@ static int32_t parse_dfx_ltran_show_args(int32_t argc, char *argv[], struct gaze
 static void gazelle_print_lstack_aggregate(void *buf, const struct gazelle_stat_msg_request *req_msg)
 {
     struct gazelle_stack_dfx_data *dfx = (struct gazelle_stack_dfx_data *)buf;
-    struct gazelle_stack_aggregate_stats *stats = &dfx->data.aggregate_stats;
+    struct gazelle_stack_aggregate_stats *stats = &dfx->data.pkts.aggregate_stats;
     char *rate_type = NULL;
     double rate;
     int32_t ret = 0;
@@ -1219,19 +1271,21 @@ static int32_t parse_dfx_lstack_show_args(int32_t argc, char *argv[], struct gaz
 
     char *param = argv[GAZELLE_OPTIONS1_ARG_IDX];
     if (strcmp(param, "rate") == 0 || strcmp(param, "-r") == 0) {
-        req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LSTACK_SHOW_RATE;
+        if (g_use_ltran) {
+	    req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_SHOW_LB_RATE;
+        } else {
+	    req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_START_LATENCY;
+	    req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_STOP_LATENCY;
+  	    req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LSTACK_SHOW_RATE;
+	}
         req_msg[cmd_index++].stat_mode = GAZELLE_STAT_MODE_MAX;
-    }
-    if (strcmp(param, "snmp") == 0 || strcmp(param, "-s") == 0) {
+    } else if (strcmp(param, "snmp") == 0 || strcmp(param, "-s") == 0) {
         req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LSTACK_SHOW_SNMP;
-    }
-    if (strcmp(param, "connect") == 0 || strcmp(param, "-c") == 0) {
+    } else if (strcmp(param, "connect") == 0 || strcmp(param, "-c") == 0) {
         req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LSTACK_SHOW_CONN;
-    }
-    if (strcmp(param, "xstats") == 0 || strcmp(param, "-x") == 0) {
+    } else if (strcmp(param, "xstats") == 0 || strcmp(param, "-x") == 0) {
         req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LSTACK_SHOW_XSTATS;
-    }
-    if (strcmp(param, "latency") == 0 || strcmp(param, "-l") == 0) {
+    } else if (strcmp(param, "latency") == 0 || strcmp(param, "-l") == 0) {
         req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_START_LATENCY;
         req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_STOP_LATENCY;
         req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LSTACK_SHOW_LATENCY;
@@ -1242,8 +1296,7 @@ static int32_t parse_dfx_lstack_show_args(int32_t argc, char *argv[], struct gaz
         if (parse_delay_arg(argc, argv, delay) != 0) {
             return 0;
         }
-    }
-    if (strcmp(param, "aggragate") == 0 || strcmp(param, "-a") == 0) {
+    } else if (strcmp(param, "aggragate") == 0 || strcmp(param, "-a") == 0) {
         req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_START_LATENCY;
         req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_STOP_LATENCY;
         req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LSTACK_SHOW_AGGREGATE;
@@ -1314,31 +1367,6 @@ static int32_t parse_dfx_cmd_args(int32_t argc, char *argv[], struct gazelle_sta
     return num_cmd;
 }
 
-static int32_t check_cmd_support(struct gazelle_stat_msg_request *req_msg, int32_t req_msg_num)
-{
-    switch (req_msg[0].stat_mode) {
-        case GAZELLE_STAT_LSTACK_LOG_LEVEL_SET:
-        case GAZELLE_STAT_LSTACK_SHOW:
-        case GAZELLE_STAT_LSTACK_SHOW_SNMP:
-        case GAZELLE_STAT_LSTACK_SHOW_CONN:
-        case GAZELLE_STAT_LSTACK_SHOW_LATENCY:
-        case GAZELLE_STAT_LSTACK_LOW_POWER_MDF:
-        case GAZELLE_STAT_LSTACK_SHOW_XSTATS:
-        case GAZELLE_STAT_LSTACK_SHOW_AGGREGATE:
-            return 0;
-        default:
-            if (req_msg[0].stat_mode == GAZELLE_STAT_LTRAN_START_LATENCY &&
-                (req_msg[req_msg_num - 1].stat_mode == GAZELLE_STAT_LSTACK_SHOW_LATENCY ||
-                 req_msg[req_msg_num - 1].stat_mode == GAZELLE_STAT_LSTACK_SHOW_AGGREGATE)) {
-                return 0;
-            }
-            /* keep output consistency */
-            printf("connect ltran failed. errno: 111 ret=-1\n");
-            printf("You may need to use the -u parameter to specify the UNIX_PREFIX that matches the configuration.\n");
-            return -1;
-    }
-}
-
 int32_t dfx_loop(struct gazelle_stat_msg_request *req_msg, int32_t req_msg_num)
 {
     int32_t ret;
@@ -1377,8 +1405,10 @@ int32_t dfx_loop(struct gazelle_stat_msg_request *req_msg, int32_t req_msg_num)
 
         // stat_mode = GAZELLE_STAT_MODE_MAX need repeat command
         if (req_msg[msg_index].stat_mode == GAZELLE_STAT_MODE_MAX) {
-            msg_index--;
-            sleep(GAZELLE_DFX_REQ_INTERVAL_S);
+	    if (req_msg[msg_index - 1].stat_mode != GAZELLE_STAT_LSTACK_SHOW_RATE) {
+	        sleep(GAZELLE_DFX_REQ_INTERVAL_S);
+	    }
+	    msg_index = 0;
         }
     }
 
@@ -1388,7 +1418,7 @@ int32_t dfx_loop(struct gazelle_stat_msg_request *req_msg, int32_t req_msg_num)
 int32_t main(int32_t argc, char *argv[])
 {
     struct gazelle_stat_msg_request req_msg[GAZELLE_CMD_MAX] = {0};
-    int32_t req_msg_num, ret;
+    int32_t req_msg_num;
 
     int unix_arg = 0;
     for (int32_t i = 1; i < argc; i++) {
@@ -1418,13 +1448,5 @@ int32_t main(int32_t argc, char *argv[])
         return 0;
     }
 
-    if (!g_use_ltran) {
-        g_gazelle_dfx_tbl[GAZELLE_STAT_LSTACK_SHOW].recv_size = sizeof(struct gazelle_stack_dfx_data);
-        ret = check_cmd_support(req_msg, req_msg_num);
-        if (ret < 0) {
-            return -1;
-        }
-    }
-
     return dfx_loop(req_msg, req_msg_num);
 }
diff --git a/src/ltran/ltran_monitor.c b/src/ltran/ltran_monitor.c
index d163a47..792db89 100644
--- a/src/ltran/ltran_monitor.c
+++ b/src/ltran/ltran_monitor.c
@@ -335,14 +335,15 @@ static int32_t lstack_req_mode_process(int32_t fd, const struct gazelle_stat_msg
         case GAZELLE_STAT_LSTACK_LOG_LEVEL_SET:
             handle_resp_lstack_transfer(req_msg, -1);
             break;
-        case GAZELLE_STAT_LSTACK_SHOW_RATE:
+        case GAZELLE_STAT_LTRAN_SHOW_LB_RATE:
             handle_resp_lstack_total(req_msg, fd);
             break;
         case GAZELLE_STAT_LSTACK_SHOW:
             handle_resp_lstack_total(req_msg, fd);
             handle_resp_lstack_transfer(req_msg, fd);
             break;
-        case GAZELLE_STAT_LSTACK_SHOW_SNMP:  // fall through
+	case GAZELLE_STAT_LSTACK_SHOW_RATE:  // fall through
+        case GAZELLE_STAT_LSTACK_SHOW_SNMP:
         case GAZELLE_STAT_LSTACK_SHOW_CONN:
         case GAZELLE_STAT_LSTACK_SHOW_LATENCY:
         case GAZELLE_STAT_LSTACK_LOW_POWER_MDF:
-- 
2.27.0

