trace: implement trace save
authorJerin Jacob <jerinj@marvell.com>
Wed, 22 Apr 2020 19:03:28 +0000 (00:33 +0530)
committerDavid Marchand <david.marchand@redhat.com>
Thu, 23 Apr 2020 13:39:29 +0000 (15:39 +0200)
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>
Acked-by: David Marchand <david.marchand@redhat.com>
lib/librte_eal/common/eal_common_trace_utils.c
lib/librte_eal/rte_eal_version.map

index 503d0ab..98026b5 100644 (file)
@@ -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;
+}
index 7bda170..b4b3a92 100644 (file)
@@ -354,4 +354,5 @@ EXPERIMENTAL {
        rte_trace_point_is_enabled;
        rte_trace_point_lookup;
        rte_trace_regexp;
+       rte_trace_save;
 };