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 EF917A0577; Mon, 13 Apr 2020 17:04:48 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 504841C032; Mon, 13 Apr 2020 17:02:24 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by dpdk.org (Postfix) with ESMTP id A2A9A1C02A for ; Mon, 13 Apr 2020 17:02:20 +0200 (CEST) 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 03DExulg014657; Mon, 13 Apr 2020 08:02:19 -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=/WXVXYYpdL/TIQr18BGPLruDkXEzpC4In4jBRRh7r/4=; b=gJJ0kGqnGPbKB/zdw9pQ+EKuBG2eXJuTLGcKIzh3HNhHOAgCMUkVJdW3gqzBbrDg9wy4 VPRun/r0127Ja8p53HcIKpD/AbKwj6+wvx5UoyrD+wYc8buA0tBaTgtywLdzQrYES5Fn PnoNM75lgxJ2KsVVxz++DiX0r2mI76U1J3T2/pncEoy4klLBImb7p8Rh5crYxxK1Ei5W p4Y8PLa2L1+JRPSLLNG1HWxAAr7y+Fbw13mGPgnU8pc47Yzc4ru5bgJO4hWcvWHYVZRC gNh5PdQ2jmw6zNeKX3zSpt1tDzHM0pPBP2eCOBBUaHaxCkFVEzQWCd84EblAjodlhFYi Ng== Received: from sc-exch04.marvell.com ([199.233.58.184]) by mx0a-0016f401.pphosted.com with ESMTP id 30bb8qexw1-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 13 Apr 2020 08:02:19 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 13 Apr 2020 08:02:18 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 13 Apr 2020 08:02:18 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id 088703F7041; Mon, 13 Apr 2020 08:02:15 -0700 (PDT) From: To: Jerin Jacob , Sunil Kumar Kori CC: , , , , Date: Mon, 13 Apr 2020 20:30:55 +0530 Message-ID: <20200413150116.734047-13-jerinj@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200413150116.734047-1-jerinj@marvell.com> References: <20200403153709.3703448-1-jerinj@marvell.com> <20200413150116.734047-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-13_07:2020-04-13, 2020-04-13 signatures=0 Subject: [dpdk-dev] [PATCH v5 12/33] 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 | 80 +++++++++++++++++++ lib/librte_eal/rte_eal_version.map | 1 + 2 files changed, 81 insertions(+) diff --git a/lib/librte_eal/common/eal_common_trace_utils.c b/lib/librte_eal/common/eal_common_trace_utils.c index de8d43661..bbe099473 100644 --- a/lib/librte_eal/common/eal_common_trace_utils.c +++ b/lib/librte_eal/common/eal_common_trace_utils.c @@ -213,3 +213,83 @@ 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); + + 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; +} diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index f95f90e3f..1d478449b 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -354,6 +354,7 @@ EXPERIMENTAL { rte_trace_pattern; rte_trace_regexp; rte_trace_by_name; + rte_trace_save; rte_trace_metadata_dump; rte_trace_dump; }; -- 2.25.1