[v4,12/33] eal/trace: implement trace save
diff mbox series

Message ID 20200403153709.3703448-13-jerinj@marvell.com
State Superseded, archived
Delegated to: David Marchand
Headers show
Series
  • DPDK Trace support
Related show

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Jerin Jacob Kollanukkaran April 3, 2020, 3:36 p.m. UTC
From: Jerin Jacob <jerinj@marvell.com>

Implement rte_trace_save(), which will save the metadata
file and trace memory snapshot to the trace directory.

Signed-off-by: Jerin Jacob <jerinj@marvell.com>
---
 .../common/eal_common_trace_utils.c           | 80 +++++++++++++++++++
 lib/librte_eal/rte_eal_version.map            |  1 +
 2 files changed, 81 insertions(+)

Patch
diff mbox series

diff --git a/lib/librte_eal/common/eal_common_trace_utils.c b/lib/librte_eal/common/eal_common_trace_utils.c
index b288a72f0..64e7a7cfa 100644
--- a/lib/librte_eal/common/eal_common_trace_utils.c
+++ b/lib/librte_eal/common/eal_common_trace_utils.c
@@ -213,3 +213,83 @@  trace_mkdir(void)
 	return 0;
 }
 
+static int
+trace_meta_save(struct trace *trace)
+{
+	char file_name[PATH_MAX];
+	FILE *f;
+	int rc;
+
+	rc = snprintf(file_name, PATH_MAX, "%s/metadata", trace->dir);
+	if (rc < 0)
+		return rc;
+
+	f = fopen(file_name, "w");
+	if (f == NULL)
+		return -errno;
+
+	rc = rte_trace_metadata_dump(f);
+
+	if (fclose(f))
+		rc = -errno;
+
+	return rc;
+}
+
+
+static inline int
+trace_file_sz(struct __rte_trace_header *hdr)
+{
+	return sizeof(struct __rte_trace_stream_header) + hdr->offset;
+}
+
+static int
+trace_mem_save(struct trace *trace, struct __rte_trace_header *hdr,
+	       uint32_t cnt)
+{
+	char file_name[PATH_MAX];
+	FILE *f;
+	int rc;
+
+	rc = snprintf(file_name, PATH_MAX, "%s/channel0_%d", trace->dir, cnt);
+	if (rc < 0)
+		return rc;
+
+	f = fopen(file_name, "w");
+	if (f == NULL)
+		return -errno;
+
+	rc = fwrite(&hdr->stream_header, trace_file_sz(hdr), 1, f);
+	rc = (rc == 1) ?  0 : -EACCES;
+
+	if (fclose(f))
+		rc = -errno;
+
+	return rc;
+}
+
+int
+rte_trace_save(void)
+{
+	struct trace *trace = trace_obj_get();
+	struct __rte_trace_header *header;
+	uint32_t count;
+	int rc = 0;
+
+	if (trace->nb_trace_mem_list == 0)
+		return rc;
+
+	rc = trace_meta_save(trace);
+	if (rc)
+		return rc;
+
+	rte_spinlock_lock(&trace->lock);
+	for (count = 0; count < trace->nb_trace_mem_list; count++) {
+		header = trace->lcore_meta[count].mem;
+		rc =  trace_mem_save(trace, header, count);
+		if (rc)
+			break;
+	}
+	rte_spinlock_unlock(&trace->lock);
+	return rc;
+}
diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map
index 82f4461e2..f841cc7d6 100644
--- a/lib/librte_eal/rte_eal_version.map
+++ b/lib/librte_eal/rte_eal_version.map
@@ -360,6 +360,7 @@  EXPERIMENTAL {
 	rte_trace_pattern;
 	rte_trace_regexp;
 	rte_trace_by_name;
+	rte_trace_save;
 	rte_trace_metadata_dump;
 	rte_trace_dump;
 };