Logo AND Algorithmique Numérique Distribuée

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