<div dir="auto">Most testpmd commands use spaces not underline as word separator.</div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Wed, Oct 1, 2025, 01:39 Thomas Monjalon <<a href="mailto:thomas@monjalon.net">thomas@monjalon.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">From: Shani Peretz <<a href="mailto:shperetz@nvidia.com" target="_blank" rel="noreferrer">shperetz@nvidia.com</a>><br>
<br>
Dump the mbuf history to the console or to a file.<br>
<br>
The dump will contain:<br>
- Operation history for each mbuf<br>
- Summary and statistics about all mbufs<br>
<br>
Dump the history of all mbuf pools:<br>
testpmd> dump_mbuf_history_all<br>
<br>
Dump the history of one mbuf pool:<br>
testpmd> dump_mbuf_history_single_mempool <mempool_name> [file_name]<br>
<br>
Dump the history of one mbuf:<br>
testpmd> dump_mbuf_history_single<br>
<br>
Signed-off-by: Shani Peretz <<a href="mailto:shperetz@nvidia.com" target="_blank" rel="noreferrer">shperetz@nvidia.com</a>><br>
---<br>
 app/test-pmd/cmdline.c | 246 ++++++++++++++++++++++++++++++++++++++++-<br>
 1 file changed, 245 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c<br>
index 3731fba370..113db68f8c 100644<br>
--- a/app/test-pmd/cmdline.c<br>
+++ b/app/test-pmd/cmdline.c<br>
@@ -40,6 +40,7 @@<br>
 #include <rte_gro.h><br>
 #endif<br>
 #include <rte_mbuf_dyn.h><br>
+#include <rte_mbuf_history.h><br>
 #include <rte_trace.h><br>
<br>
 #include <cmdline_rdline.h><br>
@@ -296,6 +297,15 @@ static void cmd_help_long_parsed(void *parsed_result,<br>
                        "dump_log_types\n"<br>
                        "    Dumps the log level for all the dpdk modules\n\n"<br>
<br>
+                       "dump_mbuf_history_all\n"<br>
+                       "    Dumps the mbuf history for all mempools\n\n"<br>
+<br>
+                       "dump_mbuf_history_single <mbuf_ptr>\n"<br>
+                       "    Dumps the history for a specific mbuf (use 0x<address> format)\n\n"<br>
+<br>
+                       "dump_mbuf_history_single_mempool <mempool_name> [file_name]\n"<br>
+                       "    Dumps the history for a specific mempool\n\n"<br>
+<br>
                        "show port (port_id) speed_lanes capabilities"<br>
                        "       Show speed lanes capabilities of a port.\n\n"<br>
                );<br>
@@ -9177,6 +9187,8 @@ static void cmd_dump_parsed(void *parsed_result,<br>
 #endif<br>
        else if (!strcmp(res->dump, "dump_log_types"))<br>
                rte_log_dump(stdout);<br>
+       else if (!strcmp(res->dump, "dump_mbuf_history_all"))<br>
+               rte_mbuf_history_dump_all(stdout);<br>
 }<br>
<br>
 static cmdline_parse_token_string_t cmd_dump_dump =<br>
@@ -9198,7 +9210,8 @@ cmd_dump_init(void)<br>
 #ifndef RTE_EXEC_ENV_WINDOWS<br>
                "dump_trace#"<br>
 #endif<br>
-               "dump_log_types";<br>
+               "dump_log_types#"<br>
+               "dump_mbuf_history";<br>
 }<br>
<br>
 static cmdline_parse_inst_t cmd_dump = {<br>
@@ -9260,6 +9273,232 @@ static cmdline_parse_inst_t cmd_dump_one = {<br>
        },<br>
 };<br>
