DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] eal: add telemetry callbacks for memory info
@ 2021-09-15  9:53 Harman Kalra
  2021-09-20 15:56 ` Bruce Richardson
  2021-10-08 12:44 ` [dpdk-dev] [PATCH v2] " Harman Kalra
  0 siblings, 2 replies; 10+ messages in thread
From: Harman Kalra @ 2021-09-15  9:53 UTC (permalink / raw)
  To: dev, bruce.richardson, ciara.power, Anatoly Burakov; +Cc: Harman Kalra

Registering new telemetry callbacks to dump named (memzones)
and unnamed (malloc) memory information to a file provided as
an argument.

Example:
Connecting to /var/run/dpdk/rte/dpdk_telemetry.v2
{"version": "DPDK 21.08.0", "pid": 34075, "max_output_len": 16384}
Connected to application: "dpdk-testpmd"
--> /eal/malloc_dump,/tmp/malloc_dump
{"/eal/malloc_dump": {"Malloc elements file: ": "/tmp/malloc_dump"}}
-->
--> /eal/malloc_info,/tmp/info
{"/eal/malloc_info": {"Malloc stats file: ": "/tmp/info"}}
-->
-->
--> /eal/memzone_dump,/tmp/memzone_info
{"/eal/memzone_dump": {"Memzones count: ": 11, \
"Memzones info file: ": "/tmp/memzone_info"}}

Signed-off-by: Harman Kalra <hkalra@marvell.com>
---
 lib/eal/common/eal_common_memory.c | 78 ++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)

diff --git a/lib/eal/common/eal_common_memory.c b/lib/eal/common/eal_common_memory.c
index f83b75092e..592b3453b6 100644
--- a/lib/eal/common/eal_common_memory.c
+++ b/lib/eal/common/eal_common_memory.c
@@ -20,6 +20,8 @@
 #include <rte_eal_paging.h>
 #include <rte_errno.h>
 #include <rte_log.h>
+#include <rte_string_fns.h>
+#include <rte_telemetry.h>
 
 #include "eal_memalloc.h"
 #include "eal_private.h"
@@ -38,6 +40,7 @@
 
 #define MEMSEG_LIST_FMT "memseg-%" PRIu64 "k-%i-%i"
 
+static int count;
 static void *next_baseaddr;
 static uint64_t system_page_sz;
 
@@ -1102,3 +1105,78 @@ rte_eal_memory_init(void)
 	rte_mcfg_mem_read_unlock();
 	return -1;
 }
+
+#define EAL_MEMZONE_DUMP_REQ	"/eal/memzone_dump"
+#define EAL_MALLOC_INFO_REQ	"/eal/malloc_info"
+#define EAL_MALLOC_DUMP_REQ	"/eal/malloc_dump"
+
+static void
+memzone_walk_clb(const struct rte_memzone *mz __rte_unused,
+		 void *arg __rte_unused)
+{
+	count++;
+}
+
+/* Callback handler for telemetry library to dump named and unnamed memory
+ * information.
+ */
+static int
+handle_eal_mem_info_request(const char *cmd, const char *params,
+		      struct rte_tel_data *d)
+{
+	char filename[PATH_MAX];
+	FILE *fp;
+
+	if (params == NULL || strlen(params) == 0)
+		return -1;
+
+	rte_strscpy(filename, params, PATH_MAX);
+
+	fp = fopen(filename, "w+");
+	if (fp == NULL) {
+		RTE_LOG(ERR, EAL, "cannot open %s", filename);
+		return -1;
+	}
+
+	rte_tel_data_start_dict(d);
+	/* Dumping memzone info. */
+	if (strcmp(cmd, EAL_MEMZONE_DUMP_REQ) == 0) {
+		count = 0;
+		/* Callback to count memzones */
+		rte_memzone_walk(memzone_walk_clb, NULL);
+		rte_tel_data_add_dict_int(d, "Memzones count: ", count);
+		rte_tel_data_add_dict_string(d, "Memzones info file: ",
+					     filename);
+		rte_memzone_dump(fp);
+	}
+
+	/* Dumping malloc statistics */
+	if (strcmp(cmd, EAL_MALLOC_INFO_REQ) == 0) {
+		rte_tel_data_add_dict_string(d, "Malloc stats file: ",
+					     filename);
+		rte_malloc_dump_stats(fp, NULL);
+	}
+
+	/* Dumping malloc elements info */
+	if (strcmp(cmd, EAL_MALLOC_DUMP_REQ) == 0) {
+		rte_tel_data_add_dict_string(d, "Malloc elements file: ",
+					     filename);
+		rte_malloc_dump_heaps(fp);
+	}
+
+	fclose(fp);
+	return 0;
+}
+
+RTE_INIT(memory_telemetry)
+{
+	rte_telemetry_register_cmd(
+			EAL_MEMZONE_DUMP_REQ, handle_eal_mem_info_request,
+			"Dumps memzones info to file. Parameters: file name");
+	rte_telemetry_register_cmd(
+			EAL_MALLOC_INFO_REQ, handle_eal_mem_info_request,
+			"Dumps malloc info to file. Parameters: file name");
+	rte_telemetry_register_cmd(
+			EAL_MALLOC_DUMP_REQ, handle_eal_mem_info_request,
+			"Dumps malloc elems to file. Parameters: file name");
+}
-- 
2.18.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-10-25 18:55 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-15  9:53 [dpdk-dev] [PATCH] eal: add telemetry callbacks for memory info Harman Kalra
2021-09-20 15:56 ` Bruce Richardson
2021-09-21  9:05   ` [dpdk-dev] [EXT] " Harman Kalra
2021-09-27 16:37     ` Bruce Richardson
2021-10-07 11:01       ` Harman Kalra
2021-10-08 12:44 ` [dpdk-dev] [PATCH v2] " Harman Kalra
2021-10-14 17:17   ` Harman Kalra
2021-10-15  8:28     ` Power, Ciara
2021-10-19 15:04       ` Bruce Richardson
2021-10-25 18:55         ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).