From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 257E3A0579; Wed, 18 Mar 2020 20:05:10 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 912E31C025; Wed, 18 Mar 2020 20:03:14 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by dpdk.org (Postfix) with ESMTP id 8FF471C10C for ; Wed, 18 Mar 2020 20:03:12 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 02IJ0rl4010845; Wed, 18 Mar 2020 12:03:11 -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=gsoKE5u1oDjQCap8P+tZotrVdLlH9AieDr9Brexn7B8=; b=brklPY7P2ohnkZ2N56bmZPyVFnSk923dBFyRIemPdaXb3fZoX4/fAxS201MKSp1ZjC6d K1Q85r37KebOKmYbNGjTdyQhZ2haNuRGecV6CbJ7GcEIrqUoxi+atdizldI43wLZUGxx ju7pz2NO6bz4+LuLlSoq9uhWsLXYxHUDeIydQCCpfUflUIVKgog+wlamCVRYHB9rghzn JUgubn0nQeofDReb6nAAHuGiipKg8vgZDxXnJnk6WqkJ2b2SsrZRlmqYkMHRB8MBuzmx eGVwr29RYXxfp+9g1Bz+krvf+U4C0ppcH90UkWEtmMA0G+w2V4n1mxvKBUNCAE2cDFkz Eg== Received: from sc-exch03.marvell.com ([199.233.58.183]) by mx0a-0016f401.pphosted.com with ESMTP id 2yu8pqm3wk-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 18 Mar 2020 12:02:47 -0700 Received: from SC-EXCH01.marvell.com (10.93.176.81) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 18 Mar 2020 12:02:46 -0700 Received: from maili.marvell.com (10.93.176.43) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 18 Mar 2020 12:02:45 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id F25633F7040; Wed, 18 Mar 2020 12:02:43 -0700 (PDT) From: To: Jerin Jacob , Sunil Kumar Kori CC: , , , , Date: Thu, 19 Mar 2020 00:32:20 +0530 Message-ID: <20200318190241.3150971-12-jerinj@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200318190241.3150971-1-jerinj@marvell.com> References: <20200318190241.3150971-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.645 definitions=2020-03-18_07:2020-03-18, 2020-03-18 signatures=0 Subject: [dpdk-dev] [PATCH v1 11/32] eal/trace: implement trace save X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Jerin Jacob Implement rte_trace_save(), which will save the metadata file and trace memory snapshot to the trace directory. Signed-off-by: Jerin Jacob --- .../common/eal_common_trace_utils.c | 75 +++++++++++++++++++ lib/librte_eal/rte_eal_version.map | 1 + 2 files changed, 76 insertions(+) diff --git a/lib/librte_eal/common/eal_common_trace_utils.c b/lib/librte_eal/common/eal_common_trace_utils.c index dbeb36668..230e4ac95 100644 --- a/lib/librte_eal/common/eal_common_trace_utils.c +++ b/lib/librte_eal/common/eal_common_trace_utils.c @@ -213,3 +213,78 @@ 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); + + fclose(f); + 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); + fclose(f); + + return rc == 1 ? 0 : -EACCES; +} + +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; +} diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index cae358608..f56d1867e 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -358,6 +358,7 @@ EXPERIMENTAL { rte_trace_mode_get; rte_trace_pattern; rte_trace_regexp; + rte_trace_save; rte_trace_from_name; rte_trace_metadata_dump; rte_trace_dump; -- 2.25.1