Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] only ignore the call if the mark type wasn't declared
[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 platform is not traced, we don't allow marks */
160   if (!TRACE_needs_platform()) return;
161
162   if (!mark_type) return;
163
164   //check if mark_type is already declared
165   char *created = xbt_dict_get_or_null(declared_marks, mark_type);
166   if (created) return;
167   xbt_dict_set (declared_marks, mark_type, xbt_strdup("1"), NULL);
168
169   XBT_DEBUG("MARK,declare %s", mark_type);
170   PJ_type_event_new(mark_type, NULL, PJ_type_get_root());
171 }
172
173 /**
174  * \ingroup TRACE_mark
175  * \brief Create a new instance of a tracing mark type.
176  *
177  * This function creates a mark in the trace file. The
178  * first parameter had to be previously declared using
179  * #TRACE_declare_mark, the second is the identifier
180  * for this mark instance. We recommend that the
181  * mark_value is a unique value for the whole simulation.
182  * Nevertheless, this is not a strong requirement: the
183  * trace will be valid even if there are multiple mark
184  * identifiers for the same trace.
185  *
186  * \param mark_type The name of the type for which the new instance will belong.
187  * \param mark_value The name of the new instance mark.
188  *
189  * \see TRACE_declare_mark
190  */
191 void TRACE_mark(const char *mark_type, const char *mark_value)
192 {
193   /* safe switch */
194   if (!TRACE_is_enabled()) return;
195
196   /* if platform is not traced, we don't allow marks */
197   if (!TRACE_needs_platform()) return;
198
199   if (!mark_type || !mark_value) return;
200
201   //check if mark_type is already declared
202   char *created = xbt_dict_get_or_null(declared_marks, mark_type);
203   if (!created) return;
204
205   XBT_DEBUG("MARK %s %s", mark_type, mark_value);
206   type_t type = PJ_type_get (mark_type, PJ_type_get_root());
207   if (type == NULL){
208     THROWF (tracing_error, 1, "mark_type with name (%s) not declared before", mark_type);
209   }
210   val_t value = PJ_value_get_or_new (mark_value, NULL, type);
211   new_pajeNewEvent (MSG_get_clock(), PJ_container_get_root(), type, value);
212 }
213
214 /** \ingroup TRACE_mark
215  *  \brief Get declared marks
216  *
217  * This function should be used to get marks that were already
218  * declared with #TRACE_declare_mark.
219  *
220  * \return A dynar with the declared marks, must be freed with xbt_dynar_free.
221  *
222  */
223 xbt_dynar_t TRACE_get_marks (void)
224 {
225   if (!TRACE_is_enabled()) return NULL;
226
227   return instr_dict_to_dynar (declared_marks);
228 }
229
230 static void instr_user_variable(double time,
231                          const char *resource,
232                          const char *variable,
233                          const char *father_type,
234                          double value,
235                          InstrUserVariable what,
236                          const char *color,
237                          xbt_dict_t filter)
238 {
239   /* safe switch */
240   if (!TRACE_is_enabled()) return;
241
242   /* if platform is not traced, we don't allow user variables */
243   if (!TRACE_needs_platform()) return;
244
245   //check if variable is already declared
246   char *created = xbt_dict_get_or_null(filter, variable);
247   if (what == INSTR_US_DECLARE){
248     if (created){
249       //already declared
250       return;
251     }else{
252       xbt_dict_set (filter, variable, xbt_strdup("1"), NULL);
253     }
254   }else{
255     if (!created){
256       //not declared, ignore
257       return;
258     }
259   }
260
261   char valuestr[100];
262   snprintf(valuestr, 100, "%g", value);
263
264   switch (what){
265   case INSTR_US_DECLARE:
266     instr_new_user_variable_type (father_type, variable, color);
267     break;
268   case INSTR_US_SET:
269   {
270     container_t container = PJ_container_get(resource);
271     type_t type = PJ_type_get (variable, container->type);
272     new_pajeSetVariable(time, container, type, value);
273     break;
274   }
275   case INSTR_US_ADD:
276   {
277     container_t container = PJ_container_get(resource);
278     type_t type = PJ_type_get (variable, container->type);
279     new_pajeAddVariable(time, container, type, value);
280     break;
281   }
282   case INSTR_US_SUB:
283   {
284     container_t container = PJ_container_get(resource);
285     type_t type = PJ_type_get (variable, container->type);
286     new_pajeSubVariable(time, container, type, value);
287     break;
288   }
289   default:
290     //TODO: launch exception
291     break;
292   }
293 }
294
295 static void instr_user_srcdst_variable(double time,
296                               const char *src,
297                               const char *dst,
298                               const char *variable,
299                               const char *father_type,
300                               double value,
301                               InstrUserVariable what)
302 {
303   xbt_dynar_t route=NULL;
304   sg_routing_edge_t src_elm = sg_routing_edge_by_name_or_null(src);
305   if(!src_elm) xbt_die("Element '%s' not found!",src);
306
307   sg_routing_edge_t dst_elm = sg_routing_edge_by_name_or_null(dst);
308   if(!dst_elm) xbt_die("Element '%s' not found!",dst);
309
310   routing_get_route_and_latency (src_elm, dst_elm, &route,NULL);
311   unsigned int i;
312   void *link;
313   xbt_dynar_foreach (route, i, link) {
314     char *link_name = ((link_CM02_t)link)->lmm_resource.generic_resource.name;
315     instr_user_variable (time, link_name, variable, father_type, value, what, NULL, user_link_variables);
316   }
317 }
318
319 /** \ingroup TRACE_API
320  *  \brief Creates a file with the topology of the platform file used for the simulator.
321  *
322  *  The graph topology will have the following properties: all hosts, links and routers
323  *  of the platform file are mapped to graph nodes; routes are mapped to edges.
324  *  The platform's AS are not represented in the output.
325  *
326  *  \param filename The name of the file that will hold the graph.
327  *
328  *  \return 1 of successful, 0 otherwise.
329  */
330 int TRACE_platform_graph_export_graphviz (const char *filename)
331 {
332   /* returns 1 if successful, 0 otherwise */
333   if (!TRACE_is_enabled()) return 0;
334   xbt_graph_t g = instr_routing_platform_graph();
335   if (g == NULL) return 0;
336   instr_routing_platform_graph_export_graphviz (g, filename);
337   xbt_graph_free_graph (g, xbt_free, xbt_free, NULL);
338   return 1;
339 }
340
341 /*
342  * Derived functions that use instr_user_variable and TRACE_user_srcdst_variable.
343  * They were previously defined as pre-processors directives, but were transformed
344  * into functions so the user can track them using gdb.
345  */
346
347 /* for host variables */
348 /** \ingroup TRACE_user_variables
349  *  \brief Declare a new user variable associated to hosts.
350  *
351  *  Declare a user variable that will be associated to hosts.
352  *  A user host variable can be used to trace user variables
353  *  such as the number of tasks in a server, the number of
354  *  clients in an application (for hosts), and so on. The color
355  *  associated to this new variable will be random.
356  *
357  *  \param variable The name of the new variable to be declared.
358  *
359  *  \see TRACE_host_variable_declare_with_color
360  */
361 void TRACE_host_variable_declare (const char *variable)
362 {
363   instr_user_variable(0, NULL, variable, "HOST", 0, INSTR_US_DECLARE, NULL, user_host_variables);
364 }
365
366 /** \ingroup TRACE_user_variables
367  *  \brief Declare a new user variable associated to hosts with a color.
368  *
369  *  Same as #TRACE_host_variable_declare, but associated a color
370  *  to the newly created user host variable. The color needs to be
371  *  a string with three numbers separated by spaces in the range [0,1].
372  *  A light-gray color can be specified using "0.7 0.7 0.7" as color.
373  *
374  *  \param variable The name of the new variable to be declared.
375  *  \param color The color for the new variable.
376  *
377  */
378 void TRACE_host_variable_declare_with_color (const char *variable, const char *color)
379 {
380   instr_user_variable(0, NULL, variable, "HOST", 0, INSTR_US_DECLARE, color, user_host_variables);
381 }
382
383 /** \ingroup TRACE_user_variables
384  *  \brief Set the value of a variable of a host.
385  *
386  *  \param host The name of the host to be considered.
387  *  \param variable The name of the variable to be considered.
388  *  \param value The new value of the variable.
389  *
390  *  \see TRACE_host_variable_declare, TRACE_host_variable_add, TRACE_host_variable_sub
391  */
392 void TRACE_host_variable_set (const char *host, const char *variable, double value)
393 {
394   TRACE_host_variable_set_with_time (MSG_get_clock(), host, variable, value);
395 }
396
397 /** \ingroup TRACE_user_variables
398  *  \brief Add a value to a variable of a host.
399  *
400  *  \param host The name of the host to be considered.
401  *  \param variable The name of the variable to be considered.
402  *  \param value The value to be added to the variable.
403  *
404  *  \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_sub
405  */
406 void TRACE_host_variable_add (const char *host, const char *variable, double value)
407 {
408   TRACE_host_variable_add_with_time (MSG_get_clock(), host, variable, value);
409 }
410
411 /** \ingroup TRACE_user_variables
412  *  \brief Subtract a value from a variable of a host.
413  *
414  *  \param host The name of the host to be considered.
415  *  \param variable The name of the variable to be considered.
416  *  \param value The value to be subtracted from the variable.
417  *
418  *  \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_add
419  */
420 void TRACE_host_variable_sub (const char *host, const char *variable, double value)
421 {
422   TRACE_host_variable_sub_with_time (MSG_get_clock(), host, variable, value);
423 }
424
425 /** \ingroup TRACE_user_variables
426  *  \brief Set the value of a variable of a host at a given timestamp.
427  *
428  *  Same as #TRACE_host_variable_set, but let user specify
429  *  the time used to trace it. Users can specify a time that
430  *  is not the simulated clock time as defined by the core
431  *  simulator. This allows a fine-grain control of time
432  *  definition, but should be used with caution since the trace
433  *  can be inconsistent if resource utilization traces are also traced.
434  *
435  *  \param time The timestamp to be used to tag this change of value.
436  *  \param host The name of the host to be considered.
437  *  \param variable The name of the variable to be considered.
438  *  \param value The new value of the variable.
439  *
440  *  \see TRACE_host_variable_declare, TRACE_host_variable_add_with_time, TRACE_host_variable_sub_with_time
441  */
442 void TRACE_host_variable_set_with_time (double time, const char *host, const char *variable, double value)
443 {
444   instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SET, NULL, user_host_variables);
445 }
446
447 /** \ingroup TRACE_user_variables
448  *  \brief Add a value to a variable of a host at a given timestamp.
449  *
450  *  Same as #TRACE_host_variable_add, but let user specify
451  *  the time used to trace it. Users can specify a time that
452  *  is not the simulated clock time as defined by the core
453  *  simulator. This allows a fine-grain control of time
454  *  definition, but should be used with caution since the trace
455  *  can be inconsistent if resource utilization traces are also traced.
456  *
457  *  \param time The timestamp to be used to tag this change of value.
458  *  \param host The name of the host to be considered.
459  *  \param variable The name of the variable to be considered.
460  *  \param value The value to be added to the variable.
461  *
462  *  \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_sub_with_time
463  */
464 void TRACE_host_variable_add_with_time (double time, const char *host, const char *variable, double value)
465 {
466   instr_user_variable(time, host, variable, "HOST", value, INSTR_US_ADD, NULL, user_host_variables);
467 }
468
469 /** \ingroup TRACE_user_variables
470  *  \brief Subtract a value from a variable of a host at a given timestamp.
471  *
472  *  Same as #TRACE_host_variable_sub, but let user specify
473  *  the time used to trace it. Users can specify a time that
474  *  is not the simulated clock time as defined by the core
475  *  simulator. This allows a fine-grain control of time
476  *  definition, but should be used with caution since the trace
477  *  can be inconsistent if resource utilization traces are also traced.
478  *
479  *  \param time The timestamp to be used to tag this change of value.
480  *  \param host The name of the host to be considered.
481  *  \param variable The name of the variable to be considered.
482  *  \param value The value to be subtracted from the variable.
483  *
484  *  \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_add_with_time
485  */
486 void TRACE_host_variable_sub_with_time (double time, const char *host, const char *variable, double value)
487 {
488   instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SUB, NULL, user_host_variables);
489 }
490
491 /** \ingroup TRACE_user_variables
492  *  \brief Get declared user host variables
493  *
494  * This function should be used to get host variables that were already
495  * declared with #TRACE_host_variable_declare or with #TRACE_host_variable_declare_with_color.
496  *
497  * \return A dynar with the declared host variables, must be freed with xbt_dynar_free.
498  */
499 xbt_dynar_t TRACE_get_host_variables (void)
500 {
501   return instr_dict_to_dynar (user_host_variables);
502 }
503
504 /* for link variables */
505 /** \ingroup TRACE_user_variables
506  *  \brief Declare a new user variable associated to links.
507  *
508  *  Declare a user variable that will be associated to links.
509  *  A user link variable can be used, for example, to trace
510  *  user variables such as the number of messages being
511  *  transferred through network links. The color
512  *  associated to this new variable will be random.
513  *
514  *  \param variable The name of the new variable to be declared.
515  *
516  *  \see TRACE_link_variable_declare_with_color
517  */
518 void TRACE_link_variable_declare (const char *variable)
519 {
520   instr_user_variable (0, NULL, variable, "LINK", 0, INSTR_US_DECLARE, NULL, user_link_variables);
521 }
522
523 /** \ingroup TRACE_user_variables
524  *  \brief Declare a new user variable associated to links with a color.
525  *
526  *  Same as #TRACE_link_variable_declare, but associated a color
527  *  to the newly created user link variable. The color needs to be
528  *  a string with three numbers separated by spaces in the range [0,1].
529  *  A light-gray color can be specified using "0.7 0.7 0.7" as color.
530  *
531  *  \param variable The name of the new variable to be declared.
532  *  \param color The color for the new variable.
533  *
534  */
535 void TRACE_link_variable_declare_with_color (const char *variable, const char *color)
536 {
537   instr_user_variable (0, NULL, variable, "LINK", 0, INSTR_US_DECLARE, color, user_link_variables);
538 }
539
540 /** \ingroup TRACE_user_variables
541  *  \brief Set the value of a variable of a link.
542  *
543  *  \param link The name of the link to be considered.
544  *  \param variable The name of the variable to be considered.
545  *  \param value The new value of the variable.
546  *
547  *  \see TRACE_link_variable_declare, TRACE_link_variable_add, TRACE_link_variable_sub
548  */
549 void TRACE_link_variable_set (const char *link, const char *variable, double value)
550 {
551   TRACE_link_variable_set_with_time (MSG_get_clock(), link, variable, value);
552 }
553
554 /** \ingroup TRACE_user_variables
555  *  \brief Add a value to a variable of a link.
556  *
557  *  \param link The name of the link to be considered.
558  *  \param variable The name of the variable to be considered.
559  *  \param value The value to be added to the variable.
560  *
561  *  \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_sub
562  */
563 void TRACE_link_variable_add (const char *link, const char *variable, double value)
564 {
565   TRACE_link_variable_add_with_time (MSG_get_clock(), link, variable, value);
566 }
567
568 /** \ingroup TRACE_user_variables
569  *  \brief Subtract a value from a variable of a link.
570  *
571  *  \param link The name of the link to be considered.
572  *  \param variable The name of the variable to be considered.
573  *  \param value The value to be subtracted from the variable.
574  *
575  *  \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_add
576  */
577 void TRACE_link_variable_sub (const char *link, const char *variable, double value)
578 {
579   TRACE_link_variable_sub_with_time (MSG_get_clock(), link, variable, value);
580 }
581
582 /** \ingroup TRACE_user_variables
583  *  \brief Set the value of a variable of a link at a given timestamp.
584  *
585  *  Same as #TRACE_link_variable_set, but let user specify
586  *  the time used to trace it. Users can specify a time that
587  *  is not the simulated clock time as defined by the core
588  *  simulator. This allows a fine-grain control of time
589  *  definition, but should be used with caution since the trace
590  *  can be inconsistent if resource utilization traces are also traced.
591  *
592  *  \param time The timestamp to be used to tag this change of value.
593  *  \param link The name of the link to be considered.
594  *  \param variable The name of the variable to be considered.
595  *  \param value The new value of the variable.
596  *
597  *  \see TRACE_link_variable_declare, TRACE_link_variable_add_with_time, TRACE_link_variable_sub_with_time
598  */
599 void TRACE_link_variable_set_with_time (double time, const char *link, const char *variable, double value)
600 {
601   instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SET, NULL, user_link_variables);
602 }
603
604 /** \ingroup TRACE_user_variables
605  *  \brief Add a value to a variable of a link at a given timestamp.
606  *
607  *  Same as #TRACE_link_variable_add, but let user specify
608  *  the time used to trace it. Users can specify a time that
609  *  is not the simulated clock time as defined by the core
610  *  simulator. This allows a fine-grain control of time
611  *  definition, but should be used with caution since the trace
612  *  can be inconsistent if resource utilization traces are also traced.
613  *
614  *  \param time The timestamp to be used to tag this change of value.
615  *  \param link The name of the link to be considered.
616  *  \param variable The name of the variable to be considered.
617  *  \param value The value to be added to the variable.
618  *
619  *  \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_sub_with_time
620  */
621 void TRACE_link_variable_add_with_time (double time, const char *link, const char *variable, double value)
622 {
623   instr_user_variable (time, link, variable, "LINK", value, INSTR_US_ADD, NULL, user_link_variables);
624 }
625
626 /** \ingroup TRACE_user_variables
627  *  \brief Subtract a value from a variable of a link at a given timestamp.
628  *
629  *  Same as #TRACE_link_variable_sub, but let user specify
630  *  the time used to trace it. Users can specify a time that
631  *  is not the simulated clock time as defined by the core
632  *  simulator. This allows a fine-grain control of time
633  *  definition, but should be used with caution since the trace
634  *  can be inconsistent if resource utilization traces are also traced.
635  *
636  *  \param time The timestamp to be used to tag this change of value.
637  *  \param link The name of the link to be considered.
638  *  \param variable The name of the variable to be considered.
639  *  \param value The value to be subtracted from the variable.
640  *
641  *  \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_add_with_time
642  */
643 void TRACE_link_variable_sub_with_time (double time, const char *link, const char *variable, double value)
644 {
645   instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SUB, NULL, user_link_variables);
646 }
647
648 /* for link variables, but with src and dst used for get_route */
649 /** \ingroup TRACE_user_variables
650  *  \brief Set the value of the variable present in the links connecting source and destination.
651  *
652  *  Same as #TRACE_link_variable_set, but instead of providing the
653  *  name of link to be considered, provide the source and destination
654  *  hosts. All links that are part of the route between source and
655  *  destination will have the variable set to the provided value.
656  *
657  *  \param src The name of the source host for get route.
658  *  \param dst The name of the destination host for get route.
659  *  \param variable The name of the variable to be considered.
660  *  \param value The new value of the variable.
661  *
662  *  \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add, TRACE_link_srcdst_variable_sub
663  */
664 void TRACE_link_srcdst_variable_set (const char *src, const char *dst, const char *variable, double value)
665 {
666   TRACE_link_srcdst_variable_set_with_time (MSG_get_clock(), src, dst, variable, value);
667 }
668
669 /** \ingroup TRACE_user_variables
670  *  \brief Add a value to the variable present in the links connecting source and destination.
671  *
672  *  Same as #TRACE_link_variable_add, but instead of providing the
673  *  name of link to be considered, provide the source and destination
674  *  hosts. All links that are part of the route between source and
675  *  destination will have the value passed as parameter added to
676  *  the current value of the variable name to be considered.
677  *
678  *  \param src The name of the source host for get route.
679  *  \param dst The name of the destination host for get route.
680  *  \param variable The name of the variable to be considered.
681  *  \param value The value to be added to the variable.
682  *
683  *  \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_sub
684  */
685 void TRACE_link_srcdst_variable_add (const char *src, const char *dst, const char *variable, double value)
686 {
687   TRACE_link_srcdst_variable_add_with_time (MSG_get_clock(), src, dst, variable, value);
688 }
689
690 /** \ingroup TRACE_user_variables
691  *  \brief Subtract a value from the variable present in the links connecting source and destination.
692  *
693  *  Same as #TRACE_link_variable_sub, but instead of providing the
694  *  name of link to be considered, provide the source and destination
695  *  hosts. All links that are part of the route between source and
696  *  destination will have the value passed as parameter subtracted from
697  *  the current value of the variable name to be considered.
698  *
699  *  \param src The name of the source host for get route.
700  *  \param dst The name of the destination host for get route.
701  *  \param variable The name of the variable to be considered.
702  *  \param value The value to be subtracted from the variable.
703  *
704  *  \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_add
705  */
706 void TRACE_link_srcdst_variable_sub (const char *src, const char *dst, const char *variable, double value)
707 {
708   TRACE_link_srcdst_variable_sub_with_time (MSG_get_clock(), src, dst, variable, value);
709 }
710
711 /** \ingroup TRACE_user_variables
712  *  \brief Set the value of the variable present in the links connecting source and destination at a given timestamp.
713  *
714  *  Same as #TRACE_link_srcdst_variable_set, but let user specify
715  *  the time used to trace it. Users can specify a time that
716  *  is not the simulated clock time as defined by the core
717  *  simulator. This allows a fine-grain control of time
718  *  definition, but should be used with caution since the trace
719  *  can be inconsistent if resource utilization traces are also traced.
720  *
721  *  \param time The timestamp to be used to tag this change of value.
722  *  \param src The name of the source host for get route.
723  *  \param dst The name of the destination host for get route.
724  *  \param variable The name of the variable to be considered.
725  *  \param value The new value of the variable.
726  *
727  *  \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add_with_time, TRACE_link_srcdst_variable_sub_with_time
728  */
729 void TRACE_link_srcdst_variable_set_with_time (double time, const char *src, const char *dst, const char *variable, double value)
730 {
731   instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SET);
732 }
733
734 /** \ingroup TRACE_user_variables
735  *  \brief Add a value to the variable present in the links connecting source and destination at a given timestamp.
736  *
737  *  Same as #TRACE_link_srcdst_variable_add, but let user specify
738  *  the time used to trace it. Users can specify a time that
739  *  is not the simulated clock time as defined by the core
740  *  simulator. This allows a fine-grain control of time
741  *  definition, but should be used with caution since the trace
742  *  can be inconsistent if resource utilization traces are also traced.
743  *
744  *  \param time The timestamp to be used to tag this change of value.
745  *  \param src The name of the source host for get route.
746  *  \param dst The name of the destination host for get route.
747  *  \param variable The name of the variable to be considered.
748  *  \param value The value to be added to the variable.
749  *
750  *  \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_sub_with_time
751  */
752 void TRACE_link_srcdst_variable_add_with_time (double time, const char *src, const char *dst, const char *variable, double value)
753 {
754   instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_ADD);
755 }
756
757 /** \ingroup TRACE_user_variables
758  *  \brief Subtract a value from the variable present in the links connecting source and destination at a given timestamp.
759  *
760  *  Same as #TRACE_link_srcdst_variable_sub, but let user specify
761  *  the time used to trace it. Users can specify a time that
762  *  is not the simulated clock time as defined by the core
763  *  simulator. This allows a fine-grain control of time
764  *  definition, but should be used with caution since the trace
765  *  can be inconsistent if resource utilization traces are also traced.
766  *
767  *  \param time The timestamp to be used to tag this change of value.
768  *  \param src The name of the source host for get route.
769  *  \param dst The name of the destination host for get route.
770  *  \param variable The name of the variable to be considered.
771  *  \param value The value to be subtracted from the variable.
772  *
773  *  \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_add_with_time
774  */
775 void TRACE_link_srcdst_variable_sub_with_time (double time, const char *src, const char *dst, const char *variable, double value)
776 {
777   instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SUB);
778 }
779
780 /** \ingroup TRACE_user_variables
781  *  \brief Get declared user link variables
782  *
783  * This function should be used to get link variables that were already
784  * declared with #TRACE_link_variable_declare or with #TRACE_link_variable_declare_with_color.
785  *
786  * \return A dynar with the declared link variables, must be freed with xbt_dynar_free.
787  */
788 xbt_dynar_t TRACE_get_link_variables (void)
789 {
790   return instr_dict_to_dynar (user_link_variables);
791 }
792
793 /** \ingroup TRACE_user_variables
794  *  \brief Declare a new user state associated to hosts.
795  *
796  *  Declare a user state that will be associated to hosts.
797  *  A user host state can be used to trace application states.
798  *
799  *  \param state The name of the new state to be declared.
800  *
801  *  \see TRACE_host_state_declare_value
802  */
803 void TRACE_host_state_declare (const char *state)
804 {
805   instr_new_user_state_type("HOST", state);
806 }
807
808 /** \ingroup TRACE_user_variables
809  *  \brief Declare a new value for a user state associated to hosts.
810  *
811  *  Declare a value for a state. The color needs to be
812  *  a string with three numbers separated by spaces in the range [0,1].
813  *  A light-gray color can be specified using "0.7 0.7 0.7" as color.
814  *
815  *  \param state The name of the new state to be declared.
816  *  \param value The name of the value
817  *  \param color The color of the value
818  *
819  *  \see TRACE_host_state_declare
820  */
821 void TRACE_host_state_declare_value (const char *state, const char *value, const char *color)
822 {
823   instr_new_value_for_user_state_type (state, value, color);
824 }
825
826 /** \ingroup TRACE_user_variables
827  *  \brief Set the user state to the given value.
828  *
829  *  Change a user state previously declared to the given value.
830  *
831  *  \param host The name of the host to be considered.
832  *  \param state The name of the state previously declared.
833  *  \param value The new value of the state.
834  *
835  *  \see TRACE_host_state_declare, TRACE_host_push_state, TRACE_host_pop_state, TRACE_host_reset_state
836  */
837 void TRACE_host_set_state (const char *host, const char *state, const char *value)
838 {
839   container_t container = PJ_container_get(host);
840   type_t type = PJ_type_get (state, container->type);
841   val_t val = PJ_value_get_or_new (value, NULL, type); /* if user didn't declare a value with a color, user a NULL color */
842   new_pajeSetState(MSG_get_clock(), container, type, val);
843 }
844
845 /** \ingroup TRACE_user_variables
846  *  \brief Push a new value for a state of a given host.
847  *
848  *  Change a user state previously declared by pushing the new value to the state.
849  *
850  *  \param host The name of the host to be considered.
851  *  \param state The name of the state previously declared.
852  *  \param value The value to be pushed.
853  *
854  *  \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_pop_state, TRACE_host_reset_state
855  */
856 void TRACE_host_push_state (const char *host, const char *state, const char *value)
857 {
858   container_t container = PJ_container_get(host);
859   type_t type = PJ_type_get (state, container->type);
860   val_t val = PJ_value_get_or_new (value, NULL, type); /* if user didn't declare a value with a color, user a NULL color */
861   new_pajePushState(MSG_get_clock(), container, type, val);
862 }
863
864 /** \ingroup TRACE_user_variables
865  *  \brief Pop the last value of a state of a given host.
866  *
867  *  Change a user state previously declared by removing the last value of the state.
868  *
869  *  \param host The name of the host to be considered.
870  *  \param state The name of the state to be popped.
871  *
872  *  \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_reset_state
873  */
874 void TRACE_host_pop_state (const char *host, const char *state)
875 {
876   container_t container = PJ_container_get(host);
877   type_t type = PJ_type_get (state, container->type);
878   new_pajePopState(MSG_get_clock(), container, type);
879 }
880
881 /** \ingroup TRACE_user_variables
882  *  \brief Reset the state of a given host.
883  *
884  *  Clear all previous values of a user state.
885  *
886  *  \param host The name of the host to be considered.
887  *  \param state The name of the state to be cleared.
888  *
889  *  \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_pop_state
890  */
891 void TRACE_host_reset_state (const char *host, const char *state)
892 {
893   container_t container = PJ_container_get(host);
894   type_t type = PJ_type_get (state, container->type);
895   new_pajeResetState(MSG_get_clock(), container, type);
896 }
897
898 /** \ingroup TRACE_API
899  *  \brief Get Paje container types that can be mapped to the nodes of a graph.
900  *
901  *  This function can be used to create a user made
902  *  graph configuration file for Triva. Normally, it is
903  *  used with the functions defined in \ref TRACE_user_variables.
904  *
905  *  \return A dynar with the types, must be freed with xbt_dynar_free.
906  */
907 xbt_dynar_t TRACE_get_node_types (void)
908 {
909   return instr_dict_to_dynar (trivaNodeTypes);
910 }
911
912 /** \ingroup TRACE_API
913  *  \brief Get Paje container types that can be mapped to the edges of a graph.
914  *
915  *  This function can be used to create a user made
916  *  graph configuration file for Triva. Normally, it is
917  *  used with the functions defined in \ref TRACE_user_variables.
918  *
919  *  \return A dynar with the types, must be freed with xbt_dynar_free.
920  */
921 xbt_dynar_t TRACE_get_edge_types (void)
922 {
923   return instr_dict_to_dynar (trivaEdgeTypes);
924 }
925
926 #endif /* HAVE_TRACING */