DPDK patches and discussions
 help / color / mirror / Atom feed
From: Robin Jarry <rjarry@redhat.com>
To: dev@dpdk.org, Jerin Jacob <jerinj@marvell.com>,
	Kiran Kumar K <kirankumark@marvell.com>,
	Nithin Dabilpuram <ndabilpuram@marvell.com>,
	Zhirun Yan <yanzhirun_163@163.com>
Subject: [PATCH] graph: enhance export to graphviz
Date: Wed, 20 Mar 2024 18:11:21 +0100	[thread overview]
Message-ID: <20240320171120.255142-2-rjarry@redhat.com> (raw)

* Quote graph name to avoid parsing errors when it contains a dash.
* Use fixed margin and smaller font for a more compact layout.
* Use sans-serif font, the default is times new roman which is not the
  best choice for a packet processing generated graph.
* Force bold blue border and arrows for source nodes.
* Force dark orange borders for sink nodes (nodes without next nodes).

Link: https://f.jarry.cc/rte-graph-dot/before.svg
Link: https://f.jarry.cc/rte-graph-dot/after.svg
Signed-off-by: Robin Jarry <rjarry@redhat.com>
---
 lib/graph/graph.c | 32 +++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/lib/graph/graph.c b/lib/graph/graph.c
index 26f0968a978d..147bc6c685c5 100644
--- a/lib/graph/graph.c
+++ b/lib/graph/graph.c
@@ -674,25 +674,43 @@ __rte_node_stream_alloc_size(struct rte_graph *graph, struct rte_node *node,
 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);
+	rc = fprintf(f, "digraph \"%s\" {\n\trankdir=LR;\n", graph->name);
+	if (rc < 0)
+		goto end;
+
+	rc = fprintf(f, "\tnode [margin=0.02 fontsize=11 fontname=sans];\n");
 	if (rc < 0)
 		goto end;
 
 	STAILQ_FOREACH(graph_node, &graph->node_list, next) {
+		const char *attrs = "";
 		node_name = graph_node->node->name;
+
+		rc = fprintf(f, "\t\"%s\"", node_name);
+		if (rc < 0)
+			goto end;
+		if (graph_node->node->flags & RTE_NODE_SOURCE_F) {
+			attrs = " [color=blue style=bold]";
+			rc = fprintf(f, "%s", attrs);
+			if (rc < 0)
+				goto end;
+		} else if (graph_node->node->nb_edges == 0) {
+			rc = fprintf(f, " [color=darkorange]");
+			if (rc < 0)
+				goto end;
+		}
+		rc = fprintf(f, ";\n");
+		if (rc < 0)
+			goto end;
 		for (i = 0; i < graph_node->node->nb_edges; i++) {
-			rc = fprintf(f, "\t\"%s\"->\"%s\"%s", node_name,
+			rc = fprintf(f, "\t\"%s\" -> \"%s\"%s;\n", node_name,
 				     graph_node->adjacency_list[i]->node->name,
-				     graph_node->node->flags & RTE_NODE_SOURCE_F
-					     ? src_edge_color
-					     : edge_color);
+				     attrs);
 			if (rc < 0)
 				goto end;
 		}
-- 
2.44.0


             reply	other threads:[~2024-03-20 17:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-20 17:11 Robin Jarry [this message]
2024-03-22  8:02 ` [EXTERNAL] " Kiran Kumar Kokkilagadda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240320171120.255142-2-rjarry@redhat.com \
    --to=rjarry@redhat.com \
    --cc=dev@dpdk.org \
    --cc=jerinj@marvell.com \
    --cc=kirankumark@marvell.com \
    --cc=ndabilpuram@marvell.com \
    --cc=yanzhirun_163@163.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).