From patchwork Wed Mar 20 17:11:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Jarry X-Patchwork-Id: 138577 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9068E43D06; Wed, 20 Mar 2024 18:11:48 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2C5B041132; Wed, 20 Mar 2024 18:11:48 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 4938C40A6F for ; Wed, 20 Mar 2024 18:11:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710954705; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=p5BPTBiD7ilIgN0mPN7zYtNmkQVWHz3wxlRdIVOSYrM=; b=XIyc5BU4h6BoMn3+uJHRpDrpU1WJn6oWhgXfng/Kr2QKB7eLoX/K8lAILfIMKaL3V6yomy Fjdc+MfxafuwZzhZ7fx9ZF1NF8j2HJiWgXi8A3OMtGT8K48q9C9xGt0vn4LZwnDU+tZ2mz WpIRu3RosUArN2AAG3LN1mfr/sbcWls= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-575-RK8ftjZBPYeO3lzhdwo1qg-1; Wed, 20 Mar 2024 13:11:40 -0400 X-MC-Unique: RK8ftjZBPYeO3lzhdwo1qg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1BF683CBD506; Wed, 20 Mar 2024 17:11:39 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.208.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id C9024492BD4; Wed, 20 Mar 2024 17:11:37 +0000 (UTC) From: Robin Jarry To: dev@dpdk.org, Jerin Jacob , Kiran Kumar K , Nithin Dabilpuram , Zhirun Yan Subject: [PATCH] graph: enhance export to graphviz Date: Wed, 20 Mar 2024 18:11:21 +0100 Message-ID: <20240320171120.255142-2-rjarry@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org * 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 Acked-by: Kiran Kumar Kokkilagadda --- 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; }