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 A6530A0561; Sun, 19 Apr 2020 12:05:18 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8A1F01D5CA; Sun, 19 Apr 2020 12:02:34 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id F0B3B1D5BB for ; Sun, 19 Apr 2020 12:02:26 +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 03JA18sx020150; Sun, 19 Apr 2020 03:02:25 -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=YEov/QC6OTR5tjgWP9qOOnQ/vG+Wh/Bg3e0ICElOj/w=; b=GRr6w3VALgCW20n/ujBHQwydpuFVGTO9cKNtmQ0FOWxb+6tMsVPUnxyHGM94lQm7CGYN usxlhelpa32HkuGyw0KZEch4MVYoTxM8GR8AWvMjIDgPiICZ3/a4ZFBxalAL1ZBNgzde g30GP2JNCrTiRi2Jpb/CflmlApstOnSSZoSM+9f/cx5XYadjoRWhCO6kk+fY76Zke9bk yJCojWt/EuEZxCHMA01lUDxm0G3CYzgQOKjG7v0SAqpngyHnDECy1FZFttctnhxEkMw8 4vVkvGhjVQf0p0Waf2a1u2OTw2cZlRBCaDGP4mWo8aNGsOHYkIVc6N+agJ9aioCxEjWj xw== Received: from sc-exch04.marvell.com ([199.233.58.184]) by mx0b-0016f401.pphosted.com with ESMTP id 30g12njxb2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sun, 19 Apr 2020 03:02:25 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sun, 19 Apr 2020 03:02:23 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sun, 19 Apr 2020 03:02:23 -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; Sun, 19 Apr 2020 03:02:22 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id CAD213F703F; Sun, 19 Apr 2020 03:02:20 -0700 (PDT) From: To: Jerin Jacob , Sunil Kumar Kori CC: , , , , Date: Sun, 19 Apr 2020 15:31:12 +0530 Message-ID: <20200419100133.3232316-13-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 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 7bda1704c..b4b3a92e5 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -354,4 +354,5 @@ EXPERIMENTAL { rte_trace_point_is_enabled; rte_trace_point_lookup; rte_trace_regexp; + rte_trace_save; }; -- 2.25.1