[v2] app/testpmd: add memory dump command
Checks
Commit Message
Introduce new command to dump memory statistics of each socket,
summary, also show changes since last call.
Usage:
dump_socket_mem
Signed-off-by: Xueming Li <xuemingl@mellanox.com>
---
app/test-pmd/cmdline.c | 53 +++++++++++++++++++++++++++++
doc/guides/testpmd_app_ug/testpmd_funcs.rst | 6 ++++
2 files changed, 59 insertions(+)
Comments
On 4/5/2020 3:49 AM, Xueming Li wrote:
> Introduce new command to dump memory statistics of each socket,
> summary, also show changes since last call.
>
> Usage:
> dump_socket_mem
>
> Signed-off-by: Xueming Li <xuemingl@mellanox.com>
<...>
> @@ -9576,6 +9626,8 @@ static void cmd_dump_parsed(void *parsed_result,
>
> if (!strcmp(res->dump, "dump_physmem"))
> rte_dump_physmem_layout(stdout);
> + else if (!strcmp(res->dump, "dump_socket_mem"))
> + dump_socket_mem(stdout);
> else if (!strcmp(res->dump, "dump_memzone"))
> rte_memzone_dump(stdout);
> else if (!strcmp(res->dump, "dump_malloc")) {
This "dump_malloc" is not in the upstream, which cause a conflict while merging
the patch, which is breaking our automated tests.
It is OK for now, but for later please rebase your patches on latest master.
> @@ -9604,6 +9656,7 @@ static void cmd_dump_parsed(void *parsed_result,
> TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
> "dump_physmem#"
> "dump_memzone#"
> + "dump_socket_mem#"
> "dump_struct_sizes#"
> "dump_ring#"
> "dump_mempool#"
> diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> index 1a9879f..0942ae5 100644
> --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> @@ -539,6 +539,12 @@ Dumps the layout of all memory zones::
>
> testpmd> dump_memzone
>
> +dump socket
> +~~~~~~~~~~~~
Title fixed as "dump socket memory" while merging
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
Applied to dpdk-next-net/master, thanks.
Hi Ferruh,
Thanks for your comments, noted.
> -----Original Message-----
> From: Ferruh Yigit <ferruh.yigit@intel.com>
> Sent: Tuesday, April 7, 2020 5:22 PM
> To: Xueming(Steven) Li <xuemingl@mellanox.com>; Wenzhuo Lu
> <wenzhuo.lu@intel.com>; Jingjing Wu <jingjing.wu@intel.com>; Bernard
> Iremonger <bernard.iremonger@intel.com>; Anatoly Burakov
> <anatoly.burakov@intel.com>; Stephen Hemminger
> <stephen@networkplumber.org>
> Cc: dev@dpdk.org; Asaf Penso <asafp@mellanox.com>
> Subject: Re: [dpdk-dev] [PATCH v2] app/testpmd: add memory dump
> command
>
> On 4/5/2020 3:49 AM, Xueming Li wrote:
> > Introduce new command to dump memory statistics of each socket,
> > summary, also show changes since last call.
> >
> > Usage:
> > dump_socket_mem
> >
> > Signed-off-by: Xueming Li <xuemingl@mellanox.com>
>
> <...>
>
> > @@ -9576,6 +9626,8 @@ static void cmd_dump_parsed(void *parsed_result,
> >
> > if (!strcmp(res->dump, "dump_physmem"))
> > rte_dump_physmem_layout(stdout);
> > + else if (!strcmp(res->dump, "dump_socket_mem"))
> > + dump_socket_mem(stdout);
> > else if (!strcmp(res->dump, "dump_memzone"))
> > rte_memzone_dump(stdout);
> > else if (!strcmp(res->dump, "dump_malloc")) {
>
> This "dump_malloc" is not in the upstream, which cause a conflict while
> merging the patch, which is breaking our automated tests.
> It is OK for now, but for later please rebase your patches on latest master.
>
> > @@ -9604,6 +9656,7 @@ static void cmd_dump_parsed(void *parsed_result,
> > TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
> > "dump_physmem#"
> > "dump_memzone#"
> > + "dump_socket_mem#"
> > "dump_struct_sizes#"
> > "dump_ring#"
> > "dump_mempool#"
> > diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> > b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> > index 1a9879f..0942ae5 100644
> > --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> > +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> > @@ -539,6 +539,12 @@ Dumps the layout of all memory zones::
> >
> > testpmd> dump_memzone
> >
> > +dump socket
> > +~~~~~~~~~~~~
>
> Title fixed as "dump socket memory" while merging
>
>
> Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com> Applied to dpdk-next-
> net/master, thanks.
@@ -9568,6 +9568,56 @@ struct cmd_dump_result {
#undef DUMP_SIZE
}
+
+/* Dump the socket memory statistics on console */
+static void
+dump_socket_mem(FILE *f)
+{
+ struct rte_malloc_socket_stats socket_stats;
+ unsigned int i;
+ size_t total = 0;
+ size_t alloc = 0;
+ size_t free = 0;
+ unsigned int n_alloc = 0;
+ unsigned int n_free = 0;
+ static size_t last_allocs;
+ static size_t last_total;
+
+
+ for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
+ if (rte_malloc_get_socket_stats(i, &socket_stats) ||
+ !socket_stats.heap_totalsz_bytes)
+ continue;
+ total += socket_stats.heap_totalsz_bytes;
+ alloc += socket_stats.heap_allocsz_bytes;
+ free += socket_stats.heap_freesz_bytes;
+ n_alloc += socket_stats.alloc_count;
+ n_free += socket_stats.free_count;
+ fprintf(f,
+ "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
+ i,
+ (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
+ (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
+ (double)socket_stats.heap_allocsz_bytes * 100 /
+ (double)socket_stats.heap_totalsz_bytes,
+ (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
+ socket_stats.alloc_count,
+ socket_stats.free_count);
+ }
+ fprintf(f,
+ "Total : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
+ (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
+ (double)alloc * 100 / (double)total,
+ (double)free / (1024 * 1024),
+ n_alloc, n_free);
+ if (last_allocs)
+ fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
+ ((double)total - (double)last_total) / (1024 * 1024),
+ (double)(alloc - (double)last_allocs) / 1024 /1024);
+ last_allocs = alloc;
+ last_total = total;
+}
+
static void cmd_dump_parsed(void *parsed_result,
__attribute__((unused)) struct cmdline *cl,
__attribute__((unused)) void *data)
@@ -9576,6 +9626,8 @@ static void cmd_dump_parsed(void *parsed_result,
if (!strcmp(res->dump, "dump_physmem"))
rte_dump_physmem_layout(stdout);
+ else if (!strcmp(res->dump, "dump_socket_mem"))
+ dump_socket_mem(stdout);
else if (!strcmp(res->dump, "dump_memzone"))
rte_memzone_dump(stdout);
else if (!strcmp(res->dump, "dump_malloc")) {
@@ -9604,6 +9656,7 @@ static void cmd_dump_parsed(void *parsed_result,
TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
"dump_physmem#"
"dump_memzone#"
+ "dump_socket_mem#"
"dump_struct_sizes#"
"dump_ring#"
"dump_mempool#"
@@ -539,6 +539,12 @@ Dumps the layout of all memory zones::
testpmd> dump_memzone
+dump socket
+~~~~~~~~~~~~
+
+Dumps the memory usage of all sockets::
+
+ testpmd> dump_socket_mem
dump struct size
~~~~~~~~~~~~~~~~