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 5E114A00C2; Wed, 22 Apr 2020 21:05:53 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 516B21D5E7; Wed, 22 Apr 2020 21:04:54 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id 4F30A1D5A2 for ; Wed, 22 Apr 2020 21:04:37 +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 03MJ1blJ005895; Wed, 22 Apr 2020 12:04:36 -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=lRlbUUFX05Ybz/AzYdL5Pzcm1FN/GrjAyKX25VIYz/yPg0+VL8bnYMG2em9fz15s8alR DSQ8l41FlJ3ND1NVDdiP5tzFNpmr/HyE/zbD8hT7AgcsdF6tzFhyrkL95PHxfN4cn1xK iMNCqEWUqqbkVRFYszU1M1IblnY4jHhMdgKz5rUh0jfRkQ1xAZ2dvFcO3+AVD8A9wjZa 6cs2lWm/FUhO/daYVBjrfk9RhcbfumIf5f0rSqpbDZy916aRHPtzrq5+cTdydDA7Foq5 c0Huho6K7THO+m3M8giTO7F7oTP3ylrWYwY/DHhoEoabzFmkrzcESHWqacGXFZgZ3z36 cA== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0b-0016f401.pphosted.com with ESMTP id 30jd013jfw-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 22 Apr 2020 12:04:36 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 22 Apr 2020 12:04:34 -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; Wed, 22 Apr 2020 12:04:34 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id 2FE6C3F703F; Wed, 22 Apr 2020 12:04:31 -0700 (PDT) From: To: Jerin Jacob , Sunil Kumar Kori CC: , , , , Date: Thu, 23 Apr 2020 00:33:28 +0530 Message-ID: <20200422190349.3768487-12-jerinj@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200422190349.3768487-1-jerinj@marvell.com> References: <20200419100133.3232316-1-jerinj@marvell.com> <20200422190349.3768487-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-22_06:2020-04-22, 2020-04-22 signatures=0 Subject: [dpdk-dev] [PATCH v7 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 | 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