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 CDED9A057C; Thu, 26 Mar 2020 17:58:22 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 976491C0C5; Thu, 26 Mar 2020 17:57:07 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by dpdk.org (Postfix) with ESMTP id 713FE1C0C5 for ; Thu, 26 Mar 2020 17:57:06 +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 02QGif5A025354; Thu, 26 Mar 2020 09:57:04 -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=iskzq3X7mS8MCt8LstSEMsAu4EmzbhGpRyI5/ZWPWgM=; b=JaVcTHhX3jWcxzFTxDrYEWJ02J8/Oz8CDf9AJSe0tk59ayt5F4cWlEvR9mrQ4aqgRywK i4d6o40TburwbqMneZqvvWvgnYdva4C9NKtXE4jrS9IA9oU7fy9jMIQLDKixrmtMJgBD AWdSnqLv7xvgPXr5bptWrZUK8OAQYGSANCUHzAksb86QDs6rmsnwiI7vnDXfG4YgiqsT JfzzDv3uMxq3cCzqlk6C9DjnM7FKSzCyanDabk6voTv3pP4kEuRv4o0u6iHaql48XZSI Uibx3LhPhHybtXDkruCDMRzYvnh6aLwyaUdu5hPU85ZtEmy3HKYYvGJAOyubl0EM6aDs wg== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0a-0016f401.pphosted.com with ESMTP id 2ywg9nxgft-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Thu, 26 Mar 2020 09:57:04 -0700 Received: from SC-EXCH01.marvell.com (10.93.176.81) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 26 Mar 2020 09:57:03 -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; Thu, 26 Mar 2020 09:57:02 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id A3D7B3F7040; Thu, 26 Mar 2020 09:57:00 -0700 (PDT) From: To: Jerin Jacob , Kiran Kumar K CC: , , , , , , Date: Thu, 26 Mar 2020 22:26:25 +0530 Message-ID: <20200326165644.866053-10-jerinj@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200326165644.866053-1-jerinj@marvell.com> References: <20200318213551.3489504-1-jerinj@marvell.com> <20200326165644.866053-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-26_08:2020-03-26, 2020-03-26 signatures=0 Subject: [dpdk-dev] [PATCH v2 09/28] graph: implement Graphviz export 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 Adding API implementation support exporting the graph object to file. This will export the graph to a file in Graphviz format. It can be viewed in many viewers such as https://dreampuf.github.io/GraphvizOnline/ Signed-off-by: Jerin Jacob Signed-off-by: Kiran Kumar K Signed-off-by: Pavan Nikhilesh --- lib/librte_graph/graph.c | 54 ++++++++++++++++++++++++++ lib/librte_graph/rte_graph_version.map | 1 + 2 files changed, 55 insertions(+) diff --git a/lib/librte_graph/graph.c b/lib/librte_graph/graph.c index 7c6a7897d..e0c0b71a7 100644 --- a/lib/librte_graph/graph.c +++ b/lib/librte_graph/graph.c @@ -474,6 +474,60 @@ __rte_node_stream_alloc(struct rte_graph *graph, struct rte_node *node) node->realloc_count++; } +static int +graph_to_dot(FILE *f, struct graph *graph) +{ + const char *src_edge_color = " [color=blue]\n"; + const char *edge_color = "\n"; + struct graph_node *graph_node; + char *node_name; + rte_edge_t i; + int rc; + + rc = fprintf(f, "Digraph %s {\n\trankdir=LR;\n", graph->name); + if (rc < 0) + goto end; + + STAILQ_FOREACH(graph_node, &graph->node_list, next) { + node_name = graph_node->node->name; + for (i = 0; i < graph_node->node->nb_edges; i++) { + rc = fprintf(f, "\t\"%s\"->\"%s\"%s", node_name, + graph_node->adjacency_list[i]->node->name, + graph_node->node->flags & RTE_NODE_SOURCE_F + ? src_edge_color + : edge_color); + if (rc < 0) + goto end; + } + } + rc = fprintf(f, "}\n"); + if (rc < 0) + goto end; + + return 0; +end: + rte_errno = EBADF; + return -rte_errno; +} + +rte_graph_t +rte_graph_export(const char *name, FILE *f) +{ + rte_graph_t rc = RTE_GRAPH_ID_INVALID; + struct graph *graph; + + STAILQ_FOREACH(graph, &graph_list, next) { + if (strncmp(graph->name, name, RTE_GRAPH_NAMESIZE) == 0) { + rc = graph_to_dot(f, graph); + goto end; + } + } + rte_errno = ENOENT; +end: + return rc; +} + + rte_graph_t rte_graph_max_count(void) { diff --git a/lib/librte_graph/rte_graph_version.map b/lib/librte_graph/rte_graph_version.map index 5a2b13293..2797be044 100644 --- a/lib/librte_graph/rte_graph_version.map +++ b/lib/librte_graph/rte_graph_version.map @@ -6,6 +6,7 @@ EXPERIMENTAL { rte_graph_create; rte_graph_destroy; + rte_graph_export; rte_graph_from_name; rte_graph_id_to_name; rte_graph_lookup; -- 2.25.1