Logo AND Algorithmique Numérique Distribuée

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