trace: add trace directory configuration parameter
authorSunil Kumar Kori <skori@marvell.com>
Wed, 22 Apr 2020 19:03:40 +0000 (00:33 +0530)
committerDavid Marchand <david.marchand@redhat.com>
Thu, 23 Apr 2020 13:39:58 +0000 (15:39 +0200)
Trace library exposes --trace-dir EAL parameter to configure
directory where traces will be generated.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Acked-by: David Marchand <david.marchand@redhat.com>
doc/guides/linux_gsg/eal_args.include.rst
lib/librte_eal/common/eal_common_options.c
lib/librte_eal/common/eal_common_trace_utils.c
lib/librte_eal/common/eal_options.h
lib/librte_eal/common/eal_trace.h

index d9e6a1d..98bfcd3 100644 (file)
@@ -152,6 +152,17 @@ Debugging options
 
     Can be specified multiple times up to 32 times.
 
+*   ``--trace-dir=<directory path>``
+
+    Specify trace directory for trace output. For example:
+
+    Configuring ``/tmp/`` as a trace output directory::
+
+        --trace-dir=/tmp
+
+    By default, trace output will created at ``home`` directory and parameter
+    must be specified once only.
+
 Other options
 ~~~~~~~~~~~~~
 
index bb6c131..f242d56 100644 (file)
@@ -69,6 +69,7 @@ eal_long_options[] = {
        {OPT_LCORES,            1, NULL, OPT_LCORES_NUM           },
        {OPT_LOG_LEVEL,         1, NULL, OPT_LOG_LEVEL_NUM        },
        {OPT_TRACE,             1, NULL, OPT_TRACE_NUM            },
+       {OPT_TRACE_DIR,         1, NULL, OPT_TRACE_DIR_NUM        },
        {OPT_MASTER_LCORE,      1, NULL, OPT_MASTER_LCORE_NUM     },
        {OPT_MBUF_POOL_OPS_NAME, 1, NULL, OPT_MBUF_POOL_OPS_NAME_NUM},
        {OPT_NO_HPET,           0, NULL, OPT_NO_HPET_NUM          },
@@ -1430,6 +1431,15 @@ eal_parse_common_option(int opt, const char *optarg,
                break;
        }
 
+       case OPT_TRACE_DIR_NUM: {
+               if (eal_trace_dir_args_save(optarg) < 0) {
+                       RTE_LOG(ERR, EAL, "invalid parameters for --"
+                               OPT_TRACE_DIR "\n");
+                       return -1;
+               }
+               break;
+       }
+
        case OPT_LCORES_NUM:
                if (eal_parse_lcores(optarg) < 0) {
                        RTE_LOG(ERR, EAL, "invalid parameter for --"
@@ -1709,6 +1719,11 @@ eal_common_usage(void)
               "                      Enable trace based on regular expression trace name.\n"
               "                      By default, the trace is disabled.\n"
               "                      User must specify this option to enable trace.\n"
+              "  --"OPT_TRACE_DIR"=<directory path>\n"
+              "                      Specify trace directory for trace output.\n"
+              "                      By default, trace output will created at\n"
+              "                      $HOME directory and parameter must be\n"
+              "                      specified once only.\n"
               "  -v                  Display version information on startup\n"
               "  -h, --help          This help\n"
               "  --"OPT_IN_MEMORY"   Operate entirely in memory. This will\n"
index 7c86a66..f5b8d4e 100644 (file)
@@ -118,6 +118,22 @@ fail:
        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)
 {
@@ -177,6 +193,37 @@ trace_args_apply(const char *arg)
        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)
 {
@@ -247,6 +294,10 @@ trace_mkdir(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 */
@@ -258,6 +309,9 @@ trace_mkdir(void)
        }
 
        rc = trace_session_name_generate(session);
+       if (rc < 0)
+               return rc;
+       rc = trace_dir_update(session);
        if (rc < 0)
                return rc;
 
index 4700410..04222e5 100644 (file)
@@ -35,6 +35,8 @@ enum {
        OPT_LOG_LEVEL_NUM,
 #define OPT_TRACE             "trace"
        OPT_TRACE_NUM,
+#define OPT_TRACE_DIR         "trace-dir"
+       OPT_TRACE_DIR_NUM,
 #define OPT_MASTER_LCORE      "master-lcore"
        OPT_MASTER_LCORE_NUM,
 #define OPT_MBUF_POOL_OPS_NAME "mbuf-pool-ops-name"
index cdbcf05..3bccb81 100644 (file)
@@ -112,5 +112,6 @@ int eal_trace_init(void);
 void eal_trace_fini(void);
 int eal_trace_args_save(const char *optarg);
 void eal_trace_args_free(void);
+int eal_trace_dir_args_save(const char *optarg);
 
 #endif /* __EAL_TRACE_H */