Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
5b2140216a928dcc9521e9b6e6de11116848149c
[simgrid.git] / src / instr / instr_interface.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 "simgrid_config.h"
8
9 #ifdef HAVE_TRACING
10 #include "instr/instr_private.h"
11 #include "surf/network_private.h"
12
13 typedef enum {
14   INSTR_US_DECLARE,
15   INSTR_US_SET,
16   INSTR_US_ADD,
17   INSTR_US_SUB
18 } InstrUserVariable;
19
20 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API");
21
22 xbt_dict_t created_categories = NULL;
23 xbt_dict_t declared_marks = NULL;
24 xbt_dict_t user_host_variables = NULL;
25 xbt_dict_t user_link_variables = NULL;
26
27 static xbt_dynar_t instr_dict_to_dynar (xbt_dict_t filter)
28 {
29   if (!TRACE_is_enabled()) return NULL;
30   if (!TRACE_needs_platform()) return NULL;
31
32   xbt_dynar_t ret = xbt_dynar_new (sizeof(char*), &xbt_free_ref);
33   xbt_dict_cursor_t cursor = NULL;
34   char *name, *value;
35   xbt_dict_foreach(filter, cursor, name, value) {
36     xbt_dynar_push_as (ret, char*, xbt_strdup(name));
37   }
38   return ret;
39 }
40
41 /** \ingroup TRACE_category
42  *  \brief Declare a new category with a random color.
43  *
44  *  This function should be used to define a user category. The
45  *  category can be used to differentiate the tasks that are created
46  *  during the simulation (for example, tasks from server1, server2,
47  *  or request tasks, computation tasks, communication tasks). All
48  *  resource utilization (host power and link bandwidth) will be
49  *  classified according to the task category. Tasks that do not
50  *  belong to a category are not traced. The color for the category
51  *  that is being declared is random. This function has no effect
52  *  if a category with the same name has been already declared.
53  *
54  * See \ref tracing_tracing for details on how to trace
55  * the (categorized) resource utilization.
56  *
57  *  \param category The name of the new tracing category to be created.
58  *
59  *  \see TRACE_category_with_color, MSG_task_set_category, SD_task_set_category
60  */
61 void TRACE_category(const char *category)
62 {
63   TRACE_category_with_color (category, NULL);
64 }
65
66 /** \ingroup TRACE_category
67  *  \brief Declare a new category with a color.
68  *
69  *  Same as #TRACE_category, but let user specify a color encoded as a
70  *  RGB-like string with three floats from 0 to 1. So, to specify a
71  *  red color, pass "1 0 0" as color parameter. A light-gray color
72  *  can be specified using "0.7 0.7 0.7" as color. This function has
73  *  no effect if a category with the same name has been already declared.
74  *
75  * See \ref tracing_tracing for details on how to trace
76  * the (categorized) resource utilization.
77  *
78  *  \param category The name of the new tracing category to be created.
79  *  \param color The color of the category (see \ref tracing_tracing to
80  *  know how to correctly specify the color)
81  *
82  *  \see MSG_task_set_category, SD_task_set_category
83  */
84 void TRACE_category_with_color (const char *category, const char *color)
85 {
86   /* safe switch */
87   if (!TRACE_is_enabled()) return;
88
89   if (!(TRACE_categorized() && category != NULL)) return;
90
91   /* if platform is not traced, we can't deal with categories */
92   if (!TRACE_needs_platform()) return;
93
94   //check if category is already created
95   char *created = xbt_dict_get_or_null(created_categories, category);
96   if (created) return;
97   xbt_dict_set (created_categories, category, xbt_strdup("1"), NULL);
98
99   //define final_color
100   char final_color[INSTR_DEFAULT_STR_SIZE];
101   if (!color){
102     //generate a random color
103     double red = drand48();
104     double green = drand48();
105     double blue = drand48();
106     snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%f %f %f", red, green, blue);
107   }else{
108     snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
109   }
110
111   XBT_DEBUG("CAT,declare %s, %s", category, final_color);
112
113   //define the type of this category on top of hosts and links
114   instr_new_variable_type (category, final_color);
115 }
116
117
118 /** \ingroup TRACE_category
119  *  \brief Get declared categories
120  *
121  * This function should be used to get categories that were already
122  * declared with #TRACE_category or with #TRACE_category_with_color.
123  *
124  * See \ref tracing_tracing for details on how to trace
125  * the (categorized) resource utilization.
126  *
127  * \return A dynar with the declared categories, must be freed with xbt_dynar_free.
128  *
129  *  \see MSG_task_set_category, SD_task_set_category
130  */
131 xbt_dynar_t TRACE_get_categories (void)
132 {
133   if (!TRACE_is_enabled()) return NULL;
134   if (!TRACE_categorized()) return NULL;
135
136   return instr_dict_to_dynar (created_categories);
137 }
138
139 /** \ingroup TRACE_mark
140  * \brief Declare a new type for tracing mark.
141  *
142  * This function declares a new Paje event
143  * type in the trace file that can be used by
144  * simulators to declare application-level
145  * marks. This function is independent of
146  * which API is used in SimGrid.
147  *
148  * \param mark_type The name of the new type.
149  *
150  * \see TRACE_mark
151  */
152 void TRACE_declare_mark(const char *mark_type)
153 {
154   /* safe switch */
155   if (!TRACE_is_enabled()) return;
156
157   if (!mark_type) return;
158
159   //check if mark_type is already declared
160   char *created = xbt_dict_get_or_null(declared_marks, mark_type);
161   if (created) return;
162   xbt_dict_set (declared_marks, mark_type, xbt_strdup("1"), NULL);
163
164   XBT_DEBUG("MARK,declare %s", mark_type);
165   PJ_type_event_new(mark_type, NULL, PJ_type_get_root());
166 }
167
168 /**
169  * \ingroup TRACE_mark
170  * \brief Create a new instance of a tracing mark type.
171  *
172  * This function creates a mark in the trace file. The
173  * first parameter had to be previously declared using
174  * #TRACE_declare_mark, the second is the identifier
175  * for this mark instance. We recommend that the
176  * mark_value is a unique value for the whole simulation.
177  * Nevertheless, this is not a strong requirement: the
178  * trace will be valid even if there are multiple mark
179  * identifiers for the same trace.
180  *
181  * \param mark_type The name of the type for which the new instance will belong.
182  * \param mark_value The name of the new instance mark.
183  *
184  * \see TRACE_declare_mark
185  */
186 void TRACE_mark(const char *mark_type, const char *mark_value)
187 {
188   /* safe switch */
189   if (!TRACE_is_enabled()) return;
190
191   if (!mark_type || !mark_value) return;
192
193   //check if mark_type is already declared
194   char *created = xbt_dict_get_or_null(declared_marks, mark_type);
195   if (created) return;
196
197   XBT_DEBUG("MARK %s %s", mark_type, mark_value);
198   type_t type = PJ_type_get (mark_type, PJ_type_get_root());
199   if (type == NULL){
200     THROWF (tracing_error, 1, "mark_type with name (%s) not declared before", mark_type);
201   }
202   val_t value = PJ_value_get (mark_value, type);
203   if (value == NULL){
204     value = PJ_value_new (mark_value, NULL, type);
205   }
206   new_pajeNewEvent (MSG_get_clock(), PJ_container_get_root(), type, value);
207 }
208
209 /** \ingroup TRACE_mark
210  *  \brief Get declared marks
211  *
212  * This function should be used to get marks that were already
213  * declared with #TRACE_declare_mark.
214  *
215  * \return A dynar with the declared marks, must be freed with xbt_dynar_free.
216  *
217  */
218 xbt_dynar_t TRACE_get_marks (void)
219 {
220   if (!TRACE_is_enabled()) return NULL;
221
222   return instr_dict_to_dynar (declared_marks);
223 }
224
225 static void instr_user_variable(double time,
226                          const char *resource,
227                          const char *variable,
228                          const char *father_type,
229                          double value,
230                          InstrUserVariable what,
231                          const char *color,
232                          xbt_dict_t filter)
233 {
234   /* safe switch */
235   if (!TRACE_is_enabled()) return;
236
237   /* if platform is not traced, we don't allow user variables */
238   if (!TRACE_needs_platform()) return;
239
240   //check if variable is already declared
241   char *created = xbt_dict_get_or_null(declared_marks, variable);
242   if (what == INSTR_US_DECLARE){
243     if (created){
244       //already declared
245       return;
246     }else{
247       xbt_dict_set (filter, variable, xbt_strdup("1"), NULL);
248     }
249   }else{
250     if (!created){
251       //not declared, ignore
252       return;
253     }
254   }
255
256   char valuestr[100];
257   snprintf(valuestr, 100, "%g", value);
258
259   switch (what){
260   case INSTR_US_DECLARE:
261     instr_new_user_variable_type (father_type, variable, color);
262     break;
263   case INSTR_US_SET:
264   {
265     container_t container = PJ_container_get(resource);
266     type_t type = PJ_type_get (variable, container->type);
267     new_pajeSetVariable(time, container, type, value);
268     break;
269   }
270   case INSTR_US_ADD:
271   {
272     container_t container = PJ_container_get(resource);
273     type_t type = PJ_type_get (variable, container->type);
274     new_pajeAddVariable(time, container, type, value);
275     break;
276   }
277   case INSTR_US_SUB:
278   {
279     container_t container = PJ_container_get(resource);
280     type_t type = PJ_type_get (variable, container->type);
281     new_pajeSubVariable(time, container, type, value);
282     break;
283   }
284   default:
285     //TODO: launch exception
286     break;
287   }
288 }
289
290 static void instr_user_srcdst_variable(double time,
291                               const char *src,
292                               const char *dst,
293                               const char *variable,
294                               const char *father_type,
295                               double value,
296                               InstrUserVariable what)
297 {
298   xbt_dynar_t route=NULL;
299   network_element_t src_elm = xbt_lib_get_or_null(host_lib,src,ROUTING_HOST_LEVEL);
300   if(!src_elm) src_elm = xbt_lib_get_or_null(as_router_lib,src,ROUTING_ASR_LEVEL);
301   if(!src_elm) xbt_die("Element '%s' not found!",src);
302
303   network_element_t dst_elm = xbt_lib_get_or_null(host_lib,dst,ROUTING_HOST_LEVEL);
304   if(!dst_elm) dst_elm = xbt_lib_get_or_null(as_router_lib,dst,ROUTING_ASR_LEVEL);
305   if(!dst_elm) xbt_die("Element '%s' not found!",dst);
306
307   routing_get_route_and_latency (src_elm, dst_elm, &route,NULL);
308   unsigned int i;
309   void *link;
310   xbt_dynar_foreach (route, i, link) {
311     char *link_name = ((link_CM02_t)link)->lmm_resource.generic_resource.name;
312     instr_user_variable (time, link_name, variable, father_type, value, what, NULL, user_link_variables);
313   }
314 }
315
316 /** \ingroup TRACE_API
317  *  \brief Creates a file with the topology of the platform file used for the simulator.
318  *
319  *  The graph topology will have the following properties: all hosts, links and routers
320  *  of the platform file are mapped to graph nodes; routes are mapped to edges.
321  *  The platform's AS are not represented in the output.
322  *
323  *  \param filename The name of the file that will hold the graph.
324  *
325  *  \return 1 of successful, 0 otherwise.
326  */
327 int TRACE_platform_graph_export_graphviz (const char *filename)
328 {
329   /* returns 1 if successful, 0 otherwise */
330   if (!TRACE_is_enabled()) return 0;
331   xbt_graph_t g = instr_routing_platform_graph();
332   if (g == NULL) return 0;
333   instr_routing_platform_graph_export_graphviz (g, filename);
334   xbt_graph_free_graph (g, xbt_free, xbt_free, NULL);
335   return 1;
336 }
337
338 /*
339  * Derived functions that use instr_user_variable and TRACE_user_srcdst_variable.
340  * They were previously defined as pre-processors directives, but were transformed
341  * into functions so the user can track them using gdb.
342  */
343
344 /* for host variables */
345 /** \ingroup TRACE_user_variables
346  *  \brief Declare a new user variable associated to hosts.
347  *
348  *  Declare a user variable that will be associated to hosts.
349  *  A user host variable can be used to trace user variables
350  *  such as the number of tasks in a server, the number of
351  *  clients in an application (for hosts), and so on. The color
352  *  associated to this new variable will be random.
353  *
354  *  \param variable The name of the new variable to be declared.
355  *
356  *  \see TRACE_host_variable_declare_with_color
357  */
358 void TRACE_host_variable_declare (const char *variable)
359 {
360   instr_user_variable(0, NULL, variable, "HOST", 0, INSTR_US_DECLARE, NULL, user_host_variables);
361 }
362
363 /** \ingroup TRACE_user_variables
364  *  \brief Declare a new user variable associated to hosts with a color.
365  *
366  *  Same as #TRACE_host_variable_declare, but associated a color
367  *  to the newly created user host variable. The color needs to be
368  *  a string with three numbers separated by spaces in the range [0,1].
369  *  A light-gray color can be specified using "0.7 0.7 0.7" as color.
370  *
371  *  \param variable The name of the new variable to be declared.
372  *  \param color The color for the new variable.
373  *
374  */
375 void TRACE_host_variable_declare_with_color (const char *variable, const char *color)
376 {
377   instr_user_variable(0, NULL, variable, "HOST", 0, INSTR_US_DECLARE, color, user_host_variables);
378 }
379
380 /** \ingroup TRACE_user_variables
381  *  \brief Set the value of a variable of a host.
382  *
383  *  \param host The name of the host to be considered.
384  *  \param variable The name of the variable to be considered.
385  *  \param value The new value of the variable.
386  *
387  *  \see TRACE_host_variable_declare, TRACE_host_variable_add, TRACE_host_variable_sub
388  */
389 void TRACE_host_variable_set (const char *host, const char *variable, double value)
390 {
391   TRACE_host_variable_set_with_time (MSG_get_clock(), host, variable, value);
392 }
393
394 /** \ingroup TRACE_user_variables
395  *  \brief Add a value to a variable of a host.
396  *
397  *  \param host The name of the host to be considered.
398  *  \param variable The name of the variable to be considered.
399  *  \param value The value to be added to the variable.
400  *
401  *  \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_sub
402  */
403 void TRACE_host_variable_add (const char *host, const char *variable, double value)
404 {
405   TRACE_host_variable_add_with_time (MSG_get_clock(), host, variable, value);
406 }
407
408 /** \ingroup TRACE_user_variables
409  *  \brief Subtract a value from a variable of a host.
410  *
411  *  \param host The name of the host to be considered.
412  *  \param variable The name of the variable to be considered.
413  *  \param value The value to be subtracted from the variable.
414  *
415  *  \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_add
416  */
417 void TRACE_host_variable_sub (const char *host, const char *variable, double value)
418 {
419   TRACE_host_variable_sub_with_time (MSG_get_clock(), host, variable, value);
420 }
421
422 /** \ingroup TRACE_user_variables
423  *  \brief Set the value of a variable of a host at a given timestamp.
424  *
425  *  Same as #TRACE_host_variable_set, but let user specify
426  *  the time used to trace it. Users can specify a time that
427  *  is not the simulated clock time as defined by the core
428  *  simulator. This allows a fine-grain control of time
429  *  definition, but should be used with caution since the trace
430  *  can be inconsistent if resource utilization traces are also traced.
431  *
432  *  \param time The timestamp to be used to tag this change of value.
433  *  \param host The name of the host to be considered.
434  *  \param variable The name of the variable to be considered.
435  *  \param value The new value of the variable.
436  *
437  *  \see TRACE_host_variable_declare, TRACE_host_variable_add_with_time, TRACE_host_variable_sub_with_time
438  */
439 void TRACE_host_variable_set_with_time (double time, const char *host, const char *variable, double value)
440 {
441   instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SET, NULL, user_host_variables);
442 }
443
444 /** \ingroup TRACE_user_variables
445  *  \brief Add a value to a variable of a host at a given timestamp.
446  *
447  *  Same as #TRACE_host_variable_add, but let user specify
448  *  the time used to trace it. Users can specify a time that
449  *  is not the simulated clock time as defined by the core
450  *  simulator. This allows a fine-grain control of time
451  *  definition, but should be used with caution since the trace
452  *  can be inconsistent if resource utilization traces are also traced.
453  *
454  *  \param time The timestamp to be used to tag this change of value.
455  *  \param host The name of the host to be considered.
456  *  \param variable The name of the variable to be considered.
457  *  \param value The value to be added to the variable.
458  *
459  *  \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_sub_with_time
460  */
461 void TRACE_host_variable_add_with_time (double time, const char *host, const char *variable, double value)
462 {
463   instr_user_variable(time, host, variable, "HOST", value, INSTR_US_ADD, NULL, user_host_variables);
464 }
465
466 /** \ingroup TRACE_user_variables
467  *  \brief Subtract a value from a variable of a host at a given timestamp.
468  *
469  *  Same as #TRACE_host_variable_sub, but let user specify
470  *  the time used to trace it. Users can specify a time that
471  *  is not the simulated clock time as defined by the core
472  *  simulator. This allows a fine-grain control of time
473  *  definition, but should be used with caution since the trace
474  *  can be inconsistent if resource utilization traces are also traced.
475  *
476  *  \param time The timestamp to be used to tag this change of value.
477  *  \param host The name of the host to be considered.
478  *  \param variable The name of the variable to be considered.
479  *  \param value The value to be subtracted from the variable.
480  *
481  *  \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_add_with_time
482  */
483 void TRACE_host_variable_sub_with_time (double time, const char *host, const char *variable, double value)
484 {
485   instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SUB, NULL, user_host_variables);
486 }
487
488 /** \ingroup TRACE_user_variables
489  *  \brief Get declared user host variables
490  *
491  * This function should be used to get host variables that were already
492  * declared with #TRACE_host_variable_declare or with #TRACE_host_variable_declare_with_color.
493  *
494  * \return A dynar with the declared host variables, must be freed with xbt_dynar_free.
495  */
496 xbt_dynar_t TRACE_get_host_variables (void)
497 {
498   return instr_dict_to_dynar (user_host_variables);
499 }
500
501 /* for link variables */
502 /** \ingroup TRACE_user_variables
503  *  \brief Declare a new user variable associated to links.
504  *
505  *  Declare a user variable that will be associated to links.
506  *  A user link variable can be used, for example, to trace
507  *  user variables such as the number of messages being
508  *  transferred through network links. The color
509  *  associated to this new variable will be random.
510  *
511  *  \param variable The name of the new variable to be declared.
512  *
513  *  \see TRACE_link_variable_declare_with_color
514  */
515 void TRACE_link_variable_declare (const char *variable)
516 {
517   instr_user_variable (0, NULL, variable, "LINK", 0, INSTR_US_DECLARE, NULL, user_link_variables);
518 }
519
520 /** \ingroup TRACE_user_variables
521  *  \brief Declare a new user variable associated to links with a color.
522  *
523  *  Same as #TRACE_link_variable_declare, but associated a color
524  *  to the newly created user link variable. The color needs to be
525  *  a string with three numbers separated by spaces in the range [0,1].
526  *  A light-gray color can be specified using "0.7 0.7 0.7" as color.
527  *
528  *  \param variable The name of the new variable to be declared.
529  *  \param color The color for the new variable.
530  *
531  */
532 void TRACE_link_variable_declare_with_color (const char *variable, const char *color)
533 {
534   instr_user_variable (0, NULL, variable, "LINK", 0, INSTR_US_DECLARE, color, user_link_variables);
535 }
536
537 /** \ingroup TRACE_user_variables
538  *  \brief Set the value of a variable of a link.
539  *
540  *  \param link The name of the link to be considered.
541  *  \param variable The name of the variable to be considered.
542  *  \param value The new value of the variable.
543  *
544  *  \see TRACE_link_variable_declare, TRACE_link_variable_add, TRACE_link_variable_sub
545  */
546 void TRACE_link_variable_set (const char *link, const char *variable, double value)
547 {
548   TRACE_link_variable_set_with_time (MSG_get_clock(), link, variable, value);
549 }
550
551 /** \ingroup TRACE_user_variables
552  *  \brief Add a value to a variable of a link.
553  *
554  *  \param link The name of the link to be considered.
555  *  \param variable The name of the variable to be considered.
556  *  \param value The value to be added to the variable.
557  *
558  *  \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_sub
559  */
560 void TRACE_link_variable_add (const char *link, const char *variable, double value)
561 {
562   TRACE_link_variable_add_with_time (MSG_get_clock(), link, variable, value);
563 }
564
565 /** \ingroup TRACE_user_variables
566  *  \brief Subtract a value from a variable of a link.
567  *
568  *  \param link The name of the link to be considered.
569  *  \param variable The name of the variable to be considered.
570  *  \param value The value to be subtracted from the variable.
571  *
572  *  \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_add
573  */
574 void TRACE_link_variable_sub (const char *link, const char *variable, double value)
575 {
576   TRACE_link_variable_sub_with_time (MSG_get_clock(), link, variable, value);
577 }
578
579 /** \ingroup TRACE_user_variables
580  *  \brief Set the value of a variable of a link at a given timestamp.
581  *
582  *  Same as #TRACE_link_variable_set, but let user specify
583  *  the time used to trace it. Users can specify a time that
584  *  is not the simulated clock time as defined by the core
585  *  simulator. This allows a fine-grain control of time
586  *  definition, but should be used with caution since the trace
587  *  can be inconsistent if resource utilization traces are also traced.
588  *
589  *  \param time The timestamp to be used to tag this change of value.
590  *  \param link The name of the link to be considered.
591  *  \param variable The name of the variable to be considered.
592  *  \param value The new value of the variable.
593  *
594  *  \see TRACE_link_variable_declare, TRACE_link_variable_add_with_time, TRACE_link_variable_sub_with_time
595  */
596 void TRACE_link_variable_set_with_time (double time, const char *link, const char *variable, double value)
597 {
598   instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SET, NULL, user_link_variables);
599 }
600
601 /** \ingroup TRACE_user_variables
602  *  \brief Add a value to a variable of a link at a given timestamp.
603  *
604  *  Same as #TRACE_link_variable_add, but let user specify
605  *  the time used to trace it. Users can specify a time that
606  *  is not the simulated clock time as defined by the core
607  *  simulator. This allows a fine-grain control of time
608  *  definition, but should be used with caution since the trace
609  *  can be inconsistent if resource utilization traces are also traced.
610  *
611  *  \param time The timestamp to be used to tag this change of value.
612  *  \param link The name of the link to be considered.
613  *  \param variable The name of the variable to be considered.
614  *  \param value The value to be added to the variable.
615  *
616  *  \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_sub_with_time
617  */
618 void TRACE_link_variable_add_with_time (double time, const char *link, const char *variable, double value)
619 {
620   instr_user_variable (time, link, variable, "LINK", value, INSTR_US_ADD, NULL, user_link_variables);
621 }
622
623 /** \ingroup TRACE_user_variables
624  *  \brief Subtract a value from a variable of a link at a given timestamp.
625  *
626  *  Same as #TRACE_link_variable_sub, but let user specify
627  *  the time used to trace it. Users can specify a time that
628  *  is not the simulated clock time as defined by the core
629  *  simulator. This allows a fine-grain control of time
630  *  definition, but should be used with caution since the trace
631  *  can be inconsistent if resource utilization traces are also traced.
632  *
633  *  \param time The timestamp to be used to tag this change of value.
634  *  \param link The name of the link to be considered.
635  *  \param variable The name of the variable to be considered.
636  *  \param value The value to be subtracted from the variable.
637  *
638  *  \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_add_with_time
639  */
640 void TRACE_link_variable_sub_with_time (double time, const char *link, const char *variable, double value)
641 {
642   instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SUB, NULL, user_link_variables);
643 }
644
645 /* for link variables, but with src and dst used for get_route */
646 /** \ingroup TRACE_user_variables
647  *  \brief Set the value of the variable present in the links connecting source and destination.
648  *
649  *  Same as #TRACE_link_variable_set, but instead of providing the
650  *  name of link to be considered, provide the source and destination
651  *  hosts. All links that are part of the route between source and
652  *  destination will have the variable set to the provided value.
653  *
654  *  \param src The name of the source host for get route.
655  *  \param dst The name of the destination host for get route.
656  *  \param variable The name of the variable to be considered.
657  *  \param value The new value of the variable.
658  *
659  *  \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add, TRACE_link_srcdst_variable_sub
660  */
661 void TRACE_link_srcdst_variable_set (const char *src, const char *dst, const char *variable, double value)
662 {
663   TRACE_link_srcdst_variable_set_with_time (MSG_get_clock(), src, dst, variable, value);
664 }
665
666 /** \ingroup TRACE_user_variables
667  *  \brief Add a value to the variable present in the links connecting source and destination.
668  *
669  *  Same as #TRACE_link_variable_add, but instead of providing the
670  *  name of link to be considered, provide the source and destination
671  *  hosts. All links that are part of the route between source and
672  *  destination will have the value passed as parameter added to
673  *  the current value of the variable name to be considered.
674  *
675  *  \param src The name of the source host for get route.
676  *  \param dst The name of the destination host for get route.
677  *  \param variable The name of the variable to be considered.
678  *  \param value The value to be added to the variable.
679  *
680  *  \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_sub
681  */
682 void TRACE_link_srcdst_variable_add (const char *src, const char *dst, const char *variable, double value)
683 {
684   TRACE_link_srcdst_variable_add_with_time (MSG_get_clock(), src, dst, variable, value);
685 }
686
687 /** \ingroup TRACE_user_variables
688  *  \brief Subtract a value from the variable present in the links connecting source and destination.
689  *
690  *  Same as #TRACE_link_variable_sub, but instead of providing the
691  *  name of link to be considered, provide the source and destination
692  *  hosts. All links that are part of the route between source and
693  *  destination will have the value passed as parameter subtracted from
694  *  the current value of the variable name to be considered.
695  *
696  *  \param src The name of the source host for get route.
697  *  \param dst The name of the destination host for get route.
698  *  \param variable The name of the variable to be considered.
699  *  \param value The value to be subtracted from the variable.
700  *
701  *  \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_add
702  */
703 void TRACE_link_srcdst_variable_sub (const char *src, const char *dst, const char *variable, double value)
704 {
705   TRACE_link_srcdst_variable_sub_with_time (MSG_get_clock(), src, dst, variable, value);
706 }
707
708 /** \ingroup TRACE_user_variables
709  *  \brief Set the value of the variable present in the links connecting source and destination at a given timestamp.
710  *
711  *  Same as #TRACE_link_srcdst_variable_set, but let user specify
712  *  the time used to trace it. Users can specify a time that
713  *  is not the simulated clock time as defined by the core
714  *  simulator. This allows a fine-grain control of time
715  *  definition, but should be used with caution since the trace
716  *  can be inconsistent if resource utilization traces are also traced.
717  *
718  *  \param time The timestamp to be used to tag this change of value.
719  *  \param src The name of the source host for get route.
720  *  \param dst The name of the destination host for get route.
721  *  \param variable The name of the variable to be considered.
722  *  \param value The new value of the variable.
723  *
724  *  \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add_with_time, TRACE_link_srcdst_variable_sub_with_time
725  */
726 void TRACE_link_srcdst_variable_set_with_time (double time, const char *src, const char *dst, const char *variable, double value)
727 {
728   instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SET);
729 }
730
731 /** \ingroup TRACE_user_variables
732  *  \brief Add a value to the variable present in the links connecting source and destination at a given timestamp.
733  *
734  *  Same as #TRACE_link_srcdst_variable_add, but let user specify
735  *  the time used to trace it. Users can specify a time that
736  *  is not the simulated clock time as defined by the core
737  *  simulator. This allows a fine-grain control of time
738  *  definition, but should be used with caution since the trace
739  *  can be inconsistent if resource utilization traces are also traced.
740  *
741  *  \param time The timestamp to be used to tag this change of value.
742  *  \param src The name of the source host for get route.
743  *  \param dst The name of the destination host for get route.
744  *  \param variable The name of the variable to be considered.
745  *  \param value The value to be added to the variable.
746  *
747  *  \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_sub_with_time
748  */
749 void TRACE_link_srcdst_variable_add_with_time (double time, const char *src, const char *dst, const char *variable, double value)
750 {
751   instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_ADD);
752 }
753
754 /** \ingroup TRACE_user_variables
755  *  \brief Subtract a value from the variable present in the links connecting source and destination at a given timestamp.
756  *
757  *  Same as #TRACE_link_srcdst_variable_sub, but let user specify
758  *  the time used to trace it. Users can specify a time that
759  *  is not the simulated clock time as defined by the core
760  *  simulator. This allows a fine-grain control of time
761  *  definition, but should be used with caution since the trace
762  *  can be inconsistent if resource utilization traces are also traced.
763  *
764  *  \param time The timestamp to be used to tag this change of value.
765  *  \param src The name of the source host for get route.
766  *  \param dst The name of the destination host for get route.
767  *  \param variable The name of the variable to be considered.
768  *  \param value The value to be subtracted from the variable.
769  *
770  *  \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_add_with_time
771  */
772 void TRACE_link_srcdst_variable_sub_with_time (double time, const char *src, const char *dst, const char *variable, double value)
773 {
774   instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SUB);
775 }
776
777 /** \ingroup TRACE_user_variables
778  *  \brief Get declared user link variables
779  *
780  * This function should be used to get link variables that were already
781  * declared with #TRACE_link_variable_declare or with #TRACE_link_variable_declare_with_color.
782  *
783  * \return A dynar with the declared link variables, must be freed with xbt_dynar_free.
784  */
785 xbt_dynar_t TRACE_get_link_variables (void)
786 {
787   return instr_dict_to_dynar (user_link_variables);
788 }
789
790 #endif /* HAVE_TRACING */