Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid into...
[simgrid.git] / src / instr / instr_routing.c
1 /* Copyright (c) 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5   * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "instr/instr_private.h"
8
9 #ifdef HAVE_TRACING
10 #include "surf/surf_private.h"
11 #include "surf/network_private.h"
12 #include "xbt/graph.h"
13
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_routing, instr, "Tracing platform hierarchy");
15
16 extern xbt_dict_t defined_types; /* from instr_interface.c */
17
18 static int platform_created = 0;            /* indicate whether the platform file has been traced */
19 static xbt_dynar_t currentContainer = NULL; /* push and pop, used only in creation */
20
21 static const char *instr_node_name (xbt_node_t node)
22 {
23   void *data = xbt_graph_node_get_data(node);
24   char *str = (char*)data;
25   return str;
26 }
27
28
29 static container_t lowestCommonAncestor (container_t a1, container_t a2)
30 {
31   //this is only an optimization (since most of a1 and a2 share the same parent)
32   if (a1->father == a2->father) return a1->father;
33
34   //create an array with all ancestors of a1
35   xbt_dynar_t ancestors_a1 = xbt_dynar_new(sizeof(container_t), NULL);
36   container_t p;
37   p = a1->father;
38   while (p){
39     xbt_dynar_push_as (ancestors_a1, container_t, p);
40     p = p->father;
41   }
42
43   //create an array with all ancestors of a2
44   xbt_dynar_t ancestors_a2 = xbt_dynar_new(sizeof(container_t), NULL);
45   p = a2->father;
46   while (p){
47     xbt_dynar_push_as (ancestors_a2, container_t, p);
48     p = p->father;
49   }
50
51   //find the lowest ancestor
52   p = NULL;
53   int i = xbt_dynar_length (ancestors_a1) - 1;
54   int j = xbt_dynar_length (ancestors_a2) - 1;
55   while (i >= 0 && j >= 0){
56     container_t a1p = *(container_t*)xbt_dynar_get_ptr (ancestors_a1, i);
57     container_t a2p = *(container_t*)xbt_dynar_get_ptr (ancestors_a2, j);
58     if (a1p == a2p){
59       p = a1p;
60     }else{
61       break;
62     }
63     i--;
64     j--;
65   }
66   xbt_dynar_free (&ancestors_a1);
67   xbt_dynar_free (&ancestors_a2);
68   return p;
69 }
70
71 static void linkContainers (container_t src, container_t dst, xbt_dict_t filter)
72 {
73   //ignore loopback
74   if (strcmp (src->name, "__loopback__") == 0 || strcmp (dst->name, "__loopback__") == 0){
75     XBT_DEBUG ("  linkContainers: ignoring loopback link");
76     return;
77   }
78
79   //find common father
80   container_t father = lowestCommonAncestor (src, dst);
81   if (!father){
82     xbt_die ("common father unknown, this is a tracing problem");
83   }
84
85   if (filter != NULL){
86     //check if we already register this pair (we only need one direction)
87     char aux1[INSTR_DEFAULT_STR_SIZE], aux2[INSTR_DEFAULT_STR_SIZE];
88     snprintf (aux1, INSTR_DEFAULT_STR_SIZE, "%s%s", src->name, dst->name);
89     snprintf (aux2, INSTR_DEFAULT_STR_SIZE, "%s%s", dst->name, src->name);
90     if (xbt_dict_get_or_null (filter, aux1)){
91       XBT_DEBUG ("  linkContainers: already registered %s <-> %s (1)", src->name, dst->name);
92       return;
93     }
94     if (xbt_dict_get_or_null (filter, aux2)){
95       XBT_DEBUG ("  linkContainers: already registered %s <-> %s (2)", dst->name, src->name);
96       return;
97     }
98
99     //ok, not found, register it
100     xbt_dict_set (filter, aux1, xbt_strdup ("1"), NULL);
101     xbt_dict_set (filter, aux2, xbt_strdup ("1"), NULL);
102   }
103
104   //declare type
105   char link_typename[INSTR_DEFAULT_STR_SIZE];
106   snprintf (link_typename, INSTR_DEFAULT_STR_SIZE, "%s-%s%s-%s%s",
107             father->type->name,
108             src->type->name, src->type->id,
109             dst->type->name, dst->type->id);
110   type_t link_type = PJ_type_get_or_null (link_typename, father->type);
111   if (link_type == NULL){
112     link_type = PJ_type_link_new (link_typename, father->type, src->type, dst->type);
113   }
114
115   //register EDGE types for triva configuration
116   xbt_dict_set (trivaEdgeTypes, link_type->name, xbt_strdup("1"), NULL);
117
118   //create the link
119   static long long counter = 0;
120   char key[INSTR_DEFAULT_STR_SIZE];
121   snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", counter++);
122   new_pajeStartLink(SIMIX_get_clock(), father, link_type, src, "G", key);
123   new_pajeEndLink(SIMIX_get_clock(), father, link_type, dst, "G", key);
124
125   XBT_DEBUG ("  linkContainers %s <-> %s", src->name, dst->name);
126 }
127
128 static int graph_extraction_filter_out (container_t c1, container_t c2)
129 {
130   if (c1->kind == INSTR_LINK ||
131       c1->kind == INSTR_SMPI ||
132       c1->kind == INSTR_MSG_PROCESS ||
133       c1->kind == INSTR_MSG_TASK ||
134       (c2 && strcmp (c1->name, c2->name) == 0))
135     return 1;
136   else
137     return 0;
138 }
139
140 static void recursiveGraphExtraction (AS_t rc, container_t container, xbt_dict_t filter)
141 {
142   XBT_DEBUG ("Graph extraction for routing_component = %s", rc->name);
143   if (!xbt_dict_is_empty(rc->routing_sons)){
144     xbt_dict_cursor_t cursor = NULL;
145     AS_t rc_son;
146     char *child_name;
147     //bottom-up recursion
148     xbt_dict_foreach(rc->routing_sons, cursor, child_name, rc_son) {
149       container_t child_container = xbt_dict_get (container->children, rc_son->name);
150       recursiveGraphExtraction (rc_son, child_container, filter);
151     }
152   }
153
154   //let's get routes
155   xbt_dict_cursor_t cursor1 = NULL, cursor2 = NULL;
156   container_t child1, child2;
157   const char *child1_name, *child2_name;
158   xbt_dict_foreach(container->children, cursor1, child1_name, child1) {
159     //if child1 is not a link, a smpi node, a msg process, a msg vm or a msg task
160     if (child1->kind == INSTR_LINK || child1->kind == INSTR_SMPI || child1->kind == INSTR_MSG_PROCESS || child1->kind == INSTR_MSG_VM || child1->kind == INSTR_MSG_TASK) continue;
161
162     xbt_dict_foreach(container->children, cursor2, child2_name, child2) {
163       //if child2 is not a link, a smpi node, a msg process, a msg vm or a msg task
164       if (child2->kind == INSTR_LINK || child2->kind == INSTR_SMPI || child2->kind == INSTR_MSG_PROCESS || child2->kind == INSTR_MSG_VM || child2->kind == INSTR_MSG_TASK) continue;
165
166       //if child1 is not child2
167       if (strcmp (child1_name, child2_name) == 0) continue;
168
169       if (graph_extraction_filter_out (child1, NULL)) continue;
170     xbt_dict_foreach(container->children, cursor2, child2_name, child2) {
171       if (graph_extraction_filter_out (child2, child1)) continue;
172       XBT_DEBUG ("get_route from %s to %s", child1_name, child2_name);
173
174       //get the route
175       sg_platf_route_cbarg_t route = xbt_new0(s_sg_platf_route_cbarg_t,1);
176       route->link_list = xbt_dynar_new(sizeof(sg_routing_link_t),NULL);
177       rc->get_route_and_latency(rc, child1->net_elm, child2->net_elm,
178                                 route, NULL);
179
180       //user might want to extract a graph using routes with only one link
181       //see --cfg=tracing/onelink_only:1 or --help-tracing for details
182       if (TRACE_onelink_only() && xbt_dynar_length (route->link_list) > 1){
183         generic_free_route(route);
184         continue;
185       }
186
187       //traverse the route connecting the containers
188       unsigned int cpt;
189       void *link;
190       container_t current, previous;
191       if (route->gw_src){
192         previous = PJ_container_get(route->gw_src->name);
193       }else{
194         previous = child1;
195       }
196
197       xbt_dynar_foreach (route->link_list, cpt, link) {
198         //FIXME (TODO): Should have a cleaner way to get the link name
199         char *link_name = ((link_CM02_t)link)->lmm_resource.generic_resource.name;
200         current = PJ_container_get(link_name);
201         linkContainers(previous, current, filter);
202         previous = current;
203       }
204       if (route->gw_dst){
205         current = PJ_container_get(route->gw_dst->name);
206       }else{
207         current = child2;
208       }
209       linkContainers(previous, current, filter);
210       generic_free_route(route);
211     }
212   }
213 }
214
215 /*
216  * Callbacks
217  */
218 static void instr_routing_parse_start_AS (sg_platf_AS_cbarg_t AS)
219 {
220   const char*id = AS->id;
221
222   if (PJ_container_get_root() == NULL){
223     PJ_container_alloc ();
224     PJ_type_alloc();
225     container_t root = PJ_container_new (id, INSTR_AS, NULL);
226     PJ_container_set_root (root);
227
228     if (TRACE_smpi_is_enabled()) {
229       if (!TRACE_smpi_is_grouped()){
230         type_t mpi = PJ_type_get_or_null ("MPI", root->type);
231         if (mpi == NULL){
232           mpi = PJ_type_container_new("MPI", root->type);
233           PJ_type_state_new ("MPI_STATE", mpi);
234           PJ_type_link_new ("MPI_LINK", PJ_type_get_root(), mpi, mpi);
235         }
236       }
237     }
238
239     if (TRACE_needs_platform()){
240       currentContainer = xbt_dynar_new (sizeof(container_t), NULL);
241       xbt_dynar_push (currentContainer, &root);
242     }
243     return;
244   }
245
246   if (TRACE_needs_platform()){
247     container_t father = *(container_t*)xbt_dynar_get_ptr(currentContainer, xbt_dynar_length(currentContainer)-1);
248     container_t new = PJ_container_new (id, INSTR_AS, father);
249     xbt_dynar_push (currentContainer, &new);
250   }
251 }
252
253 static void instr_routing_parse_end_AS ()
254 {
255   if (TRACE_needs_platform()){
256     xbt_dynar_pop_ptr (currentContainer);
257   }
258 }
259
260 static void instr_routing_parse_start_link (sg_platf_link_cbarg_t link)
261 {
262   container_t father = *(container_t*)xbt_dynar_get_ptr(currentContainer, xbt_dynar_length(currentContainer)-1);
263
264   double bandwidth_value = link->bandwidth;
265   double latency_value = link->latency;
266   xbt_dynar_t links_to_create = xbt_dynar_new (sizeof(char*), &xbt_free_ref);
267
268   if (link->policy == SURF_LINK_FULLDUPLEX){
269     char *up = bprintf("%s_UP", link->id);
270     char *down = bprintf("%s_DOWN", link->id);
271     xbt_dynar_push_as (links_to_create, char*, xbt_strdup(up));
272     xbt_dynar_push_as (links_to_create, char*, xbt_strdup(down));
273     free (up);
274     free (down);
275   }else{
276     xbt_dynar_push_as (links_to_create, char*, strdup(link->id));
277   }
278
279   char *link_name = NULL;
280   unsigned int i;
281   xbt_dynar_foreach (links_to_create, i, link_name){
282
283     container_t new = PJ_container_new (link_name, INSTR_LINK, father);
284
285     if (TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()){
286       type_t bandwidth = PJ_type_get_or_null ("bandwidth", new->type);
287       if (bandwidth == NULL){
288         bandwidth = PJ_type_variable_new ("bandwidth", NULL, new->type);
289       }
290       type_t latency = PJ_type_get_or_null ("latency", new->type);
291       if (latency == NULL){
292         latency = PJ_type_variable_new ("latency", NULL, new->type);
293       }
294       new_pajeSetVariable (0, new, bandwidth, bandwidth_value);
295       new_pajeSetVariable (0, new, latency, latency_value);
296     }
297     if (TRACE_uncategorized()){
298       type_t bandwidth_used = PJ_type_get_or_null ("bandwidth_used", new->type);
299       if (bandwidth_used == NULL){
300         bandwidth_used = PJ_type_variable_new ("bandwidth_used", "0.5 0.5 0.5", new->type);
301       }
302     }
303   }
304
305   xbt_dynar_free (&links_to_create);
306 }
307
308 static void instr_routing_parse_start_host (sg_platf_host_cbarg_t host)
309 {
310   container_t father = *(container_t*)xbt_dynar_get_ptr(currentContainer, xbt_dynar_length(currentContainer)-1);
311   container_t new = PJ_container_new (host->id, INSTR_HOST, father);
312
313   if (TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()) {
314     type_t power = PJ_type_get_or_null ("power", new->type);
315     if (power == NULL){
316       power = PJ_type_variable_new ("power", NULL, new->type);
317     }
318     new_pajeSetVariable (0, new, power, host->power_peak);
319   }
320   if (TRACE_uncategorized()){
321     type_t power_used = PJ_type_get_or_null ("power_used", new->type);
322     if (power_used == NULL){
323       power_used = PJ_type_variable_new ("power_used", "0.5 0.5 0.5", new->type);
324     }
325   }
326
327   if (TRACE_smpi_is_enabled() && TRACE_smpi_is_grouped()){
328     type_t mpi = PJ_type_get_or_null ("MPI", new->type);
329     if (mpi == NULL){
330       mpi = PJ_type_container_new("MPI", new->type);
331       PJ_type_state_new ("MPI_STATE", mpi);
332       PJ_type_link_new ("MPI_LINK", PJ_type_get_root(), mpi, mpi);
333     }
334   }
335
336   if (TRACE_msg_process_is_enabled()) {
337     type_t msg_process = PJ_type_get_or_null ("MSG_PROCESS", new->type);
338     if (msg_process == NULL){
339       msg_process = PJ_type_container_new("MSG_PROCESS", new->type);
340       type_t state = PJ_type_state_new ("MSG_PROCESS_STATE", msg_process);
341       PJ_value_new ("suspend", "1 0 1", state);
342       PJ_value_new ("sleep", "1 1 0", state);
343       PJ_value_new ("receive", "1 0 0", state);
344       PJ_value_new ("send", "0 0 1", state);
345       PJ_value_new ("task_execute", "0 1 1", state);
346       PJ_type_link_new ("MSG_PROCESS_LINK", PJ_type_get_root(), msg_process, msg_process);
347       PJ_type_link_new ("MSG_PROCESS_TASK_LINK", PJ_type_get_root(), msg_process, msg_process);
348     }
349   }
350
351   if (TRACE_msg_vm_is_enabled()) {
352     type_t msg_vm = PJ_type_get_or_null ("MSG_VM", new->type);
353     if (msg_vm == NULL){
354       msg_vm = PJ_type_container_new("MSG_VM", new->type);
355       type_t state = PJ_type_state_new ("MSG_VM_STATE", msg_vm);
356       PJ_value_new ("suspend", "1 0 1", state);
357       PJ_value_new ("sleep", "1 1 0", state);
358       PJ_value_new ("receive", "1 0 0", state);
359       PJ_value_new ("send", "0 0 1", state);
360       PJ_value_new ("task_execute", "0 1 1", state);
361       PJ_type_link_new ("MSG_VM_LINK", PJ_type_get_root(), msg_vm, msg_vm);
362       PJ_type_link_new ("MSG_VM_PROCESS_LINK", PJ_type_get_root(), msg_vm, msg_vm);
363     }
364   }
365
366 }
367
368 static void instr_routing_parse_start_router (sg_platf_router_cbarg_t router)
369 {
370   container_t father = *(container_t*)xbt_dynar_get_ptr(currentContainer, xbt_dynar_length(currentContainer)-1);
371   PJ_container_new (router->id, INSTR_ROUTER, father);
372 }
373
374 static void instr_routing_parse_end_platform ()
375 {
376   xbt_dynar_free(&currentContainer);
377   currentContainer = NULL;
378   xbt_dict_t filter = xbt_dict_new_homogeneous(xbt_free);
379   XBT_DEBUG ("Starting graph extraction.");
380   recursiveGraphExtraction (routing_platf->root, PJ_container_get_root(), filter);
381   XBT_DEBUG ("Graph extraction finished.");
382   xbt_dict_free(&filter);
383   platform_created = 1;
384   TRACE_paje_dump_buffer(1);
385 }
386
387 void instr_routing_define_callbacks ()
388 {
389   if (!TRACE_is_enabled()) return;
390   //always need the call backs to ASes (we need only the root AS),
391   //to create the rootContainer and the rootType properly
392   sg_platf_AS_begin_add_cb(instr_routing_parse_start_AS);
393   sg_platf_AS_end_add_cb(instr_routing_parse_end_AS);
394   if (!TRACE_needs_platform()) return;
395   sg_platf_link_add_cb(instr_routing_parse_start_link);
396   sg_platf_host_add_cb(instr_routing_parse_start_host);
397   sg_platf_router_add_cb(instr_routing_parse_start_router);
398
399   sg_platf_postparse_add_cb(instr_routing_parse_end_platform);
400 }
401
402 /*
403  * user categories support
404  */
405 static void recursiveNewVariableType (const char *new_typename, const char *color, type_t root)
406 {
407   if (!strcmp (root->name, "HOST")){
408     char tnstr[INSTR_DEFAULT_STR_SIZE];
409     snprintf (tnstr, INSTR_DEFAULT_STR_SIZE, "p%s", new_typename);
410     PJ_type_variable_new (tnstr, color, root);
411   }
412   if (!strcmp (root->name, "MSG_VM")){
413     char tnstr[INSTR_DEFAULT_STR_SIZE];
414     snprintf (tnstr, INSTR_DEFAULT_STR_SIZE, "p%s", new_typename);
415     PJ_type_variable_new (tnstr, color, root);
416   }
417  if (!strcmp (root->name, "LINK")){
418     char tnstr[INSTR_DEFAULT_STR_SIZE];
419     snprintf (tnstr, INSTR_DEFAULT_STR_SIZE, "b%s", new_typename);
420     PJ_type_variable_new (tnstr, color, root);
421   }
422   xbt_dict_cursor_t cursor = NULL;
423   type_t child_type;
424   char *name;
425   xbt_dict_foreach(root->children, cursor, name, child_type) {
426     recursiveNewVariableType (new_typename, color, child_type);
427   }
428 }
429
430 void instr_new_variable_type (const char *new_typename, const char *color)
431 {
432   recursiveNewVariableType (new_typename, color, PJ_type_get_root());
433 }
434
435 static void recursiveNewUserVariableType (const char *father_type, const char *new_typename, const char *color, type_t root)
436 {
437   if (!strcmp (root->name, father_type)){
438     PJ_type_variable_new (new_typename, color, root);
439   }
440   xbt_dict_cursor_t cursor = NULL;
441   type_t child_type;
442   char *name;
443   xbt_dict_foreach(root->children, cursor, name, child_type) {
444     recursiveNewUserVariableType (father_type, new_typename, color, child_type);
445   }
446 }
447
448 void instr_new_user_variable_type  (const char *father_type, const char *new_typename, const char *color)
449 {
450   recursiveNewUserVariableType (father_type, new_typename, color, PJ_type_get_root());
451 }
452
453 static void recursiveNewUserStateType (const char *father_type, const char *new_typename, type_t root)
454 {
455   if (!strcmp (root->name, father_type)){
456     PJ_type_state_new (new_typename, root);
457   }
458   xbt_dict_cursor_t cursor = NULL;
459   type_t child_type;
460   char *name;
461   xbt_dict_foreach(root->children, cursor, name, child_type) {
462     recursiveNewUserStateType (father_type, new_typename, child_type);
463   }
464 }
465
466 void instr_new_user_state_type (const char *father_type, const char *new_typename)
467 {
468   recursiveNewUserStateType (father_type, new_typename, PJ_type_get_root());
469 }
470
471 static void recursiveNewValueForUserStateType (const char *typename, const char *value, const char *color, type_t root)
472 {
473   if (!strcmp (root->name, typename)){
474     PJ_value_new (value, color, root);
475   }
476   xbt_dict_cursor_t cursor = NULL;
477   type_t child_type;
478   char *name;
479   xbt_dict_foreach(root->children, cursor, name, child_type) {
480     recursiveNewValueForUserStateType (typename, value, color, child_type);
481   }
482 }
483
484 void instr_new_value_for_user_state_type (const char *typename, const char *value, const char *color)
485 {
486   recursiveNewValueForUserStateType (typename, value, color, PJ_type_get_root());
487 }
488
489 int instr_platform_traced ()
490 {
491   return platform_created;
492 }
493
494 #define GRAPHICATOR_SUPPORT_FUNCTIONS
495
496
497 static xbt_node_t new_xbt_graph_node (xbt_graph_t graph, const char *name, xbt_dict_t nodes)
498 {
499   xbt_node_t ret = xbt_dict_get_or_null (nodes, name);
500   if (ret) return ret;
501
502   ret = xbt_graph_new_node (graph, xbt_strdup(name));
503   xbt_dict_set (nodes, name, ret, NULL);
504   return ret;
505 }
506
507 static xbt_edge_t new_xbt_graph_edge (xbt_graph_t graph, xbt_node_t s, xbt_node_t d, xbt_dict_t edges)
508 {
509   xbt_edge_t ret;
510
511   const char *sn = instr_node_name (s);
512   const char *dn = instr_node_name (d);
513   int len = strlen(sn)+strlen(dn)+1;
514   char *name = (char*)malloc(len * sizeof(char));
515
516
517   snprintf (name, len, "%s%s", sn, dn);
518   ret = xbt_dict_get_or_null (edges, name);
519   if (ret == NULL){
520     snprintf (name, len, "%s%s", dn, sn);
521     ret = xbt_dict_get_or_null (edges, name);
522   }
523
524   if (ret == NULL){
525     ret = xbt_graph_new_edge(graph, s, d, NULL);
526     xbt_dict_set (edges, name, ret, NULL);
527   }
528   free (name);
529   return ret;
530 }
531
532 static void recursiveXBTGraphExtraction (xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges,
533     AS_t rc, container_t container)
534 {
535   if (!xbt_dict_is_empty(rc->routing_sons)){
536     xbt_dict_cursor_t cursor = NULL;
537     AS_t rc_son;
538     char *child_name;
539     //bottom-up recursion
540     xbt_dict_foreach(rc->routing_sons, cursor, child_name, rc_son) {
541       container_t child_container = xbt_dict_get (container->children, rc_son->name);
542       recursiveXBTGraphExtraction (graph, nodes, edges, rc_son, child_container);
543     }
544   }
545
546   //let's get routes
547   xbt_dict_cursor_t cursor1 = NULL, cursor2 = NULL;
548   container_t child1, child2;
549   const char *child1_name, *child2_name;
550   xbt_dict_foreach(container->children, cursor1, child1_name, child1) {
551     //if child1 is not a link, a smpi node, a msg process, a msg vm or a msg task
552     if (child1->kind == INSTR_LINK || child1->kind == INSTR_SMPI || child1->kind == INSTR_MSG_PROCESS || child1->kind == INSTR_MSG_VM || child1->kind == INSTR_MSG_TASK) continue;
553
554     xbt_dict_foreach(container->children, cursor2, child2_name, child2) {
555       //if child2 is not a link, a smpi node, a msg process or a msg task
556       if (child2->kind == INSTR_LINK || child2->kind == INSTR_SMPI || child2->kind == INSTR_MSG_PROCESS || child2->kind == INSTR_MSG_VM || child2->kind == INSTR_MSG_TASK) continue;
557
558       //if child1 is not child2
559       if (strcmp (child1_name, child2_name) == 0) continue;
560
561       //get the route
562       sg_platf_route_cbarg_t route = xbt_new0(s_sg_platf_route_cbarg_t,1);
563       route->link_list = xbt_dynar_new(sizeof(sg_routing_link_t),NULL);
564       rc->get_route_and_latency(rc, child1->net_elm, child2->net_elm,
565                                 route, NULL);
566
567       //user might want to extract a graph using routes with only one link
568       //see --cfg=tracing/onelink_only:1 or --help-tracing for details
569       if (TRACE_onelink_only() && xbt_dynar_length (route->link_list) > 1) continue;
570
571       //traverse the route connecting the containers
572       unsigned int cpt;
573       void *link;
574       xbt_node_t current, previous;
575       if (route->gw_src){
576         previous = new_xbt_graph_node(graph, route->gw_src->name, nodes);
577       }else{
578         previous = new_xbt_graph_node(graph, child1_name, nodes);
579       }
580
581       xbt_dynar_foreach (route->link_list, cpt, link) {
582         char *link_name = ((link_CM02_t)link)->lmm_resource.generic_resource.name;
583         current = new_xbt_graph_node(graph, link_name, nodes);
584         new_xbt_graph_edge (graph, previous, current, edges);
585         //previous -> current
586         previous = current;
587       }
588       if (route->gw_dst){
589         current = new_xbt_graph_node(graph, route->gw_dst->name, nodes);
590       }else{
591         current = new_xbt_graph_node(graph, child2_name, nodes);
592       }
593       new_xbt_graph_edge (graph, previous, current, edges);
594       generic_free_route(route);
595     }
596   }
597
598 }
599
600 xbt_graph_t instr_routing_platform_graph (void)
601 {
602   xbt_graph_t ret = xbt_graph_new_graph (0, NULL);
603   xbt_dict_t nodes = xbt_dict_new_homogeneous(NULL);
604   xbt_dict_t edges = xbt_dict_new_homogeneous(NULL);
605   recursiveXBTGraphExtraction (ret, nodes, edges, routing_platf->root, PJ_container_get_root());
606   xbt_dict_free (&nodes);
607   xbt_dict_free (&edges);
608   return ret;
609 }
610
611 void instr_routing_platform_graph_export_graphviz (xbt_graph_t g, const char *filename)
612 {
613   unsigned int cursor = 0;
614   xbt_node_t node = NULL;
615   xbt_edge_t edge = NULL;
616   FILE *file = NULL;
617
618   file = fopen(filename, "w");
619   xbt_assert(file, "Failed to open %s \n", filename);
620
621   if (g->directed)
622     fprintf(file, "digraph test {\n");
623   else
624     fprintf(file, "graph test {\n");
625
626   fprintf(file, "  graph [overlap=scale]\n");
627
628   fprintf(file, "  node [shape=box, style=filled]\n");
629   fprintf(file,
630           "  node [width=.3, height=.3, style=filled, color=skyblue]\n\n");
631
632   xbt_dynar_foreach(g->nodes, cursor, node) {
633     fprintf(file, "  \"%s\";\n", instr_node_name(node));
634   }
635   xbt_dynar_foreach(g->edges, cursor, edge) {
636     const char *src_s = instr_node_name (edge->src);
637     const char *dst_s = instr_node_name (edge->dst);
638     if (g->directed)
639       fprintf(file, "  \"%s\" -> \"%s\";\n", src_s, dst_s);
640     else
641       fprintf(file, "  \"%s\" -- \"%s\";\n", src_s, dst_s);
642   }
643   fprintf(file, "}\n");
644   fclose(file);
645
646 }
647
648 #endif /* HAVE_TRACING */
649