X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/7141af752d0f9389c4da1c42a151c16369c70f2a..cc5c4029e1b3601786e6373815f7f8b1ec2717b1:/tools/graphicator/graphicator.c diff --git a/tools/graphicator/graphicator.c b/tools/graphicator/graphicator.c index 908cbdbb41..030f7cdfd2 100644 --- a/tools/graphicator/graphicator.c +++ b/tools/graphicator/graphicator.c @@ -26,69 +26,14 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(graphicator, "Graphicator Logging System"); -static int name_compare_links(const void *n1, const void *n2) -{ - char name1[80], name2[80]; - strcpy(name1, SD_link_get_name(*((SD_link_t *) n1))); - strcpy(name2, SD_link_get_name(*((SD_link_t *) n2))); - - return strcmp(name1, name2); -} - -static const char *node_name(xbt_node_t n) -{ - return xbt_graph_node_get_data(n); -} - -static const char *edge_name(xbt_edge_t n) -{ - return xbt_graph_edge_get_data(n); -} - -static xbt_node_t xbt_graph_search_node (xbt_graph_t graph, void *data, int (*compare_function)(const char *, const char *)) -{ - unsigned int cursor = 0; - void *tmp = NULL; - - xbt_dynar_t dynar = xbt_graph_get_nodes (graph); - xbt_dynar_foreach(dynar, cursor, tmp) { - xbt_node_t node = (xbt_node_t)tmp; - if (!compare_function (data, xbt_graph_node_get_data (node))) return node; - } - return NULL; -} - -static xbt_edge_t xbt_graph_search_edge (xbt_graph_t graph, xbt_node_t n1, xbt_node_t n2) -{ - unsigned int cursor = 0; - void *tmp = NULL; - xbt_dynar_t dynar = xbt_graph_get_edges (graph); - xbt_dynar_foreach(dynar, cursor, tmp) { - xbt_edge_t edge = (xbt_edge_t)tmp; - if (( xbt_graph_edge_get_source(edge) == n1 && - xbt_graph_edge_get_target(edge) == n2) || - ( xbt_graph_edge_get_source(edge) == n2 && - xbt_graph_edge_get_target(edge) == n1)){ - return edge; - } - } - return NULL; -} - int main(int argc, char **argv) { char *platformFile = NULL; char *graphvizFile = NULL; - unsigned int i; - char *src; - char *dst; xbt_ex_t e; - xbt_lib_cursor_t cursor,cursor_src,cursor_dst; - char * key; - char **data; - SD_init(&argc, argv); + MSG_global_init(&argc, argv); if (argc < 3){ XBT_INFO("Usage: %s ", argv[0]); @@ -98,67 +43,19 @@ int main(int argc, char **argv) graphvizFile = argv[2]; TRY { - SD_create_environment(platformFile); + MSG_create_environment(platformFile); } CATCH(e) { xbt_die("Error while loading %s: %s",platformFile,e.msg); } //creating the graph structure - xbt_graph_t graph = xbt_graph_new_graph (0, NULL); - - //adding hosts - xbt_lib_foreach(host_lib,cursor,key,data){ - if(get_network_element_type(key) == SURF_NETWORK_ELEMENT_HOST || - get_network_element_type(key) == SURF_NETWORK_ELEMENT_ROUTER ) - xbt_graph_new_node (graph, xbt_strdup(key)); + xbt_graph_t graph = TRACE_platform_graph(); + if (graph == NULL){ + XBT_INFO ("%s expects --cfg=tracing:1", argv[0]); + }else{ + xbt_graph_export_graphviz(graph, graphvizFile, &TRACE_node_name, NULL); + XBT_INFO ("Output is in file %s", graphvizFile); } - - //adding links - int totalLinks = SD_link_get_number(); - const SD_link_t *links = SD_link_get_list(); - qsort((void *) links, totalLinks, sizeof(SD_link_t), name_compare_links); - for (i = 0; i < totalLinks; i++) { - xbt_graph_new_node (graph, xbt_strdup (SD_link_get_name(links[i]))); - } - - - xbt_lib_foreach(host_lib,cursor_src,src,data){ - xbt_lib_foreach(host_lib,cursor_dst,dst,data){ - - xbt_node_t src_node = xbt_graph_search_node (graph, src, strcmp); - xbt_node_t dst_node = xbt_graph_search_node (graph, dst, strcmp); - if(get_network_element_type(src) != SURF_NETWORK_ELEMENT_AS && - get_network_element_type(dst) != SURF_NETWORK_ELEMENT_AS ){ - xbt_dynar_t route = global_routing->get_route(src,dst); - xbt_node_t previous = src_node; - for(i=0;iname); - if (strcmp(link_name, "loopback")==0 || strcmp(link_name, "__loopback__")==0) continue; - xbt_node_t link_node = xbt_graph_search_node (graph, link_name, strcmp); - if (!link_node){ - link_node = xbt_graph_new_node (graph, strdup(link_name)); - } - xbt_edge_t edge = xbt_graph_search_edge (graph, previous, link_node); - if (!edge){ - XBT_DEBUG("\%s %s", (char*)xbt_graph_node_get_data(previous), (char*)xbt_graph_node_get_data(link_node)); - xbt_graph_new_edge (graph, previous, link_node, NULL); - } - previous = link_node; - free(link_name); - } - xbt_edge_t edge = xbt_graph_search_edge (graph, previous, dst_node); - if (!edge){ - XBT_DEBUG("\%s %s", (char*)xbt_graph_node_get_data(previous), (char*)xbt_graph_node_get_data(dst_node)); - xbt_graph_new_edge (graph, previous, dst_node, NULL); - } - } - } - } - xbt_graph_export_graphviz (graph, graphvizFile, node_name, edge_name); - xbt_graph_free_graph (graph, NULL, NULL, NULL); - SD_exit(); - + MSG_clean(); return 0; }