From: Lucas Schnorr Date: Sat, 9 Apr 2011 14:42:31 +0000 (+0200) Subject: graphicator re-implemented X-Git-Tag: v3.6_beta2~59^2~9 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/cc5c4029e1b3601786e6373815f7f8b1ec2717b1?hp=1063eb59082966d2a5703148a678ccefac34c304 graphicator re-implemented - it now considers exactly the same route traversal of the tracing system - faster graphviz file generation - new tracing interface function: TRACE_platform_graph --- diff --git a/include/instr/instr.h b/include/instr/instr.h index 156a684932..9551dc7633 100644 --- a/include/instr/instr.h +++ b/include/instr/instr.h @@ -12,6 +12,7 @@ #ifdef HAVE_TRACING #include "xbt.h" +#include "xbt/graph.h" #include "msg/msg.h" #include "simdag/simdag.h" @@ -23,6 +24,8 @@ void TRACE_msg_set_process_category(m_process_t process, const char *category, c XBT_PUBLIC(void) TRACE_user_host_variable(double time, const char *variable, 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_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 49e0517e17..33c122b491 100644 --- a/src/instr/instr_interface.c +++ b/src/instr/instr_interface.c @@ -145,4 +145,19 @@ void TRACE_user_host_variable(double time, const char *variable, } } +const char *TRACE_node_name (xbt_node_t node) +{ + void *data = xbt_graph_node_get_data(node); + char *str = (char*)data; + return str; +} + +xbt_graph_t TRACE_platform_graph (void) +{ + if (!TRACE_is_active()) + return NULL; + + return instr_routing_platform_graph (); +} + #endif /* HAVE_TRACING */ diff --git a/src/instr/instr_private.h b/src/instr/instr_private.h index 67d87933cb..8eefa976c3 100644 --- a/src/instr/instr_private.h +++ b/src/instr/instr_private.h @@ -230,6 +230,7 @@ void instr_new_user_variable_type (const char *new_typename, const char *color); void instr_new_user_link_variable_type (const char *new_typename, const char *color); 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); #endif /* HAVE_TRACING */ diff --git a/src/instr/instr_routing.c b/src/instr/instr_routing.c index 20ff7eace4..9ac2f97035 100644 --- a/src/instr/instr_routing.c +++ b/src/instr/instr_routing.c @@ -369,5 +369,111 @@ int instr_platform_traced () return platform_created; } +#define GRAPHICATOR_SUPPORT_FUNCTIONS + + +static xbt_node_t new_xbt_graph_node (xbt_graph_t graph, const char *name, xbt_dict_t nodes) +{ + xbt_node_t ret = xbt_dict_get_or_null (nodes, name); + if (ret) return ret; + + ret = xbt_graph_new_node (graph, xbt_strdup(name)); + xbt_dict_set (nodes, name, ret, NULL); + return ret; +} + +static xbt_edge_t new_xbt_graph_edge (xbt_graph_t graph, xbt_node_t s, xbt_node_t d, xbt_dict_t edges) +{ + xbt_edge_t ret; + char *name; + + const char *sn = TRACE_node_name (s); + const char *dn = TRACE_node_name (d); + + name = bprintf ("%s%s", sn, dn); + ret = xbt_dict_get_or_null (edges, name); + if (ret) return ret; + free (name); + name = bprintf ("%s%s", dn, sn); + ret = xbt_dict_get_or_null (edges, name); + if (ret) return ret; + + ret = xbt_graph_new_edge(graph, s, d, NULL); + xbt_dict_set (edges, name, ret, NULL); + return ret; +} + +static void recursiveXBTGraphExtraction (xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges, + routing_component_t rc, container_t container) +{ + if (xbt_dict_length (rc->routing_sons)){ + xbt_dict_cursor_t cursor = NULL; + routing_component_t rc_son; + char *child_name; + //bottom-up recursion + xbt_dict_foreach(rc->routing_sons, cursor, child_name, rc_son) { + container_t child_container = xbt_dict_get (container->children, rc_son->name); + recursiveXBTGraphExtraction (graph, nodes, edges, rc_son, child_container); + } + } + + //let's get routes + xbt_dict_cursor_t cursor1 = NULL, cursor2 = NULL; + container_t child1, child2; + const char *child1_name, *child2_name; + xbt_dict_foreach(container->children, cursor1, child1_name, child1) { + if (child1->kind == INSTR_LINK) continue; + xbt_dict_foreach(container->children, cursor2, child2_name, child2) { + if (child2->kind == INSTR_LINK) continue; + + if ((child1->kind == INSTR_HOST || child1->kind == INSTR_ROUTER) && + (child2->kind == INSTR_HOST || child2->kind == INSTR_ROUTER) && + strcmp (child1_name, child2_name) != 0){ + + xbt_dynar_t route = global_routing->get_route (child1_name, child2_name); + unsigned int cpt; + void *link; + xbt_node_t current, previous = new_xbt_graph_node(graph, child1_name, nodes); + xbt_dynar_foreach (route, cpt, link) { + char *link_name = ((link_CM02_t)link)->lmm_resource.generic_resource.name; + current = new_xbt_graph_node(graph, link_name, nodes); + new_xbt_graph_edge (graph, previous, current, edges); + //previous -> current + previous = current; + } + current = new_xbt_graph_node(graph, child2_name, nodes); + new_xbt_graph_edge (graph, previous, current, edges); + + }else if (child1->kind == INSTR_AS && + child2->kind == INSTR_AS && + strcmp(child1_name, child2_name) != 0){ + + route_extended_t route = rc->get_route (rc, child1_name, child2_name); + unsigned int cpt; + void *link; + xbt_node_t current, previous = new_xbt_graph_node(graph, route->src_gateway, nodes); + xbt_dynar_foreach (route->generic_route.link_list, cpt, link) { + char *link_name = ((link_CM02_t)link)->lmm_resource.generic_resource.name; + current = new_xbt_graph_node(graph, link_name, nodes); + //previous -> current + previous = current; + } + current = new_xbt_graph_node(graph, route->dst_gateway, nodes); + new_xbt_graph_edge (graph, previous, current, edges); + } + } + } + +} + +xbt_graph_t instr_routing_platform_graph (void) +{ + xbt_graph_t ret = xbt_graph_new_graph (0, NULL); + xbt_dict_t nodes = xbt_dict_new (); + xbt_dict_t edges = xbt_dict_new (); + recursiveXBTGraphExtraction (ret, nodes, edges, global_routing->root, getRootContainer()); + return ret; +} + #endif /* HAVE_TRACING */ 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; }