From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from dpdk.org (dpdk.org [92.243.14.124])
	by inbox.dpdk.org (Postfix) with ESMTP id D9FD9A0561;
	Sun, 19 Apr 2020 12:08:16 +0200 (CEST)
Received: from [92.243.14.124] (localhost [127.0.0.1])
	by dpdk.org (Postfix) with ESMTP id 801ED1D636;
	Sun, 19 Apr 2020 12:03:23 +0200 (CEST)
Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com
 [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id 244841D62C
 for <dev@dpdk.org>; Sun, 19 Apr 2020 12:03:16 +0200 (CEST)
Received: from pps.filterd (m0045851.ppops.net [127.0.0.1])
 by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id
 03JA0tuu020047; Sun, 19 Apr 2020 03:03:16 -0700
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com;
 h=from : to : cc :
 subject : date : message-id : in-reply-to : references : mime-version :
 content-transfer-encoding : content-type; s=pfpt0818;
 bh=AyHMjlD8zTGjXyxJjQ06173Udf+9ZenEizEdGJXlZqg=;
 b=ZSzsEHCkm0qodKSpJsDePIJwVXBdeW55qGKRXmoSNZhiOX2244Pj0vcftY7gaQjbcTCJ
 qZfk4/HUhYg7VIRXwxz5G+dpGnJyEdJJpH9O42qy03vyI3C62XRnh4sQDJaHbW/cmf+T
 O/BEFnymyvKQA7VkZB7AB/2y+3YoaTk3vnMwOZ0UhVmAtc8iBxnGo9glXS+2GScIpmQ7
 /dSKyQAG6Juol64Nw8NrGb+gkQZ3HkenPcuR2E/eRF/kH71Wj/3hxQ0S2s8jncS9Qv5p
 4JPgVlblEwRp+aexFSi/i4sfX23RwqHstdTGy6gsPLTpAU742mYbpgSg6mNpm6sLWhb+ tQ== 
Received: from sc-exch02.marvell.com ([199.233.58.182])
 by mx0b-0016f401.pphosted.com with ESMTP id 30g12njxen-1
 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT);
 Sun, 19 Apr 2020 03:03:16 -0700
Received: from DC5-EXCH02.marvell.com (10.69.176.39) by SC-EXCH02.marvell.com
 (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2;
 Sun, 19 Apr 2020 03:03:14 -0700
Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com
 (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.2;
 Sun, 19 Apr 2020 03:03:13 -0700
Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com
 (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.2 via Frontend
 Transport; Sun, 19 Apr 2020 03:03:13 -0700
Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14])
 by maili.marvell.com (Postfix) with ESMTP id AAC723F703F;
 Sun, 19 Apr 2020 03:03:10 -0700 (PDT)
From: <jerinj@marvell.com>
To: John McNamara <john.mcnamara@intel.com>, Marko Kovacevic
 <marko.kovacevic@intel.com>, Jerin Jacob <jerinj@marvell.com>, "Sunil Kumar
 Kori" <skori@marvell.com>
CC: <dev@dpdk.org>, <thomas@monjalon.net>, <bruce.richardson@intel.com>,
 <david.marchand@redhat.com>, <mattias.ronnblom@ericsson.com>
Date: Sun, 19 Apr 2020 15:31:26 +0530
Message-ID: <20200419100133.3232316-27-jerinj@marvell.com>
X-Mailer: git-send-email 2.25.1
In-Reply-To: <20200419100133.3232316-1-jerinj@marvell.com>
References: <20200413150116.734047-1-jerinj@marvell.com>
 <20200419100133.3232316-1-jerinj@marvell.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.676
 definitions=2020-04-19_02:2020-04-17,
 2020-04-19 signatures=0
Subject: [dpdk-dev] [PATCH v6 26/33] eal/trace: add trace mode configuration
	parameter
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>

From: Sunil Kumar Kori <skori@marvell.com>

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>
---
 doc/guides/linux_gsg/eal_args.include.rst     | 12 ++++++
 lib/librte_eal/common/eal_common_options.c    | 17 ++++++++
 .../common/eal_common_trace_utils.c           | 40 +++++++++++++++++++
 lib/librte_eal/common/eal_options.h           |  2 +
 lib/librte_eal/common/eal_trace.h             |  1 +
 5 files changed, 72 insertions(+)

diff --git a/doc/guides/linux_gsg/eal_args.include.rst b/doc/guides/linux_gsg/eal_args.include.rst
index b921c83b8..361c7cf67 100644
--- a/doc/guides/linux_gsg/eal_args.include.rst
+++ b/doc/guides/linux_gsg/eal_args.include.rst
@@ -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
 ~~~~~~~~~~~~~
 
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 32b163a81..7e3a7df9c 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -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"
diff --git a/lib/librte_eal/common/eal_common_trace_utils.c b/lib/librte_eal/common/eal_common_trace_utils.c
index b4ac79c95..5b2906677 100644
--- a/lib/librte_eal/common/eal_common_trace_utils.c
+++ b/lib/librte_eal/common/eal_common_trace_utils.c
@@ -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)
 {
diff --git a/lib/librte_eal/common/eal_options.h b/lib/librte_eal/common/eal_options.h
index 3e9a54f3a..90ead1b7c 100644
--- a/lib/librte_eal/common/eal_options.h
+++ b/lib/librte_eal/common/eal_options.h
@@ -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"
diff --git a/lib/librte_eal/common/eal_trace.h b/lib/librte_eal/common/eal_trace.h
index 2fd73c5d5..dc3eca6eb 100644
--- a/lib/librte_eal/common/eal_trace.h
+++ b/lib/librte_eal/common/eal_trace.h
@@ -116,6 +116,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 */
-- 
2.25.1