return -rte_errno;
}
+static int
+trace_dir_update(const char *str)
+{
+ struct trace *trace = trace_obj_get();
+ int rc, remaining;
+
+ remaining = sizeof(trace->dir) - trace->dir_offset;
+ rc = rte_strscpy(&trace->dir[0] + trace->dir_offset, str, remaining);
+ if (rc < 0)
+ goto fail;
+
+ trace->dir_offset += rc;
+fail:
+ return rc;
+}
+
+int
+eal_trace_args_save(const char *optarg)
+{
+ struct trace *trace = trace_obj_get();
+ char *trace_args;
+ uint8_t nb_args;
+
+ nb_args = trace->args.nb_args;
+
+ if (nb_args >= TRACE_MAX_ARGS) {
+ trace_err("ignoring trace %s as limit exceeds", optarg);
+ return 0;
+ }
+
+ trace_args = calloc(1, (strlen(optarg) + 1));
+ if (trace_args == NULL) {
+ trace_err("fail to allocate memory for %s", optarg);
+ return -ENOMEM;
+ }
+
+ memcpy(trace_args, optarg, strlen(optarg));
+ trace->args.args[nb_args++] = trace_args;
+ trace->args.nb_args = nb_args;
+ return 0;
+}
+
+void
+eal_trace_args_free(void)
+{
+ struct trace *trace = trace_obj_get();
+ int i;
+
+ for (i = 0; i < trace->args.nb_args; i++) {
+ if (trace->args.args[i]) {
+ free((void *)trace->args.args[i]);
+ trace->args.args[i] = NULL;
+ }
+ }
+}
+
+int
+trace_args_apply(const char *arg)
+{
+ char *str;
+
+ str = strdup(arg);
+ if (str == NULL)
+ return -1;
+
+ if (rte_trace_regexp(str, true) < 0) {
+ trace_err("cannot enable trace for %s", str);
+ free(str);
+ return -1;
+ }
+
+ free(str);
+ return 0;
+}
+
+int
+eal_trace_bufsz_args_save(char const *optarg)
+{
+ struct trace *trace = trace_obj_get();
+ uint64_t bufsz;
+
+ if (optarg == NULL) {
+ trace_err("no optarg is passed");
+ return -EINVAL;
+ }
+
+ bufsz = rte_str_to_size(optarg);
+ if (bufsz == 0) {
+ trace_err("buffer size cannot be zero");
+ return -EINVAL;
+ }
+
+ trace->buff_len = bufsz;
+ return 0;
+}
+
+void
+trace_bufsz_args_apply(void)
+{
+ struct trace *trace = trace_obj_get();
+
+ if (trace->buff_len == 0)
+ trace->buff_len = 1024 * 1024; /* 1MB */
+}
+
+int
+eal_trace_mode_args_save(const char *optarg)
+{
+ struct trace *trace = trace_obj_get();
+ size_t len = strlen(optarg);
+ unsigned long tmp;
+ char *pattern;
+
+ if (optarg == NULL) {
+ trace_err("no optarg is passed");
+ return -EINVAL;
+ }
+
+ if (len == 0) {
+ trace_err("value is not provided with option");
+ return -EINVAL;
+ }
+
+ pattern = (char *)calloc(1, len + 2);
+ if (pattern == NULL) {
+ trace_err("fail to allocate memory");
+ return -ENOMEM;
+ }
+
+ sprintf(pattern, "%s*", optarg);
+
+ if (fnmatch(pattern, "overwrite", 0) == 0)
+ tmp = RTE_TRACE_MODE_OVERWRITE;
+ else if (fnmatch(pattern, "discard", 0) == 0)
+ tmp = RTE_TRACE_MODE_DISCARD;
+ else {
+ free(pattern);
+ return -EINVAL;
+ }
+
+ trace->mode = tmp;
+ free(pattern);
+ return 0;
+}
+
+int
+eal_trace_dir_args_save(char const *optarg)
+{
+ struct trace *trace = trace_obj_get();
+ uint32_t size = sizeof(trace->dir);
+ char *dir_path = NULL;
+ int rc;
+
+ if (optarg == NULL) {
+ trace_err("no optarg is passed");
+ return -EINVAL;
+ }
+
+ if (strlen(optarg) >= size) {
+ trace_err("input string is too big");
+ return -ENAMETOOLONG;
+ }
+
+ dir_path = (char *)calloc(1, size);
+ if (dir_path == NULL) {
+ trace_err("fail to allocate memory");
+ return -ENOMEM;
+ }
+
+ sprintf(dir_path, "%s/", optarg);
+ rc = trace_dir_update(dir_path);
+
+ free(dir_path);
+ return rc;
+}
+
int
trace_epoch_time_save(void)
{
return rc;
}
+ rc = trace_dir_update(dir_path);
+ free(dir_path);
+ if (rc < 0)
+ return rc;
}
/* Create the path if it t exist, no "mkdir -p" available here */
}
rc = trace_session_name_generate(session);
+ if (rc < 0)
+ return rc;
+ rc = trace_dir_update(session);
if (rc < 0)
return rc;
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;
+}