<br>
+/* Dump mbuf history to file */<br>
+struct cmd_dump_mbuf_to_file_result {<br>
+       cmdline_fixed_string_t dump;<br>
+       cmdline_fixed_string_t file;<br>
+};<br>
+<br>
+static void cmd_dump_mbuf_to_file_parsed(void *parsed_result,<br>
+               struct cmdline *cl, __rte_unused void *data)<br>
+{<br>
+       struct cmd_dump_mbuf_to_file_result *res = parsed_result;<br>
+       FILE *file = stdout;<br>
+       char *file_name = res->file;<br>
+<br>
+       if (strcmp(res->dump, "dump_mbuf_history_all")) {<br>
+               cmdline_printf(cl, "Invalid dump type\n");<br>
+               return;<br>
+       }<br>
+<br>
+       if (file_name && strlen(file_name)) {<br>
+               file = fopen(file_name, "w");<br>
+               if (!file) {<br>
+                       rte_mbuf_history_dump_all(stdout);<br>
+                       return;<br>
+               }<br>
+       }<br>
+       rte_mbuf_history_dump_all(file);<br>
+       printf("Flow dump finished\n");<br>
+       if (file_name && strlen(file_name))<br>
+               fclose(file);<br>
+}<br>
+<br>
+static cmdline_parse_token_string_t cmd_dump_mbuf_to_file_dump =<br>
+       TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_to_file_result, dump,<br>
+                       "dump_mbuf_history_all");<br>
+<br>
+static cmdline_parse_token_string_t cmd_dump_mbuf_to_file_file =<br>
+       TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_to_file_result, file, NULL);<br>
+<br>
+static cmdline_parse_inst_t cmd_dump_mbuf_to_file = {<br>
+       .f = cmd_dump_mbuf_to_file_parsed,  /* function to call */<br>
+       .data = NULL,      /* 2nd arg of func */<br>
+       .help_str = "dump_mbuf_history_all <file_name>: Dump mbuf history to file",<br>
+       .tokens = {        /* token list, NULL terminated */<br>
+               (void *)&cmd_dump_mbuf_to_file_dump,<br>
+               (void *)&cmd_dump_mbuf_to_file_file,<br>
+               NULL,<br>
+       },<br>
+};<br>
+<br>
+/* Dump single mbuf history */<br>
+struct cmd_dump_mbuf_history_single_result {<br>
+       cmdline_fixed_string_t dump;<br>
+       cmdline_fixed_string_t mbuf_ptr;<br>
+};<br>
+<br>
+static void cmd_dump_mbuf_history_single_parsed(void *parsed_result,<br>
+               __rte_unused struct cmdline *cl, __rte_unused void *data)<br>
+{<br>
+       struct cmd_dump_mbuf_history_single_result *res = parsed_result;<br>
+       struct rte_mbuf *mbuf;<br>
+       uintptr_t mbuf_addr;<br>
+<br>
+       /* Parse the mbuf pointer from hex string */<br>
+       if (sscanf(res->mbuf_ptr, "0x%" SCNxPTR, &mbuf_addr) != 1) {<br>
+               printf("Invalid mbuf pointer format. Use 0x<address>\n");<br>
+               return;<br>
+       }<br>
+<br>
+       mbuf = (struct rte_mbuf *)mbuf_addr;<br>
+<br>
+       printf("Dumping history for mbuf at %p:\n", mbuf);<br>
+       rte_mbuf_history_dump(stdout, mbuf);<br>
+}<br>
+<br>
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_single_dump =<br>
+       TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_single_result, dump,<br>
+                       "dump_mbuf_history_single");<br>
+<br>
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_single_ptr =<br>
+       TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_single_result, mbuf_ptr,<br>
+                       NULL);<br>
+<br>
+static cmdline_parse_inst_t cmd_dump_mbuf_history_single = {<br>
+       .f = cmd_dump_mbuf_history_single_parsed,<br>
+       .data = NULL,<br>
+       .help_str = "dump_mbuf_history_single <mbuf_ptr>: Dump history for specific mbuf",<br>
+       .tokens = {<br>
+               (void *)&cmd_dump_mbuf_history_single_dump,<br>
+               (void *)&cmd_dump_mbuf_history_single_ptr,<br>
+               NULL,<br>
+       },<br>
+};<br>
+<br>
+/* Dump single mempool history */<br>
+struct cmd_dump_mbuf_history_single_mempool_result {<br>
+       cmdline_fixed_string_t dump;<br>
+       cmdline_fixed_string_t mempool_name;<br>
+};<br>
+<br>
+static void cmd_dump_mbuf_history_single_mempool_parsed(void *parsed_result,<br>
+               __rte_unused struct cmdline *cl, __rte_unused void *data)<br>
+{<br>
+       struct cmd_dump_mbuf_history_single_mempool_result *res = parsed_result;<br>
+       struct rte_mempool *mp;<br>
+<br>
+       mp = rte_mempool_lookup(res->mempool_name);<br>
+       if (mp == NULL) {<br>
+               printf("Mempool '%s' not found\n", res->mempool_name);<br>
+               return;<br>
+       }<br>
+<br>
+       printf("Dumping history for mempool '%s':\n", res->mempool_name);<br>
+<br>
+       rte_mbuf_history_dump_mempool(stdout, mp);<br>
+}<br>
+<br>
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_single_mempool_dump =<br>
+       TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_single_mempool_result,<br>
+                       dump, "dump_mbuf_history_single_mempool");<br>
+<br>
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_single_mempool_name =<br>
+       TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_single_mempool_result,<br>
+                       mempool_name, NULL);<br>
+<br>
+static cmdline_parse_inst_t cmd_dump_mbuf_history_single_mempool = {<br>
+       .f = cmd_dump_mbuf_history_single_mempool_parsed,<br>
+       .data = NULL,<br>
+       .help_str = "dump_mbuf_history_single_mempool <mempool_name>: Dump history for specific mempool",<br>
+       .tokens = {<br>
+               (void *)&cmd_dump_mbuf_history_single_mempool_dump,<br>
+               (void *)&cmd_dump_mbuf_history_single_mempool_name,<br>
+               NULL,<br>
+       },<br>
+};<br>
+<br>
+/* Dump single mempool history to file only */<br>
+struct cmd_dump_mbuf_history_single_mempool_to_file_result {<br>
+       cmdline_fixed_string_t dump;<br>
+       cmdline_fixed_string_t mempool_name;<br>
+       cmdline_fixed_string_t file;<br>
+};<br>
+<br>
+static void cmd_dump_mbuf_history_single_mempool_to_file_parsed(void *parsed_result,<br>
+               __rte_unused struct cmdline *cl, __rte_unused void *data)<br>
+{<br>
+       struct cmd_dump_mbuf_history_single_mempool_to_file_result *res = parsed_result;<br>
+       struct rte_mempool *mp;<br>
+       FILE *file = NULL;<br>
+       char *file_name = res->file;<br>
+<br>
+       mp = rte_mempool_lookup(res->mempool_name);<br>
+       if (mp == NULL) {<br>
+               printf("Mempool '%s' not found\n", res->mempool_name);<br>
+               return;<br>
+       }<br>
+<br>
+       if (file_name && strlen(file_name)) {<br>
+               file = fopen(file_name, "w");<br>
+               if (!file) {<br>
+                       printf("Failed to open file '%s'\n", file_name);<br>
+                       return;<br>
+               }<br>
+       } else {<br>
+               printf("File name required for this command\n");<br>
+               return;<br>
+       }<br>
+<br>
+       printf("Dumping history for mempool '%s' to file '%s'...\n", res->mempool_name, file_name);<br>
+       rte_mbuf_history_dump_mempool(file, mp);<br>
+       printf("Mempool history dump finished\n");<br>
+       fclose(file);<br>
+}<br>
+<br>
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_single_mempool_to_file_dump =<br>
+       TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_single_mempool_to_file_result,<br>
+                       dump, "dump_mbuf_history_single_mempool");<br>
+<br>
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_single_mempool_to_file_name =<br>
+       TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_single_mempool_to_file_result,<br>
+                       mempool_name, NULL);<br>
+<br>
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_single_mempool_to_file_file =<br>
+       TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_single_mempool_to_file_result,<br>
+                       file, NULL);<br>
+<br>
+static cmdline_parse_inst_t cmd_dump_mbuf_history_single_mempool_to_file = {<br>
+       .f = cmd_dump_mbuf_history_single_mempool_to_file_parsed,<br>
+       .data = NULL,<br>
+       .help_str = "dump_mbuf_history_single_mempool <mempool_name> <file_name>: Dump history for specific mempool to file",<br>
+       .tokens = {<br>
+               (void *)&cmd_dump_mbuf_history_single_mempool_to_file_dump,<br>
+               (void *)&cmd_dump_mbuf_history_single_mempool_to_file_name,<br>
+               (void *)&cmd_dump_mbuf_history_single_mempool_to_file_file,<br>
+               NULL,<br>
+       },<br>
+};<br>
+<br>
+/* Dump all mempools history */<br>
+struct cmd_dump_mbuf_history_all_result {<br>
+       cmdline_fixed_string_t dump;<br>
+};<br>
+<br>
+static void cmd_dump_mbuf_history_all_parsed(void *parsed_result,<br>
+               __rte_unused struct cmdline *cl, __rte_unused void *data)<br>
+{<br>
+       __rte_unused struct cmd_dump_mempool_history_all_result *res = parsed_result;<br>
+<br>
+       printf("Dumping history for all mempools:\n");<br>
+       rte_mbuf_history_dump_all(stdout);<br>
+}<br>
+<br>
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_all_dump =<br>
+       TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_all_result, dump,<br>
+                       "dump_mbuf_history_all");<br>
+<br>
+static cmdline_parse_inst_t cmd_dump_mbuf_history_all = {<br>
+       .f = cmd_dump_mbuf_history_all_parsed,<br>
+       .data = NULL,<br>
+       .help_str = "dump_mbuf_history_all: Dump history for all mempools",<br>
+       .tokens = {<br>
+               (void *)&cmd_dump_mbuf_history_all_dump,<br>
+               NULL,<br>
+       },<br>
+};<br>
+<br>
+<br>
 /* *** Filters Control *** */<br>
<br>
 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \<br>
@@ -13999,6 +14238,11 @@ static cmdline_parse_ctx_t builtin_ctx[] = {<br>
        &cmd_cleanup_txq_mbufs,<br>
        &cmd_dump,<br>
        &cmd_dump_one,<br>
+       &cmd_dump_mbuf_to_file,<br>
+       &cmd_dump_mbuf_history_single,<br>
+       &cmd_dump_mbuf_history_single_mempool,<br>
+       &cmd_dump_mbuf_history_single_mempool_to_file,<br>
+       &cmd_dump_mbuf_history_all,<br>
        &cmd_flow,<br>
        &cmd_show_port_meter_cap,<br>
        &cmd_add_port_meter_profile_srtcm,<br>
-- <br>
2.51.0<br>
<br>
</blockquote></div>