[v1,11/32] eal/trace: implement trace save
diff mbox series

Message ID 20200318190241.3150971-12-jerinj@marvell.com
State Superseded, archived
Delegated to: Thomas Monjalon
Headers show
Series
  • DPDK Trace support
Related show

Checks

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

Commit Message

Jerin Jacob Kollanukkaran March 18, 2020, 7:02 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           | 75 +++++++++++++++++++
 lib/librte_eal/rte_eal_version.map            |  1 +
 2 files changed, 76 insertions(+)

Comments

Mattias Rönnblom March 19, 2020, 7:07 p.m. UTC | #1
On 2020-03-18 20:02, jerinj@marvell.com wrote:
> 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           | 75 +++++++++++++++++++
>   lib/librte_eal/rte_eal_version.map            |  1 +
>   2 files changed, 76 insertions(+)
>
> diff --git a/lib/librte_eal/common/eal_common_trace_utils.c b/lib/librte_eal/common/eal_common_trace_utils.c
> index dbeb36668..230e4ac95 100644
> --- a/lib/librte_eal/common/eal_common_trace_utils.c
> +++ b/lib/librte_eal/common/eal_common_trace_utils.c
> @@ -213,3 +213,78 @@ 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);
> +
> +	fclose(f);
Check fclose() return code.
> +	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);
> +	fclose(f);
Again, check return code.
> +
> +	return rc == 1 ?  0 : -EACCES;
> +}
> +
> +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 cae358608..f56d1867e 100644
> --- a/lib/librte_eal/rte_eal_version.map
> +++ b/lib/librte_eal/rte_eal_version.map
> @@ -358,6 +358,7 @@ EXPERIMENTAL {
>   	rte_trace_mode_get;
>   	rte_trace_pattern;
>   	rte_trace_regexp;
> +	rte_trace_save;
>   	rte_trace_from_name;
>   	rte_trace_metadata_dump;
>   	rte_trace_dump;
Jerin Jacob March 23, 2020, 9:26 a.m. UTC | #2
On Fri, Mar 20, 2020 at 12:37 AM Mattias Rönnblom
<mattias.ronnblom@ericsson.com> wrote:
>
> On 2020-03-18 20:02, jerinj@marvell.com wrote:
> > From: Jerin Jacob <jerinj@marvell.com>

> > +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);
> > +
> > +     fclose(f);
> Check fclose() return code.

Ack. Will fix it v2.



> > +     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);
> > +     fclose(f);
> Again, check return code.

Ack. Will fix it v2.

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 dbeb36668..230e4ac95 100644
--- a/lib/librte_eal/common/eal_common_trace_utils.c
+++ b/lib/librte_eal/common/eal_common_trace_utils.c
@@ -213,3 +213,78 @@  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);
+
+	fclose(f);
+	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);
+	fclose(f);
+
+	return rc == 1 ?  0 : -EACCES;
+}
+
+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 cae358608..f56d1867e 100644
--- a/lib/librte_eal/rte_eal_version.map
+++ b/lib/librte_eal/rte_eal_version.map
@@ -358,6 +358,7 @@  EXPERIMENTAL {
 	rte_trace_mode_get;
 	rte_trace_pattern;
 	rte_trace_regexp;
+	rte_trace_save;
 	rte_trace_from_name;
 	rte_trace_metadata_dump;
 	rte_trace_dump;