From e55e72933ce9336c43e103a0f03de3c21269da85 Mon Sep 17 00:00:00 2001 From: Lucas Schnorr Date: Mon, 11 Apr 2011 22:41:46 +0200 Subject: [PATCH] export to graphviz function in the tracing way, we need node names --- include/instr/instr.h | 1 + src/instr/instr_interface.c | 5 +++++ src/instr/instr_private.h | 2 ++ src/instr/instr_routing.c | 38 +++++++++++++++++++++++++++++++++ tools/graphicator/graphicator.c | 2 +- 5 files changed, 47 insertions(+), 1 deletion(-) diff --git a/include/instr/instr.h b/include/instr/instr.h index 9551dc7633..250d263751 100644 --- a/include/instr/instr.h +++ b/include/instr/instr.h @@ -26,6 +26,7 @@ XBT_PUBLIC(void) TRACE_user_host_variable(double time, double value, const char *what); XBT_PUBLIC(const char *) TRACE_node_name (xbt_node_t node); XBT_PUBLIC(xbt_graph_t) TRACE_platform_graph (void); +XBT_PUBLIC(void) TRACE_platform_graph_export_graphviz (xbt_graph_t g, const char *filename); XBT_PUBLIC(void) TRACE_user_link_variable(double time, const char *resource, const char *variable, double value, const char *what); diff --git a/src/instr/instr_interface.c b/src/instr/instr_interface.c index 33c122b491..f409086d80 100644 --- a/src/instr/instr_interface.c +++ b/src/instr/instr_interface.c @@ -160,4 +160,9 @@ xbt_graph_t TRACE_platform_graph (void) return instr_routing_platform_graph (); } +void TRACE_platform_graph_export_graphviz (xbt_graph_t g, const char *filename) +{ + instr_routing_platform_graph_export_graphviz (g, filename); +} + #endif /* HAVE_TRACING */ diff --git a/src/instr/instr_private.h b/src/instr/instr_private.h index 2c6442bd93..6290b45509 100644 --- a/src/instr/instr_private.h +++ b/src/instr/instr_private.h @@ -17,6 +17,7 @@ #include "msg/msg.h" #include "simdag/private.h" #include "simix/private.h" +#include "xbt/graph_private.h" typedef enum { TYPE_VARIABLE, @@ -232,6 +233,7 @@ void instr_new_user_link_variable_type (const char *new_typename, const char *c void instr_new_user_host_variable_type (const char *new_typename, const char *color); int instr_platform_traced (void); xbt_graph_t instr_routing_platform_graph (void); +void instr_routing_platform_graph_export_graphviz (xbt_graph_t g, const char *filename); #endif /* HAVE_TRACING */ diff --git a/src/instr/instr_routing.c b/src/instr/instr_routing.c index 9ac2f97035..5613849568 100644 --- a/src/instr/instr_routing.c +++ b/src/instr/instr_routing.c @@ -9,6 +9,7 @@ #ifdef HAVE_TRACING #include "surf/surf_private.h" #include "surf/network_private.h" +#include "xbt/graph.h" XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_routing, instr, "Tracing platform hierarchy"); @@ -475,5 +476,42 @@ xbt_graph_t instr_routing_platform_graph (void) return ret; } +void instr_routing_platform_graph_export_graphviz (xbt_graph_t g, const char *filename) +{ + unsigned int cursor = 0; + xbt_node_t node = NULL; + xbt_edge_t edge = NULL; + FILE *file = NULL; + + file = fopen(filename, "w"); + xbt_assert(file, "Failed to open %s \n", filename); + + if (g->directed) + fprintf(file, "digraph test {\n"); + else + fprintf(file, "graph test {\n"); + + fprintf(file, " graph [overlap=scale]\n"); + + fprintf(file, " node [shape=box, style=filled]\n"); + fprintf(file, + " node [width=.3, height=.3, style=filled, color=skyblue]\n\n"); + + xbt_dynar_foreach(g->nodes, cursor, node) { + fprintf(file, " \"%s\";\n", TRACE_node_name(node)); + } + xbt_dynar_foreach(g->edges, cursor, edge) { + const char *src_s = TRACE_node_name (edge->src); + const char *dst_s = TRACE_node_name (edge->dst); + if (g->directed) + fprintf(file, " \"%s\" -> \"%s\";\n", src_s, dst_s); + else + fprintf(file, " \"%s\" -- \"%s\";\n", src_s, dst_s); + } + fprintf(file, "}\n"); + fclose(file); + +} + #endif /* HAVE_TRACING */ diff --git a/tools/graphicator/graphicator.c b/tools/graphicator/graphicator.c index 030f7cdfd2..571f278ec3 100644 --- a/tools/graphicator/graphicator.c +++ b/tools/graphicator/graphicator.c @@ -53,7 +53,7 @@ int main(int argc, char **argv) if (graph == NULL){ XBT_INFO ("%s expects --cfg=tracing:1", argv[0]); }else{ - xbt_graph_export_graphviz(graph, graphvizFile, &TRACE_node_name, NULL); + TRACE_platform_graph_export_graphviz (graph, graphvizFile); XBT_INFO ("Output is in file %s", graphvizFile); } MSG_clean(); -- 2.20.1