1 /* Copyright (c) 2010-2015. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include "simgrid_config.h"
9 #include "src/surf/network_interface.hpp"
10 #include "src/instr/instr_private.h"
11 #include "surf/surf.h"
12 #include "src/surf/surf_private.h"
21 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API");
23 xbt_dict_t created_categories = NULL;
24 xbt_dict_t declared_marks = NULL;
25 xbt_dict_t user_host_variables = NULL;
26 xbt_dict_t user_vm_variables = NULL;
27 xbt_dict_t user_link_variables = NULL;
28 extern xbt_dict_t trivaNodeTypes;
29 extern xbt_dict_t trivaEdgeTypes;
31 static xbt_dynar_t instr_dict_to_dynar (xbt_dict_t filter)
33 if (!TRACE_is_enabled()) return NULL;
34 if (!TRACE_needs_platform()) return NULL;
36 xbt_dynar_t ret = xbt_dynar_new (sizeof(char*), &xbt_free_ref);
37 xbt_dict_cursor_t cursor = NULL;
39 xbt_dict_foreach(filter, cursor, name, value) {
40 xbt_dynar_push_as (ret, char*, xbt_strdup(name));
45 /** \ingroup TRACE_category
46 * \brief Declare a new category with a random color.
48 * This function should be used to define a user category. The
49 * category can be used to differentiate the tasks that are created
50 * during the simulation (for example, tasks from server1, server2,
51 * or request tasks, computation tasks, communication tasks). All
52 * resource utilization (host power and link bandwidth) will be
53 * classified according to the task category. Tasks that do not
54 * belong to a category are not traced. The color for the category
55 * that is being declared is random. This function has no effect
56 * if a category with the same name has been already declared.
58 * See \ref tracing for details on how to trace
59 * the (categorized) resource utilization.
61 * \param category The name of the new tracing category to be created.
63 * \see TRACE_category_with_color, MSG_task_set_category, SD_task_set_category
65 void TRACE_category(const char *category)
67 TRACE_category_with_color (category, NULL);
70 /** \ingroup TRACE_category
71 * \brief Declare a new category with a color.
73 * Same as #TRACE_category, but let user specify a color encoded as a
74 * RGB-like string with three floats from 0 to 1. So, to specify a
75 * red color, pass "1 0 0" as color parameter. A light-gray color
76 * can be specified using "0.7 0.7 0.7" as color. This function has
77 * no effect if a category with the same name has been already declared.
79 * See \ref tracing for details on how to trace
80 * the (categorized) resource utilization.
82 * \param category The name of the new tracing category to be created.
83 * \param color The color of the category (see \ref tracing to
84 * know how to correctly specify the color)
86 * \see MSG_task_set_category, SD_task_set_category
88 void TRACE_category_with_color (const char *category, const char *color)
91 if (!TRACE_is_enabled()) return;
93 if (!(TRACE_categorized() && category != NULL)) return;
95 /* if platform is not traced, we can't deal with categories */
96 if (!TRACE_needs_platform()) return;
98 //check if category is already created
99 char *created = (char*)xbt_dict_get_or_null(created_categories, category);
101 xbt_dict_set (created_categories, category, xbt_strdup("1"), NULL);
104 char final_color[INSTR_DEFAULT_STR_SIZE];
106 //generate a random color
107 double red = drand48();
108 double green = drand48();
109 double blue = drand48();
110 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%f %f %f", red, green, blue);
112 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
115 XBT_DEBUG("CAT,declare %s, \"%s\" \"%s\"", category, color, final_color);
117 //define the type of this category on top of hosts and links
118 instr_new_variable_type (category, final_color);
122 /** \ingroup TRACE_category
123 * \brief Get declared categories
125 * This function should be used to get categories that were already
126 * declared with #TRACE_category or with #TRACE_category_with_color.
128 * See \ref tracing for details on how to trace
129 * the (categorized) resource utilization.
131 * \return A dynar with the declared categories, must be freed with xbt_dynar_free.
133 * \see MSG_task_set_category, SD_task_set_category
135 xbt_dynar_t TRACE_get_categories (void)
137 if (!TRACE_is_enabled()) return NULL;
138 if (!TRACE_categorized()) return NULL;
140 return instr_dict_to_dynar (created_categories);
143 /** \ingroup TRACE_mark
144 * \brief Declare a new type for tracing mark.
146 * This function declares a new Paje event
147 * type in the trace file that can be used by
148 * simulators to declare application-level
149 * marks. This function is independent of
150 * which API is used in SimGrid.
152 * \param mark_type The name of the new type.
156 void TRACE_declare_mark(const char *mark_type)
159 if (!TRACE_is_enabled()) return;
161 /* if platform is not traced, we don't allow marks */
162 if (!TRACE_needs_platform()) return;
164 if (!mark_type) THROWF (tracing_error, 1, "mark_type is NULL");
166 //check if mark_type is already declared
167 char *created = (char*)xbt_dict_get_or_null(declared_marks, mark_type);
169 THROWF (tracing_error, 1, "mark_type with name (%s) is already declared", mark_type);
172 XBT_DEBUG("MARK,declare %s", mark_type);
173 PJ_type_event_new(mark_type, PJ_type_get_root());
174 xbt_dict_set (declared_marks, mark_type, xbt_strdup("1"), NULL);
177 /** \ingroup TRACE_mark
178 * \brief Declare a new colored value for a previously declared mark type.
180 * This function declares a new colored value for a Paje event
181 * type in the trace file that can be used by
182 * simulators to declare application-level
183 * marks. This function is independent of
184 * which API is used in SimGrid. The color needs to be
185 * a string with three numbers separated by spaces in the range [0,1].
186 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
187 * If a NULL color is provided, the color used will be white ("1 1 1").
189 * \param mark_type The name of the new type.
190 * \param mark_value The name of the new value for this type.
191 * \param mark_color The color of the new value for this type.
195 void TRACE_declare_mark_value_with_color (const char *mark_type, const char *mark_value, const char *mark_color)
198 if (!TRACE_is_enabled()) return;
200 /* if platform is not traced, we don't allow marks */
201 if (!TRACE_needs_platform()) return;
203 if (!mark_type) THROWF (tracing_error, 1, "mark_type is NULL");
204 if (!mark_value) THROWF (tracing_error, 1, "mark_value is NULL");
206 type_t type = PJ_type_get (mark_type, PJ_type_get_root());
208 THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
211 char white[INSTR_DEFAULT_STR_SIZE] = "1.0 1.0 1.0";
212 if (!mark_color) mark_color = white;
214 XBT_DEBUG("MARK,declare_value %s %s %s", mark_type, mark_value, mark_color);
215 PJ_value_new (mark_value, mark_color, type);
218 /** \ingroup TRACE_mark
219 * \brief Declare a new value for a previously declared mark type.
221 * This function declares a new value for a Paje event
222 * type in the trace file that can be used by
223 * simulators to declare application-level
224 * marks. This function is independent of
225 * which API is used in SimGrid. Calling this function is the same
226 * as calling \ref TRACE_declare_mark_value_with_color with a NULL color.
228 * \param mark_type The name of the new type.
229 * \param mark_value The name of the new value for this type.
233 void TRACE_declare_mark_value (const char *mark_type, const char *mark_value)
235 TRACE_declare_mark_value_with_color (mark_type, mark_value, NULL);
239 * \ingroup TRACE_mark
240 * \brief Create a new instance of a tracing mark type.
242 * This function creates a mark in the trace file. The
243 * first parameter had to be previously declared using
244 * #TRACE_declare_mark, the second is the identifier
245 * for this mark instance. We recommend that the
246 * mark_value is a unique value for the whole simulation.
247 * Nevertheless, this is not a strong requirement: the
248 * trace will be valid even if there are multiple mark
249 * identifiers for the same trace.
251 * \param mark_type The name of the type for which the new instance will belong.
252 * \param mark_value The name of the new instance mark.
254 * \see TRACE_declare_mark
256 void TRACE_mark(const char *mark_type, const char *mark_value)
259 if (!TRACE_is_enabled()) return;
261 /* if platform is not traced, we don't allow marks */
262 if (!TRACE_needs_platform()) return;
264 if (!mark_type) THROWF (tracing_error, 1, "mark_type is NULL");
265 if (!mark_value) THROWF (tracing_error, 1, "mark_value is NULL");
267 //check if mark_type is already declared
268 type_t type = PJ_type_get (mark_type, PJ_type_get_root());
270 THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
273 val_t value = PJ_value_get (mark_value, type);
274 XBT_DEBUG("MARK %s %s", mark_type, mark_value);
275 new_pajeNewEvent (MSG_get_clock(), PJ_container_get_root(), type, value);
278 /** \ingroup TRACE_mark
279 * \brief Get declared marks
281 * This function should be used to get marks that were already
282 * declared with #TRACE_declare_mark.
284 * \return A dynar with the declared marks, must be freed with xbt_dynar_free.
287 xbt_dynar_t TRACE_get_marks (void)
289 if (!TRACE_is_enabled()) return NULL;
291 return instr_dict_to_dynar (declared_marks);
294 static void instr_user_variable(double time,
295 const char *resource,
296 const char *variable,
297 const char *father_type,
299 InstrUserVariable what,
304 if (!TRACE_is_enabled()) return;
306 /* if platform is not traced, we don't allow user variables */
307 if (!TRACE_needs_platform()) return;
309 //check if variable is already declared
310 char *created = (char*)xbt_dict_get_or_null(filter, variable);
311 if (what == INSTR_US_DECLARE){
316 xbt_dict_set (filter, variable, xbt_strdup("1"), NULL);
320 //not declared, ignore
326 snprintf(valuestr, 100, "%g", value);
329 case INSTR_US_DECLARE:
330 instr_new_user_variable_type (father_type, variable, color);
334 container_t container = PJ_container_get(resource);
335 type_t type = PJ_type_get (variable, container->type);
336 new_pajeSetVariable(time, container, type, value);
341 container_t container = PJ_container_get(resource);
342 type_t type = PJ_type_get (variable, container->type);
343 new_pajeAddVariable(time, container, type, value);
348 container_t container = PJ_container_get(resource);
349 type_t type = PJ_type_get (variable, container->type);
350 new_pajeSubVariable(time, container, type, value);
354 //TODO: launch exception
359 static void instr_user_srcdst_variable(double time,
362 const char *variable,
363 const char *father_type,
365 InstrUserVariable what)
367 sg_netcard_t src_elm = sg_netcard_by_name_or_null(src);
368 if(!src_elm) xbt_die("Element '%s' not found!",src);
370 sg_netcard_t dst_elm = sg_netcard_by_name_or_null(dst);
371 if(!dst_elm) xbt_die("Element '%s' not found!",dst);
373 std::vector<Link*> *route = new std::vector<Link*>();
374 routing_platf->getRouteAndLatency (src_elm, dst_elm, route,NULL);
375 for (auto link : *route)
376 instr_user_variable (time, link->getName(), variable, father_type, value, what, NULL, user_link_variables);
380 /** \ingroup TRACE_API
381 * \brief Creates a file with the topology of the platform file used for the simulator.
383 * The graph topology will have the following properties: all hosts, links and routers
384 * of the platform file are mapped to graph nodes; routes are mapped to edges.
385 * The platform's AS are not represented in the output.
387 * \param filename The name of the file that will hold the graph.
389 * \return 1 of successful, 0 otherwise.
391 int TRACE_platform_graph_export_graphviz (const char *filename)
393 /* returns 1 if successful, 0 otherwise */
394 if (!TRACE_is_enabled()) return 0;
395 xbt_graph_t g = instr_routing_platform_graph();
396 if (g == NULL) return 0;
397 instr_routing_platform_graph_export_graphviz (g, filename);
398 xbt_graph_free_graph(g, xbt_free_f, xbt_free_f, NULL);
403 * Derived functions that use instr_user_variable and TRACE_user_srcdst_variable.
404 * They were previously defined as pre-processors directives, but were transformed
405 * into functions so the user can track them using gdb.
408 /* for VM variables */
409 /** \ingroup TRACE_user_variables
410 * \brief Declare a new user variable associated to VMs.
412 * Declare a user variable that will be associated to VMs.
413 * A user vm variable can be used to trace user variables
414 * such as the number of tasks in a VM, the number of
415 * clients in an application (for VMs), and so on. The color
416 * associated to this new variable will be random.
418 * \param variable The name of the new variable to be declared.
420 * \see TRACE_vm_variable_declare_with_color
422 void TRACE_vm_variable_declare (const char *variable)
424 instr_user_variable(0, NULL, variable, "MSG_VM", 0, INSTR_US_DECLARE, NULL, user_vm_variables);
427 /** \ingroup TRACE_user_variables
428 * \brief Declare a new user variable associated to VMs with a color.
430 * Same as #TRACE_vm_variable_declare, but associated a color
431 * to the newly created user host variable. The color needs to be
432 * a string with three numbers separated by spaces in the range [0,1].
433 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
435 * \param variable The name of the new variable to be declared.
436 * \param color The color for the new variable.
439 void TRACE_vm_variable_declare_with_color (const char *variable, const char *color)
441 instr_user_variable(0, NULL, variable, "MSG_VM", 0, INSTR_US_DECLARE, color, user_vm_variables);
444 /** \ingroup TRACE_user_variables
445 * \brief Set the value of a variable of a host.
447 * \param vm The name of the VM to be considered.
448 * \param variable The name of the variable to be considered.
449 * \param value The new value of the variable.
451 * \see TRACE_vm_variable_declare, TRACE_vm_variable_add, TRACE_vm_variable_sub
453 void TRACE_vm_variable_set (const char *vm, const char *variable, double value)
456 TRACE_vm_variable_set_with_time (MSG_get_clock(), vm, variable, value);
459 /** \ingroup TRACE_user_variables
460 * \brief Add a value to a variable of a VM.
462 * \param vm The name of the VM to be considered.
463 * \param variable The name of the variable to be considered.
464 * \param value The value to be added to the variable.
466 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_sub
468 void TRACE_vm_variable_add (const char *vm, const char *variable, double value)
470 TRACE_vm_variable_add_with_time (MSG_get_clock(), vm, variable, value);
473 /** \ingroup TRACE_user_variables
474 * \brief Subtract a value from a variable of a VM.
476 * \param vm The name of the vm to be considered.
477 * \param variable The name of the variable to be considered.
478 * \param value The value to be subtracted from the variable.
480 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_add
482 void TRACE_vm_variable_sub (const char *vm, const char *variable, double value)
484 TRACE_vm_variable_sub_with_time (MSG_get_clock(), vm, variable, value);
487 /** \ingroup TRACE_user_variables
488 * \brief Set the value of a variable of a VM at a given timestamp.
490 * Same as #TRACE_vm_variable_set, but let user specify
491 * the time used to trace it. Users can specify a time that
492 * is not the simulated clock time as defined by the core
493 * simulator. This allows a fine-grain control of time
494 * definition, but should be used with caution since the trace
495 * can be inconsistent if resource utilization traces are also traced.
497 * \param time The timestamp to be used to tag this change of value.
498 * \param vm The name of the VM to be considered.
499 * \param variable The name of the variable to be considered.
500 * \param value The new value of the variable.
502 * \see TRACE_vm_variable_declare, TRACE_vm_variable_add_with_time, TRACE_vm_variable_sub_with_time
504 void TRACE_vm_variable_set_with_time (double time, const char *vm, const char *variable, double value)
506 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_SET, NULL, user_vm_variables);
509 /** \ingroup TRACE_user_variables
510 * \brief Add a value to a variable of a VM at a given timestamp.
512 * Same as #TRACE_vm_variable_add, but let user specify
513 * the time used to trace it. Users can specify a time that
514 * is not the simulated clock time as defined by the core
515 * simulator. This allows a fine-grain control of time
516 * definition, but should be used with caution since the trace
517 * can be inconsistent if resource utilization traces are also traced.
519 * \param time The timestamp to be used to tag this change of value.
520 * \param vm The name of the VM to be considered.
521 * \param variable The name of the variable to be considered.
522 * \param value The value to be added to the variable.
524 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_sub_with_time
526 void TRACE_vm_variable_add_with_time (double time, const char *vm, const char *variable, double value)
528 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_ADD, NULL, user_vm_variables);
531 /** \ingroup TRACE_user_variables
532 * \brief Subtract a value from a variable of a VM at a given timestamp.
534 * Same as #TRACE_vm_variable_sub, but let user specify
535 * the time used to trace it. Users can specify a time that
536 * is not the simulated clock time as defined by the core
537 * simulator. This allows a fine-grain control of time
538 * definition, but should be used with caution since the trace
539 * can be inconsistent if resource utilization traces are also traced.
541 * \param time The timestamp to be used to tag this change of value.
542 * \param vm The name of the VM to be considered.
543 * \param variable The name of the variable to be considered.
544 * \param value The value to be subtracted from the variable.
546 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_add_with_time
548 void TRACE_vm_variable_sub_with_time (double time, const char *vm, const char *variable, double value)
550 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_SUB, NULL, user_vm_variables);
553 /** \ingroup TRACE_user_variables
554 * \brief Get declared user vm variables
556 * This function should be used to get VM variables that were already
557 * declared with #TRACE_vm_variable_declare or with #TRACE_vm_variable_declare_with_color.
559 * \return A dynar with the declared host variables, must be freed with xbt_dynar_free.
561 xbt_dynar_t TRACE_get_vm_variables (void)
563 return instr_dict_to_dynar (user_vm_variables);
568 /* for host variables */
569 /** \ingroup TRACE_user_variables
570 * \brief Declare a new user variable associated to hosts.
572 * Declare a user variable that will be associated to hosts.
573 * A user host variable can be used to trace user variables
574 * such as the number of tasks in a server, the number of
575 * clients in an application (for hosts), and so on. The color
576 * associated to this new variable will be random.
578 * \param variable The name of the new variable to be declared.
580 * \see TRACE_host_variable_declare_with_color
582 void TRACE_host_variable_declare (const char *variable)
584 instr_user_variable(0, NULL, variable, "HOST", 0, INSTR_US_DECLARE, NULL, user_host_variables);
587 /** \ingroup TRACE_user_variables
588 * \brief Declare a new user variable associated to hosts with a color.
590 * Same as #TRACE_host_variable_declare, but associated a color
591 * to the newly created user host variable. The color needs to be
592 * a string with three numbers separated by spaces in the range [0,1].
593 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
595 * \param variable The name of the new variable to be declared.
596 * \param color The color for the new variable.
599 void TRACE_host_variable_declare_with_color (const char *variable, const char *color)
601 instr_user_variable(0, NULL, variable, "HOST", 0, INSTR_US_DECLARE, color, user_host_variables);
604 /** \ingroup TRACE_user_variables
605 * \brief Set the value of a variable of a host.
607 * \param host The name of the host to be considered.
608 * \param variable The name of the variable to be considered.
609 * \param value The new value of the variable.
611 * \see TRACE_host_variable_declare, TRACE_host_variable_add, TRACE_host_variable_sub
613 void TRACE_host_variable_set (const char *host, const char *variable, double value)
615 TRACE_host_variable_set_with_time (MSG_get_clock(), host, variable, value);
618 /** \ingroup TRACE_user_variables
619 * \brief Add a value to a variable of a host.
621 * \param host The name of the host to be considered.
622 * \param variable The name of the variable to be considered.
623 * \param value The value to be added to the variable.
625 * \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_sub
627 void TRACE_host_variable_add (const char *host, const char *variable, double value)
629 TRACE_host_variable_add_with_time (MSG_get_clock(), host, variable, value);
632 /** \ingroup TRACE_user_variables
633 * \brief Subtract a value from a variable of a host.
635 * \param host The name of the host to be considered.
636 * \param variable The name of the variable to be considered.
637 * \param value The value to be subtracted from the variable.
639 * \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_add
641 void TRACE_host_variable_sub (const char *host, const char *variable, double value)
643 TRACE_host_variable_sub_with_time (MSG_get_clock(), host, variable, value);
646 /** \ingroup TRACE_user_variables
647 * \brief Set the value of a variable of a host at a given timestamp.
649 * Same as #TRACE_host_variable_set, but let user specify
650 * the time used to trace it. Users can specify a time that
651 * is not the simulated clock time as defined by the core
652 * simulator. This allows a fine-grain control of time
653 * definition, but should be used with caution since the trace
654 * can be inconsistent if resource utilization traces are also traced.
656 * \param time The timestamp to be used to tag this change of value.
657 * \param host The name of the host to be considered.
658 * \param variable The name of the variable to be considered.
659 * \param value The new value of the variable.
661 * \see TRACE_host_variable_declare, TRACE_host_variable_add_with_time, TRACE_host_variable_sub_with_time
663 void TRACE_host_variable_set_with_time (double time, const char *host, const char *variable, double value)
665 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SET, NULL, user_host_variables);
668 /** \ingroup TRACE_user_variables
669 * \brief Add a value to a variable of a host at a given timestamp.
671 * Same as #TRACE_host_variable_add, but let user specify
672 * the time used to trace it. Users can specify a time that
673 * is not the simulated clock time as defined by the core
674 * simulator. This allows a fine-grain control of time
675 * definition, but should be used with caution since the trace
676 * can be inconsistent if resource utilization traces are also traced.
678 * \param time The timestamp to be used to tag this change of value.
679 * \param host The name of the host to be considered.
680 * \param variable The name of the variable to be considered.
681 * \param value The value to be added to the variable.
683 * \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_sub_with_time
685 void TRACE_host_variable_add_with_time (double time, const char *host, const char *variable, double value)
687 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_ADD, NULL, user_host_variables);
690 /** \ingroup TRACE_user_variables
691 * \brief Subtract a value from a variable of a host at a given timestamp.
693 * Same as #TRACE_host_variable_sub, but let user specify
694 * the time used to trace it. Users can specify a time that
695 * is not the simulated clock time as defined by the core
696 * simulator. This allows a fine-grain control of time
697 * definition, but should be used with caution since the trace
698 * can be inconsistent if resource utilization traces are also traced.
700 * \param time The timestamp to be used to tag this change of value.
701 * \param host The name of the host to be considered.
702 * \param variable The name of the variable to be considered.
703 * \param value The value to be subtracted from the variable.
705 * \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_add_with_time
707 void TRACE_host_variable_sub_with_time (double time, const char *host, const char *variable, double value)
709 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SUB, NULL, user_host_variables);
712 /** \ingroup TRACE_user_variables
713 * \brief Get declared user host variables
715 * This function should be used to get host variables that were already
716 * declared with #TRACE_host_variable_declare or with #TRACE_host_variable_declare_with_color.
718 * \return A dynar with the declared host variables, must be freed with xbt_dynar_free.
720 xbt_dynar_t TRACE_get_host_variables (void)
722 return instr_dict_to_dynar (user_host_variables);
725 /* for link variables */
726 /** \ingroup TRACE_user_variables
727 * \brief Declare a new user variable associated to links.
729 * Declare a user variable that will be associated to links.
730 * A user link variable can be used, for example, to trace
731 * user variables such as the number of messages being
732 * transferred through network links. The color
733 * associated to this new variable will be random.
735 * \param variable The name of the new variable to be declared.
737 * \see TRACE_link_variable_declare_with_color
739 void TRACE_link_variable_declare (const char *variable)
741 instr_user_variable (0, NULL, variable, "LINK", 0, INSTR_US_DECLARE, NULL, user_link_variables);
744 /** \ingroup TRACE_user_variables
745 * \brief Declare a new user variable associated to links with a color.
747 * Same as #TRACE_link_variable_declare, but associated a color
748 * to the newly created user link variable. The color needs to be
749 * a string with three numbers separated by spaces in the range [0,1].
750 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
752 * \param variable The name of the new variable to be declared.
753 * \param color The color for the new variable.
756 void TRACE_link_variable_declare_with_color (const char *variable, const char *color)
758 instr_user_variable (0, NULL, variable, "LINK", 0, INSTR_US_DECLARE, color, user_link_variables);
761 /** \ingroup TRACE_user_variables
762 * \brief Set the value of a variable of a link.
764 * \param link The name of the link to be considered.
765 * \param variable The name of the variable to be considered.
766 * \param value The new value of the variable.
768 * \see TRACE_link_variable_declare, TRACE_link_variable_add, TRACE_link_variable_sub
770 void TRACE_link_variable_set (const char *link, const char *variable, double value)
772 TRACE_link_variable_set_with_time (MSG_get_clock(), link, variable, value);
775 /** \ingroup TRACE_user_variables
776 * \brief Add a value to a variable of a link.
778 * \param link The name of the link to be considered.
779 * \param variable The name of the variable to be considered.
780 * \param value The value to be added to the variable.
782 * \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_sub
784 void TRACE_link_variable_add (const char *link, const char *variable, double value)
786 TRACE_link_variable_add_with_time (MSG_get_clock(), link, variable, value);
789 /** \ingroup TRACE_user_variables
790 * \brief Subtract a value from a variable of a link.
792 * \param link The name of the link to be considered.
793 * \param variable The name of the variable to be considered.
794 * \param value The value to be subtracted from the variable.
796 * \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_add
798 void TRACE_link_variable_sub (const char *link, const char *variable, double value)
800 TRACE_link_variable_sub_with_time (MSG_get_clock(), link, variable, value);
803 /** \ingroup TRACE_user_variables
804 * \brief Set the value of a variable of a link at a given timestamp.
806 * Same as #TRACE_link_variable_set, but let user specify
807 * the time used to trace it. Users can specify a time that
808 * is not the simulated clock time as defined by the core
809 * simulator. This allows a fine-grain control of time
810 * definition, but should be used with caution since the trace
811 * can be inconsistent if resource utilization traces are also traced.
813 * \param time The timestamp to be used to tag this change of value.
814 * \param link The name of the link to be considered.
815 * \param variable The name of the variable to be considered.
816 * \param value The new value of the variable.
818 * \see TRACE_link_variable_declare, TRACE_link_variable_add_with_time, TRACE_link_variable_sub_with_time
820 void TRACE_link_variable_set_with_time (double time, const char *link, const char *variable, double value)
822 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SET, NULL, user_link_variables);
825 /** \ingroup TRACE_user_variables
826 * \brief Add a value to a variable of a link at a given timestamp.
828 * Same as #TRACE_link_variable_add, but let user specify
829 * the time used to trace it. Users can specify a time that
830 * is not the simulated clock time as defined by the core
831 * simulator. This allows a fine-grain control of time
832 * definition, but should be used with caution since the trace
833 * can be inconsistent if resource utilization traces are also traced.
835 * \param time The timestamp to be used to tag this change of value.
836 * \param link The name of the link to be considered.
837 * \param variable The name of the variable to be considered.
838 * \param value The value to be added to the variable.
840 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_sub_with_time
842 void TRACE_link_variable_add_with_time (double time, const char *link, const char *variable, double value)
844 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_ADD, NULL, user_link_variables);
847 /** \ingroup TRACE_user_variables
848 * \brief Subtract a value from a variable of a link at a given timestamp.
850 * Same as #TRACE_link_variable_sub, but let user specify
851 * the time used to trace it. Users can specify a time that
852 * is not the simulated clock time as defined by the core
853 * simulator. This allows a fine-grain control of time
854 * definition, but should be used with caution since the trace
855 * can be inconsistent if resource utilization traces are also traced.
857 * \param time The timestamp to be used to tag this change of value.
858 * \param link The name of the link to be considered.
859 * \param variable The name of the variable to be considered.
860 * \param value The value to be subtracted from the variable.
862 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_add_with_time
864 void TRACE_link_variable_sub_with_time (double time, const char *link, const char *variable, double value)
866 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SUB, NULL, user_link_variables);
869 /* for link variables, but with src and dst used for get_route */
870 /** \ingroup TRACE_user_variables
871 * \brief Set the value of the variable present in the links connecting source and destination.
873 * Same as #TRACE_link_variable_set, but instead of providing the
874 * name of link to be considered, provide the source and destination
875 * hosts. All links that are part of the route between source and
876 * destination will have the variable set to the provided value.
878 * \param src The name of the source host for get route.
879 * \param dst The name of the destination host for get route.
880 * \param variable The name of the variable to be considered.
881 * \param value The new value of the variable.
883 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add, TRACE_link_srcdst_variable_sub
885 void TRACE_link_srcdst_variable_set (const char *src, const char *dst, const char *variable, double value)
887 TRACE_link_srcdst_variable_set_with_time (MSG_get_clock(), src, dst, variable, value);
890 /** \ingroup TRACE_user_variables
891 * \brief Add a value to the variable present in the links connecting source and destination.
893 * Same as #TRACE_link_variable_add, but instead of providing the
894 * name of link to be considered, provide the source and destination
895 * hosts. All links that are part of the route between source and
896 * destination will have the value passed as parameter added to
897 * the current value of the variable name to be considered.
899 * \param src The name of the source host for get route.
900 * \param dst The name of the destination host for get route.
901 * \param variable The name of the variable to be considered.
902 * \param value The value to be added to the variable.
904 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_sub
906 void TRACE_link_srcdst_variable_add (const char *src, const char *dst, const char *variable, double value)
908 TRACE_link_srcdst_variable_add_with_time (MSG_get_clock(), src, dst, variable, value);
911 /** \ingroup TRACE_user_variables
912 * \brief Subtract a value from the variable present in the links connecting source and destination.
914 * Same as #TRACE_link_variable_sub, but instead of providing the
915 * name of link to be considered, provide the source and destination
916 * hosts. All links that are part of the route between source and
917 * destination will have the value passed as parameter subtracted from
918 * the current value of the variable name to be considered.
920 * \param src The name of the source host for get route.
921 * \param dst The name of the destination host for get route.
922 * \param variable The name of the variable to be considered.
923 * \param value The value to be subtracted from the variable.
925 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_add
927 void TRACE_link_srcdst_variable_sub (const char *src, const char *dst, const char *variable, double value)
929 TRACE_link_srcdst_variable_sub_with_time (MSG_get_clock(), src, dst, variable, value);
932 /** \ingroup TRACE_user_variables
933 * \brief Set the value of the variable present in the links connecting source and destination at a given timestamp.
935 * Same as #TRACE_link_srcdst_variable_set, but let user specify
936 * the time used to trace it. Users can specify a time that
937 * is not the simulated clock time as defined by the core
938 * simulator. This allows a fine-grain control of time
939 * definition, but should be used with caution since the trace
940 * can be inconsistent if resource utilization traces are also traced.
942 * \param time The timestamp to be used to tag this change of value.
943 * \param src The name of the source host for get route.
944 * \param dst The name of the destination host for get route.
945 * \param variable The name of the variable to be considered.
946 * \param value The new value of the variable.
948 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add_with_time, TRACE_link_srcdst_variable_sub_with_time
950 void TRACE_link_srcdst_variable_set_with_time (double time, const char *src, const char *dst, const char *variable, double value)
952 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SET);
955 /** \ingroup TRACE_user_variables
956 * \brief Add a value to the variable present in the links connecting source and destination at a given timestamp.
958 * Same as #TRACE_link_srcdst_variable_add, but let user specify
959 * the time used to trace it. Users can specify a time that
960 * is not the simulated clock time as defined by the core
961 * simulator. This allows a fine-grain control of time
962 * definition, but should be used with caution since the trace
963 * can be inconsistent if resource utilization traces are also traced.
965 * \param time The timestamp to be used to tag this change of value.
966 * \param src The name of the source host for get route.
967 * \param dst The name of the destination host for get route.
968 * \param variable The name of the variable to be considered.
969 * \param value The value to be added to the variable.
971 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_sub_with_time
973 void TRACE_link_srcdst_variable_add_with_time (double time, const char *src, const char *dst, const char *variable, double value)
975 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_ADD);
978 /** \ingroup TRACE_user_variables
979 * \brief Subtract a value from the variable present in the links connecting source and destination at a given timestamp.
981 * Same as #TRACE_link_srcdst_variable_sub, but let user specify
982 * the time used to trace it. Users can specify a time that
983 * is not the simulated clock time as defined by the core
984 * simulator. This allows a fine-grain control of time
985 * definition, but should be used with caution since the trace
986 * can be inconsistent if resource utilization traces are also traced.
988 * \param time The timestamp to be used to tag this change of value.
989 * \param src The name of the source host for get route.
990 * \param dst The name of the destination host for get route.
991 * \param variable The name of the variable to be considered.
992 * \param value The value to be subtracted from the variable.
994 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_add_with_time
996 void TRACE_link_srcdst_variable_sub_with_time (double time, const char *src, const char *dst, const char *variable, double value)
998 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SUB);
1001 /** \ingroup TRACE_user_variables
1002 * \brief Get declared user link variables
1004 * This function should be used to get link variables that were already
1005 * declared with #TRACE_link_variable_declare or with #TRACE_link_variable_declare_with_color.
1007 * \return A dynar with the declared link variables, must be freed with xbt_dynar_free.
1009 xbt_dynar_t TRACE_get_link_variables (void)
1011 return instr_dict_to_dynar (user_link_variables);
1014 /** \ingroup TRACE_user_variables
1015 * \brief Declare a new user state associated to hosts.
1017 * Declare a user state that will be associated to hosts.
1018 * A user host state can be used to trace application states.
1020 * \param state The name of the new state to be declared.
1022 * \see TRACE_host_state_declare_value
1024 void TRACE_host_state_declare (const char *state)
1026 instr_new_user_state_type("HOST", state);
1029 /** \ingroup TRACE_user_variables
1030 * \brief Declare a new value for a user state associated to hosts.
1032 * Declare a value for a state. The color needs to be
1033 * a string with three numbers separated by spaces in the range [0,1].
1034 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
1036 * \param state The name of the new state to be declared.
1037 * \param value The name of the value
1038 * \param color The color of the value
1040 * \see TRACE_host_state_declare
1042 void TRACE_host_state_declare_value (const char *state, const char *value, const char *color)
1044 instr_new_value_for_user_state_type (state, value, color);
1047 /** \ingroup TRACE_user_variables
1048 * \brief Set the user state to the given value.
1050 * Change a user state previously declared to the given value.
1052 * \param host The name of the host to be considered.
1053 * \param state The name of the state previously declared.
1054 * \param value The new value of the state.
1056 * \see TRACE_host_state_declare, TRACE_host_push_state, TRACE_host_pop_state, TRACE_host_reset_state
1058 void TRACE_host_set_state (const char *host, const char *state, const char *value)
1060 container_t container = PJ_container_get(host);
1061 type_t type = PJ_type_get (state, container->type);
1062 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 */
1063 new_pajeSetState(MSG_get_clock(), container, type, val);
1066 /** \ingroup TRACE_user_variables
1067 * \brief Push a new value for a state of a given host.
1069 * Change a user state previously declared by pushing the new value to the state.
1071 * \param host The name of the host to be considered.
1072 * \param state The name of the state previously declared.
1073 * \param value The value to be pushed.
1075 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_pop_state, TRACE_host_reset_state
1077 void TRACE_host_push_state (const char *host, const char *state, const char *value)
1079 container_t container = PJ_container_get(host);
1080 type_t type = PJ_type_get (state, container->type);
1081 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 */
1082 new_pajePushState(MSG_get_clock(), container, type, val);
1085 /** \ingroup TRACE_user_variables
1086 * \brief Pop the last value of a state of a given host.
1088 * Change a user state previously declared by removing the last value of the state.
1090 * \param host The name of the host to be considered.
1091 * \param state The name of the state to be popped.
1093 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_reset_state
1095 void TRACE_host_pop_state (const char *host, const char *state)
1097 container_t container = PJ_container_get(host);
1098 type_t type = PJ_type_get (state, container->type);
1099 new_pajePopState(MSG_get_clock(), container, type);
1102 /** \ingroup TRACE_user_variables
1103 * \brief Reset the state of a given host.
1105 * Clear all previous values of a user state.
1107 * \param host The name of the host to be considered.
1108 * \param state The name of the state to be cleared.
1110 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_pop_state
1112 void TRACE_host_reset_state (const char *host, const char *state)
1114 container_t container = PJ_container_get(host);
1115 type_t type = PJ_type_get (state, container->type);
1116 new_pajeResetState(MSG_get_clock(), container, type);
1119 /** \ingroup TRACE_API
1120 * \brief Get Paje container types that can be mapped to the nodes of a graph.
1122 * This function can be used to create a user made
1123 * graph configuration file for Triva. Normally, it is
1124 * used with the functions defined in \ref TRACE_user_variables.
1126 * \return A dynar with the types, must be freed with xbt_dynar_free.
1128 xbt_dynar_t TRACE_get_node_types (void)
1130 return instr_dict_to_dynar (trivaNodeTypes);
1133 /** \ingroup TRACE_API
1134 * \brief Get Paje container types that can be mapped to the edges of a graph.
1136 * This function can be used to create a user made
1137 * graph configuration file for Triva. Normally, it is
1138 * used with the functions defined in \ref TRACE_user_variables.
1140 * \return A dynar with the types, must be freed with xbt_dynar_free.
1142 xbt_dynar_t TRACE_get_edge_types (void)
1144 return instr_dict_to_dynar (trivaEdgeTypes);
1147 /** \ingroup TRACE_API
1148 * \brief Pauses all tracing activities.
1151 void TRACE_pause (void)
1153 instr_pause_tracing();
1156 /** \ingroup TRACE_API
1157 * \brief Resumes all tracing activities.
1160 void TRACE_resume (void)
1162 instr_resume_tracing();