New appctl 'dpdk/get-malloc-stats' implemented to get result of
'rte_malloc_dump_stats()' function.

Could be used for debugging.

Signed-off-by: Eli Britstein <[email protected]>
Reviewed-by: Salem Sol <[email protected]>
---
 NEWS                 |  1 +
 lib/dpdk-unixctl.man |  2 ++
 lib/dpdk.c           | 29 +++++++++++++++++++++++++++++
 3 files changed, 32 insertions(+)

diff --git a/NEWS b/NEWS
index e0c0f0408..3420c38ce 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@ Post-v2.15.0
      * New command 'record-hostname-if-not-set' to update hostname in ovsdb.
    - DPDK:
      * New debug appctl command 'dpdk/get-socket-stats'.
+     * New debug appctl command 'dpdk/get-malloc-stats'.
 
 
 v2.15.0 - 15 Feb 2021
diff --git a/lib/dpdk-unixctl.man b/lib/dpdk-unixctl.man
index 37f02d6c7..dc927c531 100644
--- a/lib/dpdk-unixctl.man
+++ b/lib/dpdk-unixctl.man
@@ -14,5 +14,7 @@ by a colon from the logging \fBlevel\fR to apply.
 Prints the statistics information about DPDK socket \fIsocket\fR.
 If called without arguments, information of all the available sockets will
 be printed.
+.IP "\fBdpdk/get-malloc-stats\fR"
+Prints the statistics information about DPDK malloc.
 .RE
 .
diff --git a/lib/dpdk.c b/lib/dpdk.c
index 5a6b2015c..c4f223f30 100644
--- a/lib/dpdk.c
+++ b/lib/dpdk.c
@@ -414,6 +414,33 @@ out:
     free(response);
 }
 
+static void
+dpdk_unixctl_get_malloc_stats(struct unixctl_conn *conn,
+                              int argc OVS_UNUSED,
+                              const char *argv[] OVS_UNUSED,
+                              void *aux OVS_UNUSED)
+{
+    size_t size;
+    FILE *stream;
+    char *response = NULL;
+
+    stream = open_memstream(&response, &size);
+    if (!stream) {
+        response = xasprintf("Unable to open memstream: %s.",
+                             ovs_strerror(errno));
+        unixctl_command_reply_error(conn, response);
+        goto out;
+    }
+
+    rte_malloc_dump_stats(stream, NULL);
+
+    fclose(stream);
+
+    unixctl_command_reply(conn, response);
+out:
+    free(response);
+}
+
 static bool
 dpdk_init__(const struct smap *ovs_other_config)
 {
@@ -585,6 +612,8 @@ dpdk_init__(const struct smap *ovs_other_config)
                              INT_MAX, dpdk_unixctl_log_set, NULL);
     unixctl_command_register("dpdk/get-socket-stats", "[socket]", 0, INT_MAX,
                              dpdk_unixctl_get_socket_stats, NULL);
+    unixctl_command_register("dpdk/get-malloc-stats", "", 0, 0,
+                             dpdk_unixctl_get_malloc_stats, NULL);
 
     /* We are called from the main thread here */
     RTE_PER_LCORE(_lcore_id) = NON_PMD_CORE_ID;
-- 
2.28.0.2311.g225365fb51

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to