trace: add trace mode configuration parameter
authorSunil Kumar Kori <skori@marvell.com>
Wed, 22 Apr 2020 19:03:42 +0000 (00:33 +0530)
committerDavid Marchand <david.marchand@redhat.com>
Thu, 23 Apr 2020 13:40:01 +0000 (15:40 +0200)
Trace library exposes --trace-mode eal parameter to configure
event record mode when ring buffers are full.

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 b921c83..361c7cf 100644 (file)
@@ -176,6 +176,18 @@ Debugging options
     By default, size of trace output file is ``1MB`` and parameter
     must be specified once only.
 
+*   ``--trace-mode=<o[verwrite] | d[iscard] >``
+
+    Specify the mode of update of trace output file. Either update on a file
+    can be wrapped or discarded when file size reaches its maximum limit.
+    For example:
+
+    To ``discard`` update on trace output file::
+
+        --trace-mode=d or --trace-mode=discard
+
+    Default mode is ``overwrite`` and parameter must be specified once only.
+
 Other options
 ~~~~~~~~~~~~~
 
index 32b163a..7e3a7df 100644 (file)
@@ -71,6 +71,7 @@ eal_long_options[] = {
        {OPT_TRACE,             1, NULL, OPT_TRACE_NUM            },
        {OPT_TRACE_DIR,         1, NULL, OPT_TRACE_DIR_NUM        },
        {OPT_TRACE_BUF_SIZE,    1, NULL, OPT_TRACE_BUF_SIZE_NUM   },
+       {OPT_TRACE_MODE,        1, NULL, OPT_TRACE_MODE_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          },
@@ -1450,6 +1451,15 @@ eal_parse_common_option(int opt, const char *optarg,
                break;
        }
 
+       case OPT_TRACE_MODE_NUM: {
+               if (eal_trace_mode_args_save(optarg) < 0) {
+                       RTE_LOG(ERR, EAL, "invalid parameters for --"
+                               OPT_TRACE_MODE "\n");
+                       return -1;
+               }
+               break;
+       }
+
        case OPT_LCORES_NUM:
                if (eal_parse_lcores(optarg) < 0) {
                        RTE_LOG(ERR, EAL, "invalid parameter for --"
@@ -1741,6 +1751,13 @@ eal_common_usage(void)
               "                      'KBytes' and 'MBytes' respectively.\n"
               "                      Default is 1MB and parameter must be\n"
               "                      specified once only.\n"
+              "  --"OPT_TRACE_MODE"=<o[verwrite] | d[iscard]>\n"
+              "                      Specify the mode of update of trace\n"
+              "                      output file. Either update on a file can\n"
+              "                      be wrapped or discarded when file size\n"
+              "                      reaches its maximum limit.\n"
+              "                      Default mode is 'overwrite' and parameter\n"
+              "                      must be 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 4fce605..fce8892 100644 (file)
@@ -223,6 +223,46 @@ trace_bufsz_args_apply(void)
                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)
 {
index 3e9a54f..90ead1b 100644 (file)
@@ -39,6 +39,8 @@ enum {
        OPT_TRACE_DIR_NUM,
 #define OPT_TRACE_BUF_SIZE    "trace-bufsz"
        OPT_TRACE_BUF_SIZE_NUM,
+#define OPT_TRACE_MODE        "trace-mode"
+       OPT_TRACE_MODE_NUM,
 #define OPT_MASTER_LCORE      "master-lcore"
        OPT_MASTER_LCORE_NUM,
 #define OPT_MBUF_POOL_OPS_NAME "mbuf-pool-ops-name"
index 787c7fe..f53ccc0 100644 (file)
@@ -114,6 +114,7 @@ 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);
+int eal_trace_mode_args_save(const char *optarg);
 int eal_trace_bufsz_args_save(const char *optarg);
 
 #endif /* __EAL_TRACE_H */