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"
8 #include "src/surf/network_interface.hpp"
9 #include "src/instr/instr_private.h"
10 #include "surf/surf.h"
11 #include "src/surf/surf_private.h"
20 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API");
22 xbt_dict_t created_categories = nullptr;
23 xbt_dict_t declared_marks = nullptr;
24 xbt_dict_t user_host_variables = nullptr;
25 xbt_dict_t user_vm_variables = nullptr;
26 xbt_dict_t user_link_variables = nullptr;
27 extern xbt_dict_t trivaNodeTypes;
28 extern xbt_dict_t trivaEdgeTypes;
30 static xbt_dynar_t instr_dict_to_dynar (xbt_dict_t filter)
32 if (!TRACE_is_enabled() || !TRACE_needs_platform())
35 xbt_dynar_t ret = xbt_dynar_new (sizeof(char*), &xbt_free_ref);
36 xbt_dict_cursor_t cursor = nullptr;
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 category can be used to differentiate the tasks that
49 * are created during the simulation (for example, tasks from server1, server2, or request tasks, computation tasks,
50 * communication tasks). All resource utilization (host power and link bandwidth) will be classified according to the
51 * task category. Tasks that do not belong to a category are not traced. The color for the category that is being
52 * declared is random. This function has no effect if a category with the same name has been already declared.
54 * See \ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
56 * \param category The name of the new tracing category to be created.
58 * \see TRACE_category_with_color, MSG_task_set_category, SD_task_set_category
60 void TRACE_category(const char *category)
62 TRACE_category_with_color (category, nullptr);
65 /** \ingroup TRACE_category
66 * \brief Declare a new category with a color.
68 * Same as #TRACE_category, but let user specify a color encoded as a RGB-like string with three floats from 0 to 1.
69 * So, to specify a red color, pass "1 0 0" as color parameter. A light-gray color can be specified using "0.7 0.7 0.7"
70 * as color. This function has no effect if a category with the same name has been already declared.
72 * See \ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
74 * \param category The name of the new tracing category to be created.
75 * \param color The color of the category (see \ref outcomes_vizu to
76 * know how to correctly specify the color)
78 * \see MSG_task_set_category, SD_task_set_category
80 void TRACE_category_with_color (const char *category, const char *color)
82 /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with categories */
83 if (!TRACE_is_enabled() || !TRACE_needs_platform())
86 if (!(TRACE_categorized() && category != nullptr))
89 //check if category is already created
90 if (xbt_dict_get_or_null(created_categories, category) != nullptr)
93 xbt_dict_set (created_categories, category, xbt_strdup("1"), nullptr);
96 char final_color[INSTR_DEFAULT_STR_SIZE];
98 //generate a random color
99 double red = drand48();
100 double green = drand48();
101 double blue = drand48();
102 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%f %f %f", red, green, blue);
104 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
107 XBT_DEBUG("CAT,declare %s, \"%s\" \"%s\"", category, color, final_color);
109 //define the type of this category on top of hosts and links
110 instr_new_variable_type (category, final_color);
113 /** \ingroup TRACE_category
114 * \brief Get declared categories
116 * This function should be used to get categories that were already declared with #TRACE_category or with
117 * #TRACE_category_with_color.
119 * See \ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
121 * \return A dynar with the declared categories, must be freed with xbt_dynar_free.
123 * \see MSG_task_set_category, SD_task_set_category
125 xbt_dynar_t TRACE_get_categories ()
127 if (!TRACE_is_enabled() || !TRACE_categorized())
130 return instr_dict_to_dynar (created_categories);
133 /** \ingroup TRACE_mark
134 * \brief Declare a new type for tracing mark.
136 * This function declares a new Paje event type in the trace file that can be used by simulators to declare
137 * application-level marks. This function is independent of which API is used in SimGrid.
139 * \param mark_type The name of the new type.
143 void TRACE_declare_mark(const char *mark_type)
145 /* safe switchs. tracing has to be activated and if platform is not traced, we can't deal with marks */
146 if (!TRACE_is_enabled() || !TRACE_needs_platform())
150 THROWF (tracing_error, 1, "mark_type is nullptr");
152 //check if mark_type is already declared
153 if (xbt_dict_get_or_null(declared_marks, mark_type) != nullptr) {
154 THROWF (tracing_error, 1, "mark_type with name (%s) is already declared", mark_type);
157 XBT_DEBUG("MARK,declare %s", mark_type);
158 PJ_type_event_new(mark_type, PJ_type_get_root());
159 xbt_dict_set (declared_marks, mark_type, xbt_strdup("1"), nullptr);
162 /** \ingroup TRACE_mark
163 * \brief Declare a new colored value for a previously declared mark type.
165 * This function declares a new colored value for a Paje event type in the trace file that can be used by simulators to
166 * declare application-level marks. This function is independent of which API is used in SimGrid. The color needs to be
167 * a string with three numbers separated by spaces in the range [0,1].
168 * A light-gray color can be specified using "0.7 0.7 0.7" as color. If a nullptr color is provided, the color used will
169 * be white ("1 1 1").
171 * \param mark_type The name of the new type.
172 * \param mark_value The name of the new value for this type.
173 * \param mark_color The color of the new value for this type.
177 void TRACE_declare_mark_value_with_color (const char *mark_type, const char *mark_value, const char *mark_color)
179 /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
180 if (!TRACE_is_enabled() || !TRACE_needs_platform())
184 THROWF (tracing_error, 1, "mark_type is nullptr");
186 THROWF (tracing_error, 1, "mark_value is nullptr");
188 type_t type = PJ_type_get (mark_type, PJ_type_get_root());
190 THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
193 char white[INSTR_DEFAULT_STR_SIZE] = "1.0 1.0 1.0";
197 XBT_DEBUG("MARK,declare_value %s %s %s", mark_type, mark_value, mark_color);
198 PJ_value_new (mark_value, mark_color, type);
201 /** \ingroup TRACE_mark
202 * \brief Declare a new value for a previously declared mark type.
204 * This function declares a new value for a Paje event type in the trace file that can be used by simulators to declare
205 * application-level marks. This function is independent of which API is used in SimGrid. Calling this function is the
206 * same as calling \ref TRACE_declare_mark_value_with_color with a nullptr color.
208 * \param mark_type The name of the new type.
209 * \param mark_value The name of the new value for this type.
213 void TRACE_declare_mark_value (const char *mark_type, const char *mark_value)
215 TRACE_declare_mark_value_with_color (mark_type, mark_value, nullptr);
219 * \ingroup TRACE_mark
220 * \brief Create a new instance of a tracing mark type.
222 * This function creates a mark in the trace file. The first parameter had to be previously declared using
223 * #TRACE_declare_mark, the second is the identifier for this mark instance. We recommend that the mark_value is a
224 * unique value for the whole simulation. Nevertheless, this is not a strong requirement: the trace will be valid even
225 * if there are multiple mark identifiers for the same trace.
227 * \param mark_type The name of the type for which the new instance will belong.
228 * \param mark_value The name of the new instance mark.
230 * \see TRACE_declare_mark
232 void TRACE_mark(const char *mark_type, const char *mark_value)
234 /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
235 if (!TRACE_is_enabled() || !TRACE_needs_platform())
239 THROWF (tracing_error, 1, "mark_type is nullptr");
241 THROWF (tracing_error, 1, "mark_value is nullptr");
243 //check if mark_type is already declared
244 type_t type = PJ_type_get (mark_type, PJ_type_get_root());
246 THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
249 val_t value = PJ_value_get (mark_value, type);
250 XBT_DEBUG("MARK %s %s", mark_type, mark_value);
251 new_pajeNewEvent (MSG_get_clock(), PJ_container_get_root(), type, value);
254 /** \ingroup TRACE_mark
255 * \brief Get declared marks
257 * This function should be used to get marks that were already declared with #TRACE_declare_mark.
259 * \return A dynar with the declared marks, must be freed with xbt_dynar_free.
261 xbt_dynar_t TRACE_get_marks ()
263 if (!TRACE_is_enabled())
266 return instr_dict_to_dynar (declared_marks);
269 static void instr_user_variable(double time, const char *resource, const char *variable, const char *father_type,
270 double value, InstrUserVariable what, const char *color, xbt_dict_t filter)
272 /* safe switches. tracing has to be activated and if platform is not traced, we don't allow user variables */
273 if (!TRACE_is_enabled() || !TRACE_needs_platform())
276 //check if variable is already declared
277 char *created = (char*)xbt_dict_get_or_null(filter, variable);
278 if (what == INSTR_US_DECLARE){
279 if (created){//already declared
282 xbt_dict_set (filter, variable, xbt_strdup("1"), nullptr);
283 instr_new_user_variable_type (father_type, variable, color);
286 if (!created){//not declared, ignore
290 snprintf(valuestr, 100, "%g", value);
291 container_t container = PJ_container_get(resource);
292 type_t type = PJ_type_get (variable, container->type);
295 new_pajeSetVariable(time, container, type, value);
298 new_pajeAddVariable(time, container, type, value);
301 new_pajeSubVariable(time, container, type, value);
311 static void instr_user_srcdst_variable(double time, const char *src, const char *dst, const char *variable,
312 const char *father_type, double value, InstrUserVariable what)
314 sg_netcard_t src_elm = sg_netcard_by_name_or_null(src);
316 xbt_die("Element '%s' not found!",src);
318 sg_netcard_t dst_elm = sg_netcard_by_name_or_null(dst);
320 xbt_die("Element '%s' not found!",dst);
322 std::vector<Link*> route;
323 simgrid::kernel::routing::AsImpl::getGlobalRoute(src_elm, dst_elm, &route, nullptr);
324 for (auto link : route)
325 instr_user_variable (time, link->getName(), variable, father_type, value, what, nullptr, user_link_variables);
328 /** \ingroup TRACE_API
329 * \brief Creates a file with the topology of the platform file used for the simulator.
331 * The graph topology will have the following properties: all hosts, links and routers of the platform file are mapped
332 * to graph nodes; routes are mapped to edges.
333 * The platform's AS are not represented in the output.
335 * \param filename The name of the file that will hold the graph.
337 * \return 1 of successful, 0 otherwise.
339 int TRACE_platform_graph_export_graphviz (const char *filename)
341 /* returns 1 if successful, 0 otherwise */
342 if (!TRACE_is_enabled())
344 xbt_graph_t g = instr_routing_platform_graph();
347 instr_routing_platform_graph_export_graphviz (g, filename);
348 xbt_graph_free_graph(g, xbt_free_f, xbt_free_f, nullptr);
353 * Derived functions that use instr_user_variable and TRACE_user_srcdst_variable. They were previously defined as
354 * pre-processors directives, but were transformed into functions so the user can track them using gdb.
357 /* for VM variables */
358 /** \ingroup TRACE_user_variables
359 * \brief Declare a new user variable associated to VMs.
361 * Declare a user variable that will be associated to VMs. A user vm variable can be used to trace user variables
362 * such as the number of tasks in a VM, the number of clients in an application (for VMs), and so on. The color
363 * associated to this new variable will be random.
365 * \param variable The name of the new variable to be declared.
367 * \see TRACE_vm_variable_declare_with_color
369 void TRACE_vm_variable_declare (const char *variable)
371 instr_user_variable(0, nullptr, variable, "MSG_VM", 0, INSTR_US_DECLARE, nullptr, user_vm_variables);
374 /** \ingroup TRACE_user_variables
375 * \brief Declare a new user variable associated to VMs with a color.
377 * Same as #TRACE_vm_variable_declare, but associated a color to the newly created user host variable. The color needs
378 * to be a string with three numbers separated by spaces in the range [0,1].
379 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
381 * \param variable The name of the new variable to be declared.
382 * \param color The color for the new variable.
384 void TRACE_vm_variable_declare_with_color (const char *variable, const char *color)
386 instr_user_variable(0, nullptr, variable, "MSG_VM", 0, INSTR_US_DECLARE, color, user_vm_variables);
389 /** \ingroup TRACE_user_variables
390 * \brief Set the value of a variable of a host.
392 * \param vm The name of the VM to be considered.
393 * \param variable The name of the variable to be considered.
394 * \param value The new value of the variable.
396 * \see TRACE_vm_variable_declare, TRACE_vm_variable_add, TRACE_vm_variable_sub
398 void TRACE_vm_variable_set (const char *vm, const char *variable, double value)
400 TRACE_vm_variable_set_with_time (MSG_get_clock(), vm, variable, value);
403 /** \ingroup TRACE_user_variables
404 * \brief Add a value to a variable of a VM.
406 * \param vm The name of the VM to be considered.
407 * \param variable The name of the variable to be considered.
408 * \param value The value to be added to the variable.
410 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_sub
412 void TRACE_vm_variable_add (const char *vm, const char *variable, double value)
414 TRACE_vm_variable_add_with_time (MSG_get_clock(), vm, variable, value);
417 /** \ingroup TRACE_user_variables
418 * \brief Subtract a value from a variable of a VM.
420 * \param vm The name of the vm to be considered.
421 * \param variable The name of the variable to be considered.
422 * \param value The value to be subtracted from the variable.
424 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_add
426 void TRACE_vm_variable_sub (const char *vm, const char *variable, double value)
428 TRACE_vm_variable_sub_with_time (MSG_get_clock(), vm, variable, value);
431 /** \ingroup TRACE_user_variables
432 * \brief Set the value of a variable of a VM at a given timestamp.
434 * Same as #TRACE_vm_variable_set, but let user specify the time used to trace it. Users can specify a time that
435 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
436 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
439 * \param time The timestamp to be used to tag this change of value.
440 * \param vm The name of the VM to be considered.
441 * \param variable The name of the variable to be considered.
442 * \param value The new value of the variable.
444 * \see TRACE_vm_variable_declare, TRACE_vm_variable_add_with_time, TRACE_vm_variable_sub_with_time
446 void TRACE_vm_variable_set_with_time (double time, const char *vm, const char *variable, double value)
448 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_SET, nullptr, user_vm_variables);
451 /** \ingroup TRACE_user_variables
452 * \brief Add a value to a variable of a VM at a given timestamp.
454 * Same as #TRACE_vm_variable_add, but let user specify the time used to trace it. Users can specify a time that
455 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
456 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
459 * \param time The timestamp to be used to tag this change of value.
460 * \param vm The name of the VM to be considered.
461 * \param variable The name of the variable to be considered.
462 * \param value The value to be added to the variable.
464 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_sub_with_time
466 void TRACE_vm_variable_add_with_time (double time, const char *vm, const char *variable, double value)
468 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_ADD, nullptr, user_vm_variables);
471 /** \ingroup TRACE_user_variables
472 * \brief Subtract a value from a variable of a VM at a given timestamp.
474 * Same as #TRACE_vm_variable_sub, but let user specify the time used to trace it. Users can specify a time that
475 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
476 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
479 * \param time The timestamp to be used to tag this change of value.
480 * \param vm The name of the VM 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.
484 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_add_with_time
486 void TRACE_vm_variable_sub_with_time (double time, const char *vm, const char *variable, double value)
488 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_SUB, nullptr, user_vm_variables);
491 /** \ingroup TRACE_user_variables
492 * \brief Get declared user vm variables
494 * This function should be used to get VM variables that were already declared with #TRACE_vm_variable_declare or with
495 * #TRACE_vm_variable_declare_with_color.
497 * \return A dynar with the declared host variables, must be freed with xbt_dynar_free.
499 xbt_dynar_t TRACE_get_vm_variables ()
501 return instr_dict_to_dynar (user_vm_variables);
504 /* for host variables */
505 /** \ingroup TRACE_user_variables
506 * \brief Declare a new user variable associated to hosts.
508 * Declare a user variable that will be associated to hosts.
509 * A user host variable can be used to trace user variables such as the number of tasks in a server, the number of
510 * clients in an application (for hosts), and so on. The color associated to this new variable will be random.
512 * \param variable The name of the new variable to be declared.
514 * \see TRACE_host_variable_declare_with_color
516 void TRACE_host_variable_declare (const char *variable)
518 instr_user_variable(0, nullptr, variable, "HOST", 0, INSTR_US_DECLARE, nullptr, user_host_variables);
521 /** \ingroup TRACE_user_variables
522 * \brief Declare a new user variable associated to hosts with a color.
524 * Same as #TRACE_host_variable_declare, but associated a color to the newly created user host variable. The color
525 * needs to be a string with three numbers separated by spaces in the range [0,1].
526 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
528 * \param variable The name of the new variable to be declared.
529 * \param color The color for the new variable.
531 void TRACE_host_variable_declare_with_color (const char *variable, const char *color)
533 instr_user_variable(0, nullptr, variable, "HOST", 0, INSTR_US_DECLARE, color, user_host_variables);
536 /** \ingroup TRACE_user_variables
537 * \brief Set the value of a variable of a host.
539 * \param host The name of the host to be considered.
540 * \param variable The name of the variable to be considered.
541 * \param value The new value of the variable.
543 * \see TRACE_host_variable_declare, TRACE_host_variable_add, TRACE_host_variable_sub
545 void TRACE_host_variable_set (const char *host, const char *variable, double value)
547 TRACE_host_variable_set_with_time (MSG_get_clock(), host, variable, value);
550 /** \ingroup TRACE_user_variables
551 * \brief Add a value to a variable of a host.
553 * \param host The name of the host to be considered.
554 * \param variable The name of the variable to be considered.
555 * \param value The value to be added to the variable.
557 * \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_sub
559 void TRACE_host_variable_add (const char *host, const char *variable, double value)
561 TRACE_host_variable_add_with_time (MSG_get_clock(), host, variable, value);
564 /** \ingroup TRACE_user_variables
565 * \brief Subtract a value from a variable of a host.
567 * \param host The name of the host to be considered.
568 * \param variable The name of the variable to be considered.
569 * \param value The value to be subtracted from the variable.
571 * \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_add
573 void TRACE_host_variable_sub (const char *host, const char *variable, double value)
575 TRACE_host_variable_sub_with_time (MSG_get_clock(), host, variable, value);
578 /** \ingroup TRACE_user_variables
579 * \brief Set the value of a variable of a host at a given timestamp.
581 * Same as #TRACE_host_variable_set, but let user specify the time used to trace it. Users can specify a time that
582 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
583 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
586 * \param time The timestamp to be used to tag this change of value.
587 * \param host The name of the host to be considered.
588 * \param variable The name of the variable to be considered.
589 * \param value The new value of the variable.
591 * \see TRACE_host_variable_declare, TRACE_host_variable_add_with_time, TRACE_host_variable_sub_with_time
593 void TRACE_host_variable_set_with_time (double time, const char *host, const char *variable, double value)
595 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SET, nullptr, user_host_variables);
598 /** \ingroup TRACE_user_variables
599 * \brief Add a value to a variable of a host at a given timestamp.
601 * Same as #TRACE_host_variable_add, but let user specify the time used to trace it. Users can specify a time that
602 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
603 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
606 * \param time The timestamp to be used to tag this change of value.
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 value to be added to the variable.
611 * \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_sub_with_time
613 void TRACE_host_variable_add_with_time (double time, const char *host, const char *variable, double value)
615 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_ADD, nullptr, user_host_variables);
618 /** \ingroup TRACE_user_variables
619 * \brief Subtract a value from a variable of a host at a given timestamp.
621 * Same as #TRACE_host_variable_sub, but let user specify the time used to trace it. Users can specify a time that
622 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
623 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
626 * \param time The timestamp to be used to tag this change of value.
627 * \param host The name of the host to be considered.
628 * \param variable The name of the variable to be considered.
629 * \param value The value to be subtracted from the variable.
631 * \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_add_with_time
633 void TRACE_host_variable_sub_with_time (double time, const char *host, const char *variable, double value)
635 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SUB, nullptr, user_host_variables);
638 /** \ingroup TRACE_user_variables
639 * \brief Get declared user host variables
641 * This function should be used to get host variables that were already declared with #TRACE_host_variable_declare or
642 * with #TRACE_host_variable_declare_with_color.
644 * \return A dynar with the declared host variables, must be freed with xbt_dynar_free.
646 xbt_dynar_t TRACE_get_host_variables ()
648 return instr_dict_to_dynar (user_host_variables);
651 /* for link variables */
652 /** \ingroup TRACE_user_variables
653 * \brief Declare a new user variable associated to links.
655 * Declare a user variable that will be associated to links.
656 * A user link variable can be used, for example, to trace user variables such as the number of messages being
657 * transferred through network links. The color associated to this new variable will be random.
659 * \param variable The name of the new variable to be declared.
661 * \see TRACE_link_variable_declare_with_color
663 void TRACE_link_variable_declare (const char *variable)
665 instr_user_variable (0, nullptr, variable, "LINK", 0, INSTR_US_DECLARE, nullptr, user_link_variables);
668 /** \ingroup TRACE_user_variables
669 * \brief Declare a new user variable associated to links with a color.
671 * Same as #TRACE_link_variable_declare, but associated a color to the newly created user link variable. The color
672 * needs to be a string with three numbers separated by spaces in the range [0,1].
673 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
675 * \param variable The name of the new variable to be declared.
676 * \param color The color for the new variable.
678 void TRACE_link_variable_declare_with_color (const char *variable, const char *color)
680 instr_user_variable (0, nullptr, variable, "LINK", 0, INSTR_US_DECLARE, color, user_link_variables);
683 /** \ingroup TRACE_user_variables
684 * \brief Set the value of a variable of a link.
686 * \param link The name of the link to be considered.
687 * \param variable The name of the variable to be considered.
688 * \param value The new value of the variable.
690 * \see TRACE_link_variable_declare, TRACE_link_variable_add, TRACE_link_variable_sub
692 void TRACE_link_variable_set (const char *link, const char *variable, double value)
694 TRACE_link_variable_set_with_time (MSG_get_clock(), link, variable, value);
697 /** \ingroup TRACE_user_variables
698 * \brief Add a value to a variable of a link.
700 * \param link The name of the link to be considered.
701 * \param variable The name of the variable to be considered.
702 * \param value The value to be added to the variable.
704 * \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_sub
706 void TRACE_link_variable_add (const char *link, const char *variable, double value)
708 TRACE_link_variable_add_with_time (MSG_get_clock(), link, variable, value);
711 /** \ingroup TRACE_user_variables
712 * \brief Subtract a value from a variable of a link.
714 * \param link The name of the link to be considered.
715 * \param variable The name of the variable to be considered.
716 * \param value The value to be subtracted from the variable.
718 * \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_add
720 void TRACE_link_variable_sub (const char *link, const char *variable, double value)
722 TRACE_link_variable_sub_with_time (MSG_get_clock(), link, variable, value);
725 /** \ingroup TRACE_user_variables
726 * \brief Set the value of a variable of a link at a given timestamp.
728 * Same as #TRACE_link_variable_set, but let user specify the time used to trace it. Users can specify a time that
729 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
730 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
733 * \param time The timestamp to be used to tag this change of value.
734 * \param link The name of the link to be considered.
735 * \param variable The name of the variable to be considered.
736 * \param value The new value of the variable.
738 * \see TRACE_link_variable_declare, TRACE_link_variable_add_with_time, TRACE_link_variable_sub_with_time
740 void TRACE_link_variable_set_with_time (double time, const char *link, const char *variable, double value)
742 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SET, nullptr, user_link_variables);
745 /** \ingroup TRACE_user_variables
746 * \brief Add a value to a variable of a link at a given timestamp.
748 * Same as #TRACE_link_variable_add, but let user specify the time used to trace it. Users can specify a time that
749 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
750 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
753 * \param time The timestamp to be used to tag this change of value.
754 * \param link The name of the link to be considered.
755 * \param variable The name of the variable to be considered.
756 * \param value The value to be added to the variable.
758 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_sub_with_time
760 void TRACE_link_variable_add_with_time (double time, const char *link, const char *variable, double value)
762 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_ADD, nullptr, user_link_variables);
765 /** \ingroup TRACE_user_variables
766 * \brief Subtract a value from a variable of a link at a given timestamp.
768 * Same as #TRACE_link_variable_sub, but let user specify the time used to trace it. Users can specify a time that
769 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
770 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
773 * \param time The timestamp to be used to tag this change of value.
774 * \param link The name of the link to be considered.
775 * \param variable The name of the variable to be considered.
776 * \param value The value to be subtracted from the variable.
778 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_add_with_time
780 void TRACE_link_variable_sub_with_time (double time, const char *link, const char *variable, double value)
782 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SUB, nullptr, user_link_variables);
785 /* for link variables, but with src and dst used for get_route */
786 /** \ingroup TRACE_user_variables
787 * \brief Set the value of the variable present in the links connecting source and destination.
789 * Same as #TRACE_link_variable_set, but instead of providing the name of link to be considered, provide the source
790 * and destination hosts. All links that are part of the route between source and destination will have the variable
791 * set to the provided value.
793 * \param src The name of the source host for get route.
794 * \param dst The name of the destination host for get route.
795 * \param variable The name of the variable to be considered.
796 * \param value The new value of the variable.
798 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add, TRACE_link_srcdst_variable_sub
800 void TRACE_link_srcdst_variable_set (const char *src, const char *dst, const char *variable, double value)
802 TRACE_link_srcdst_variable_set_with_time (MSG_get_clock(), src, dst, variable, value);
805 /** \ingroup TRACE_user_variables
806 * \brief Add a value to the variable present in the links connecting source and destination.
808 * Same as #TRACE_link_variable_add, but instead of providing the name of link to be considered, provide the source
809 * and destination hosts. All links that are part of the route between source and destination will have the value
810 * passed as parameter added to the current value of the variable name to be considered.
812 * \param src The name of the source host for get route.
813 * \param dst The name of the destination host for get route.
814 * \param variable The name of the variable to be considered.
815 * \param value The value to be added to the variable.
817 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_sub
819 void TRACE_link_srcdst_variable_add (const char *src, const char *dst, const char *variable, double value)
821 TRACE_link_srcdst_variable_add_with_time (MSG_get_clock(), src, dst, variable, value);
824 /** \ingroup TRACE_user_variables
825 * \brief Subtract a value from the variable present in the links connecting source and destination.
827 * Same as #TRACE_link_variable_sub, but instead of providing the name of link to be considered, provide the source
828 * and destination hosts. All links that are part of the route between source and destination will have the value
829 * passed as parameter subtracted from the current value of the variable name to be considered.
831 * \param src The name of the source host for get route.
832 * \param dst The name of the destination host for get route.
833 * \param variable The name of the variable to be considered.
834 * \param value The value to be subtracted from the variable.
836 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_add
838 void TRACE_link_srcdst_variable_sub (const char *src, const char *dst, const char *variable, double value)
840 TRACE_link_srcdst_variable_sub_with_time (MSG_get_clock(), src, dst, variable, value);
843 /** \ingroup TRACE_user_variables
844 * \brief Set the value of the variable present in the links connecting source and destination at a given timestamp.
846 * Same as #TRACE_link_srcdst_variable_set, but let user specify the time used to trace it. Users can specify a time
847 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
848 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
851 * \param time The timestamp to be used to tag this change of value.
852 * \param src The name of the source host for get route.
853 * \param dst The name of the destination host for get route.
854 * \param variable The name of the variable to be considered.
855 * \param value The new value of the variable.
857 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add_with_time, TRACE_link_srcdst_variable_sub_with_time
859 void TRACE_link_srcdst_variable_set_with_time (double time, const char *src, const char *dst, const char *variable,
862 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SET);
865 /** \ingroup TRACE_user_variables
866 * \brief Add a value to the variable present in the links connecting source and destination at a given timestamp.
868 * Same as #TRACE_link_srcdst_variable_add, but let user specify the time used to trace it. Users can specify a time
869 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
870 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
873 * \param time The timestamp to be used to tag this change of value.
874 * \param src The name of the source host for get route.
875 * \param dst The name of the destination host for get route.
876 * \param variable The name of the variable to be considered.
877 * \param value The value to be added to the variable.
879 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_sub_with_time
881 void TRACE_link_srcdst_variable_add_with_time (double time, const char *src, const char *dst, const char *variable,
884 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_ADD);
887 /** \ingroup TRACE_user_variables
888 * \brief Subtract a value from the variable present in the links connecting source and dest. at a given timestamp.
890 * Same as #TRACE_link_srcdst_variable_sub, but let user specify the time used to trace it. Users can specify a time
891 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
892 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
895 * \param time The timestamp to be used to tag this change of value.
896 * \param src The name of the source host for get route.
897 * \param dst The name of the destination host for get route.
898 * \param variable The name of the variable to be considered.
899 * \param value The value to be subtracted from the variable.
901 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_add_with_time
903 void TRACE_link_srcdst_variable_sub_with_time (double time, const char *src, const char *dst, const char *variable,
906 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SUB);
909 /** \ingroup TRACE_user_variables
910 * \brief Get declared user link variables
912 * This function should be used to get link variables that were already declared with #TRACE_link_variable_declare or
913 * with #TRACE_link_variable_declare_with_color.
915 * \return A dynar with the declared link variables, must be freed with xbt_dynar_free.
917 xbt_dynar_t TRACE_get_link_variables ()
919 return instr_dict_to_dynar (user_link_variables);
922 /** \ingroup TRACE_user_variables
923 * \brief Declare a new user state associated to hosts.
925 * Declare a user state that will be associated to hosts.
926 * A user host state can be used to trace application states.
928 * \param state The name of the new state to be declared.
930 * \see TRACE_host_state_declare_value
932 void TRACE_host_state_declare (const char *state)
934 instr_new_user_state_type("HOST", state);
937 /** \ingroup TRACE_user_variables
938 * \brief Declare a new value for a user state associated to hosts.
940 * Declare a value for a state. The color needs to be a string with 3 numbers separated by spaces in the range [0,1].
941 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
943 * \param state The name of the new state to be declared.
944 * \param value The name of the value
945 * \param color The color of the value
947 * \see TRACE_host_state_declare
949 void TRACE_host_state_declare_value (const char *state, const char *value, const char *color)
951 instr_new_value_for_user_state_type (state, value, color);
954 /** \ingroup TRACE_user_variables
955 * \brief Set the user state to the given value.
957 * Change a user state previously declared to the given value.
959 * \param host The name of the host to be considered.
960 * \param state The name of the state previously declared.
961 * \param value The new value of the state.
963 * \see TRACE_host_state_declare, TRACE_host_push_state, TRACE_host_pop_state, TRACE_host_reset_state
965 void TRACE_host_set_state (const char *host, const char *state, const char *value)
967 container_t container = PJ_container_get(host);
968 type_t type = PJ_type_get (state, container->type);
969 val_t val = PJ_value_get_or_new (value, nullptr, type); /* if user didn't declare a value with a color, use nullptr color */
970 new_pajeSetState(MSG_get_clock(), container, type, val);
973 /** \ingroup TRACE_user_variables
974 * \brief Push a new value for a state of a given host.
976 * Change a user state previously declared by pushing the new value to the state.
978 * \param host The name of the host to be considered.
979 * \param state The name of the state previously declared.
980 * \param value The value to be pushed.
982 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_pop_state, TRACE_host_reset_state
984 void TRACE_host_push_state (const char *host, const char *state, const char *value)
986 container_t container = PJ_container_get(host);
987 type_t type = PJ_type_get (state, container->type);
988 val_t val = PJ_value_get_or_new (value, nullptr, type); /* if user didn't declare a value with a color, use nullptr color */
989 new_pajePushState(MSG_get_clock(), container, type, val);
992 /** \ingroup TRACE_user_variables
993 * \brief Pop the last value of a state of a given host.
995 * Change a user state previously declared by removing the last value of the state.
997 * \param host The name of the host to be considered.
998 * \param state The name of the state to be popped.
1000 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_reset_state
1002 void TRACE_host_pop_state (const char *host, const char *state)
1004 container_t container = PJ_container_get(host);
1005 type_t type = PJ_type_get (state, container->type);
1006 new_pajePopState(MSG_get_clock(), container, type);
1009 /** \ingroup TRACE_user_variables
1010 * \brief Reset the state of a given host.
1012 * Clear all previous values of a user state.
1014 * \param host The name of the host to be considered.
1015 * \param state The name of the state to be cleared.
1017 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_pop_state
1019 void TRACE_host_reset_state (const char *host, const char *state)
1021 container_t container = PJ_container_get(host);
1022 type_t type = PJ_type_get (state, container->type);
1023 new_pajeResetState(MSG_get_clock(), container, type);
1026 /** \ingroup TRACE_API
1027 * \brief Get Paje container types that can be mapped to the nodes of a graph.
1029 * This function can be used to create a user made graph configuration file for Triva. Normally, it is used with the
1030 * functions defined in \ref TRACE_user_variables.
1032 * \return A dynar with the types, must be freed with xbt_dynar_free.
1034 xbt_dynar_t TRACE_get_node_types ()
1036 return instr_dict_to_dynar (trivaNodeTypes);
1039 /** \ingroup TRACE_API
1040 * \brief Get Paje container types that can be mapped to the edges of a graph.
1042 * This function can be used to create a user made graph configuration file for Triva. Normally, it is used with the
1043 * functions defined in \ref TRACE_user_variables.
1045 * \return A dynar with the types, must be freed with xbt_dynar_free.
1047 xbt_dynar_t TRACE_get_edge_types ()
1049 return instr_dict_to_dynar (trivaEdgeTypes);
1052 /** \ingroup TRACE_API
1053 * \brief Pauses all tracing activities.
1058 instr_pause_tracing();
1061 /** \ingroup TRACE_API
1062 * \brief Resumes all tracing activities.
1065 void TRACE_resume ()
1067 instr_resume_tracing();