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())
34 if (!TRACE_needs_platform())
37 xbt_dynar_t ret = xbt_dynar_new (sizeof(char*), &xbt_free_ref);
38 xbt_dict_cursor_t cursor = nullptr;
41 xbt_dict_foreach(filter, cursor, name, value) {
42 xbt_dynar_push_as (ret, char*, xbt_strdup(name));
47 /** \ingroup TRACE_category
48 * \brief Declare a new category with a random color.
50 * This function should be used to define a user category. The category can be used to differentiate the tasks that
51 * are created during the simulation (for example, tasks from server1, server2, or request tasks, computation tasks,
52 * communication tasks). All resource utilization (host power and link bandwidth) will be classified according to the
53 * task category. Tasks that do not belong to a category are not traced. The color for the category that is being
54 * declared is random. This function has no effect if a category with the same name has been already declared.
56 * See \ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
58 * \param category The name of the new tracing category to be created.
60 * \see TRACE_category_with_color, MSG_task_set_category, SD_task_set_category
62 void TRACE_category(const char *category)
64 TRACE_category_with_color (category, nullptr);
67 /** \ingroup TRACE_category
68 * \brief Declare a new category with a color.
70 * Same as #TRACE_category, but let user specify a color encoded as a RGB-like string with three floats from 0 to 1.
71 * 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"
72 * as color. This function has no effect if a category with the same name has been already declared.
74 * See \ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
76 * \param category The name of the new tracing category to be created.
77 * \param color The color of the category (see \ref outcomes_vizu to
78 * know how to correctly specify the color)
80 * \see MSG_task_set_category, SD_task_set_category
82 void TRACE_category_with_color (const char *category, const char *color)
85 if (!TRACE_is_enabled())
88 if (!(TRACE_categorized() && category != nullptr))
91 /* if platform is not traced, we can't deal with categories */
92 if (!TRACE_needs_platform())
95 //check if category is already created
96 char *created = static_cast<char*>(xbt_dict_get_or_null(created_categories, category));
99 xbt_dict_set (created_categories, category, xbt_strdup("1"), nullptr);
102 char final_color[INSTR_DEFAULT_STR_SIZE];
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);
110 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
113 XBT_DEBUG("CAT,declare %s, \"%s\" \"%s\"", category, color, final_color);
115 //define the type of this category on top of hosts and links
116 instr_new_variable_type (category, final_color);
119 /** \ingroup TRACE_category
120 * \brief Get declared categories
122 * This function should be used to get categories that were already declared with #TRACE_category or with
123 * #TRACE_category_with_color.
125 * See \ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
127 * \return A dynar with the declared categories, must be freed with xbt_dynar_free.
129 * \see MSG_task_set_category, SD_task_set_category
131 xbt_dynar_t TRACE_get_categories ()
133 if (!TRACE_is_enabled())
135 if (!TRACE_categorized())
138 return instr_dict_to_dynar (created_categories);
141 /** \ingroup TRACE_mark
142 * \brief Declare a new type for tracing mark.
144 * This function declares a new Paje event type in the trace file that can be used by simulators to declare
145 * application-level marks. This function is independent of which API is used in SimGrid.
147 * \param mark_type The name of the new type.
151 void TRACE_declare_mark(const char *mark_type)
154 if (!TRACE_is_enabled())
157 /* if platform is not traced, we don't allow marks */
158 if (!TRACE_needs_platform())
162 THROWF (tracing_error, 1, "mark_type is nullptr");
164 //check if mark_type is already declared
165 char *created = static_cast<char*>(xbt_dict_get_or_null(declared_marks, mark_type));
167 THROWF (tracing_error, 1, "mark_type with name (%s) is already declared", mark_type);
170 XBT_DEBUG("MARK,declare %s", mark_type);
171 PJ_type_event_new(mark_type, PJ_type_get_root());
172 xbt_dict_set (declared_marks, mark_type, xbt_strdup("1"), nullptr);
175 /** \ingroup TRACE_mark
176 * \brief Declare a new colored value for a previously declared mark type.
178 * This function declares a new colored value for a Paje event type in the trace file that can be used by simulators to
179 * declare application-level marks. This function is independent of which API is used in SimGrid. The color needs to be
180 * a string with three numbers separated by spaces in the range [0,1].
181 * 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
182 * be white ("1 1 1").
184 * \param mark_type The name of the new type.
185 * \param mark_value The name of the new value for this type.
186 * \param mark_color The color of the new value for this type.
190 void TRACE_declare_mark_value_with_color (const char *mark_type, const char *mark_value, const char *mark_color)
193 if (!TRACE_is_enabled())
196 /* if platform is not traced, we don't allow marks */
197 if (!TRACE_needs_platform())
201 THROWF (tracing_error, 1, "mark_type is nullptr");
203 THROWF (tracing_error, 1, "mark_value is nullptr");
205 type_t type = PJ_type_get (mark_type, PJ_type_get_root());
207 THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
210 char white[INSTR_DEFAULT_STR_SIZE] = "1.0 1.0 1.0";
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 type in the trace file that can be used by simulators to declare
222 * application-level marks. This function is independent of which API is used in SimGrid. Calling this function is the
223 * same as calling \ref TRACE_declare_mark_value_with_color with a nullptr color.
225 * \param mark_type The name of the new type.
226 * \param mark_value The name of the new value for this type.
230 void TRACE_declare_mark_value (const char *mark_type, const char *mark_value)
232 TRACE_declare_mark_value_with_color (mark_type, mark_value, nullptr);
236 * \ingroup TRACE_mark
237 * \brief Create a new instance of a tracing mark type.
239 * This function creates a mark in the trace file. The first parameter had to be previously declared using
240 * #TRACE_declare_mark, the second is the identifier for this mark instance. We recommend that the mark_value is a
241 * unique value for the whole simulation. Nevertheless, this is not a strong requirement: the trace will be valid even
242 * if there are multiple mark identifiers for the same trace.
244 * \param mark_type The name of the type for which the new instance will belong.
245 * \param mark_value The name of the new instance mark.
247 * \see TRACE_declare_mark
249 void TRACE_mark(const char *mark_type, const char *mark_value)
252 if (!TRACE_is_enabled())
255 /* if platform is not traced, we don't allow marks */
256 if (!TRACE_needs_platform())
260 THROWF (tracing_error, 1, "mark_type is nullptr");
262 THROWF (tracing_error, 1, "mark_value is nullptr");
264 //check if mark_type is already declared
265 type_t type = PJ_type_get (mark_type, PJ_type_get_root());
267 THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
270 val_t value = PJ_value_get (mark_value, type);
271 XBT_DEBUG("MARK %s %s", mark_type, mark_value);
272 new_pajeNewEvent (MSG_get_clock(), PJ_container_get_root(), type, value);
275 /** \ingroup TRACE_mark
276 * \brief Get declared marks
278 * This function should be used to get marks that were already declared with #TRACE_declare_mark.
280 * \return A dynar with the declared marks, must be freed with xbt_dynar_free.
282 xbt_dynar_t TRACE_get_marks (void)
284 if (!TRACE_is_enabled())
287 return instr_dict_to_dynar (declared_marks);
290 static void instr_user_variable(double time, const char *resource, const char *variable, const char *father_type,
291 double value, InstrUserVariable what, const char *color, xbt_dict_t filter)
294 if (!TRACE_is_enabled())
297 /* if platform is not traced, we don't allow user variables */
298 if (!TRACE_needs_platform())
301 //check if variable is already declared
302 char *created = (char*)xbt_dict_get_or_null(filter, variable);
303 if (what == INSTR_US_DECLARE){
304 if (created){//already declared
307 xbt_dict_set (filter, variable, xbt_strdup("1"), nullptr);
308 instr_new_user_variable_type (father_type, variable, color);
311 if (!created){//not declared, ignore
315 snprintf(valuestr, 100, "%g", value);
316 container_t container = PJ_container_get(resource);
317 type_t type = PJ_type_get (variable, container->type);
320 new_pajeSetVariable(time, container, type, value);
323 new_pajeAddVariable(time, container, type, value);
326 new_pajeSubVariable(time, container, type, value);
336 static void instr_user_srcdst_variable(double time, const char *src, const char *dst, const char *variable,
337 const char *father_type, double value, InstrUserVariable what)
339 sg_netcard_t src_elm = sg_netcard_by_name_or_null(src);
341 xbt_die("Element '%s' not found!",src);
343 sg_netcard_t dst_elm = sg_netcard_by_name_or_null(dst);
345 xbt_die("Element '%s' not found!",dst);
347 std::vector<Link*> *route = new std::vector<Link*>();
348 routing_platf->getRouteAndLatency (src_elm, dst_elm, route,nullptr);
349 for (auto link : *route)
350 instr_user_variable (time, link->getName(), variable, father_type, value, what, nullptr, user_link_variables);
354 /** \ingroup TRACE_API
355 * \brief Creates a file with the topology of the platform file used for the simulator.
357 * The graph topology will have the following properties: all hosts, links and routers of the platform file are mapped
358 * to graph nodes; routes are mapped to edges.
359 * The platform's AS are not represented in the output.
361 * \param filename The name of the file that will hold the graph.
363 * \return 1 of successful, 0 otherwise.
365 int TRACE_platform_graph_export_graphviz (const char *filename)
367 /* returns 1 if successful, 0 otherwise */
368 if (!TRACE_is_enabled())
370 xbt_graph_t g = instr_routing_platform_graph();
373 instr_routing_platform_graph_export_graphviz (g, filename);
374 xbt_graph_free_graph(g, xbt_free_f, xbt_free_f, nullptr);
379 * Derived functions that use instr_user_variable and TRACE_user_srcdst_variable. They were previously defined as
380 * pre-processors directives, but were transformed into functions so the user can track them using gdb.
383 /* for VM variables */
384 /** \ingroup TRACE_user_variables
385 * \brief Declare a new user variable associated to VMs.
387 * Declare a user variable that will be associated to VMs. A user vm variable can be used to trace user variables
388 * such as the number of tasks in a VM, the number of clients in an application (for VMs), and so on. The color
389 * associated to this new variable will be random.
391 * \param variable The name of the new variable to be declared.
393 * \see TRACE_vm_variable_declare_with_color
395 void TRACE_vm_variable_declare (const char *variable)
397 instr_user_variable(0, nullptr, variable, "MSG_VM", 0, INSTR_US_DECLARE, nullptr, user_vm_variables);
400 /** \ingroup TRACE_user_variables
401 * \brief Declare a new user variable associated to VMs with a color.
403 * Same as #TRACE_vm_variable_declare, but associated a color to the newly created user host variable. The color needs
404 * to be a string with three numbers separated by spaces in the range [0,1].
405 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
407 * \param variable The name of the new variable to be declared.
408 * \param color The color for the new variable.
410 void TRACE_vm_variable_declare_with_color (const char *variable, const char *color)
412 instr_user_variable(0, nullptr, variable, "MSG_VM", 0, INSTR_US_DECLARE, color, user_vm_variables);
415 /** \ingroup TRACE_user_variables
416 * \brief Set the value of a variable of a host.
418 * \param vm The name of the VM to be considered.
419 * \param variable The name of the variable to be considered.
420 * \param value The new value of the variable.
422 * \see TRACE_vm_variable_declare, TRACE_vm_variable_add, TRACE_vm_variable_sub
424 void TRACE_vm_variable_set (const char *vm, const char *variable, double value)
426 TRACE_vm_variable_set_with_time (MSG_get_clock(), vm, variable, value);
429 /** \ingroup TRACE_user_variables
430 * \brief Add a value to a variable of a VM.
432 * \param vm The name of the VM to be considered.
433 * \param variable The name of the variable to be considered.
434 * \param value The value to be added to the variable.
436 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_sub
438 void TRACE_vm_variable_add (const char *vm, const char *variable, double value)
440 TRACE_vm_variable_add_with_time (MSG_get_clock(), vm, variable, value);
443 /** \ingroup TRACE_user_variables
444 * \brief Subtract a value from a variable of a VM.
446 * \param vm The name of the vm to be considered.
447 * \param variable The name of the variable to be considered.
448 * \param value The value to be subtracted from the variable.
450 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_add
452 void TRACE_vm_variable_sub (const char *vm, const char *variable, double value)
454 TRACE_vm_variable_sub_with_time (MSG_get_clock(), vm, variable, value);
457 /** \ingroup TRACE_user_variables
458 * \brief Set the value of a variable of a VM at a given timestamp.
460 * Same as #TRACE_vm_variable_set, but let user specify the time used to trace it. Users can specify a time that
461 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
462 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
465 * \param time The timestamp to be used to tag this change of value.
466 * \param vm The name of the VM to be considered.
467 * \param variable The name of the variable to be considered.
468 * \param value The new value of the variable.
470 * \see TRACE_vm_variable_declare, TRACE_vm_variable_add_with_time, TRACE_vm_variable_sub_with_time
472 void TRACE_vm_variable_set_with_time (double time, const char *vm, const char *variable, double value)
474 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_SET, nullptr, user_vm_variables);
477 /** \ingroup TRACE_user_variables
478 * \brief Add a value to a variable of a VM at a given timestamp.
480 * Same as #TRACE_vm_variable_add, but let user specify the time used to trace it. Users can specify a time that
481 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
482 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
485 * \param time The timestamp to be used to tag this change of value.
486 * \param vm The name of the VM to be considered.
487 * \param variable The name of the variable to be considered.
488 * \param value The value to be added to the variable.
490 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_sub_with_time
492 void TRACE_vm_variable_add_with_time (double time, const char *vm, const char *variable, double value)
494 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_ADD, nullptr, user_vm_variables);
497 /** \ingroup TRACE_user_variables
498 * \brief Subtract a value from a variable of a VM at a given timestamp.
500 * Same as #TRACE_vm_variable_sub, but let user specify the time used to trace it. Users can specify a time that
501 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
502 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
505 * \param time The timestamp to be used to tag this change of value.
506 * \param vm The name of the VM to be considered.
507 * \param variable The name of the variable to be considered.
508 * \param value The value to be subtracted from the variable.
510 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_add_with_time
512 void TRACE_vm_variable_sub_with_time (double time, const char *vm, const char *variable, double value)
514 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_SUB, nullptr, user_vm_variables);
517 /** \ingroup TRACE_user_variables
518 * \brief Get declared user vm variables
520 * This function should be used to get VM variables that were already declared with #TRACE_vm_variable_declare or with
521 * #TRACE_vm_variable_declare_with_color.
523 * \return A dynar with the declared host variables, must be freed with xbt_dynar_free.
525 xbt_dynar_t TRACE_get_vm_variables (void)
527 return instr_dict_to_dynar (user_vm_variables);
530 /* for host variables */
531 /** \ingroup TRACE_user_variables
532 * \brief Declare a new user variable associated to hosts.
534 * Declare a user variable that will be associated to hosts.
535 * A user host variable can be used to trace user variables such as the number of tasks in a server, the number of
536 * clients in an application (for hosts), and so on. The color associated to this new variable will be random.
538 * \param variable The name of the new variable to be declared.
540 * \see TRACE_host_variable_declare_with_color
542 void TRACE_host_variable_declare (const char *variable)
544 instr_user_variable(0, nullptr, variable, "HOST", 0, INSTR_US_DECLARE, nullptr, user_host_variables);
547 /** \ingroup TRACE_user_variables
548 * \brief Declare a new user variable associated to hosts with a color.
550 * Same as #TRACE_host_variable_declare, but associated a color to the newly created user host variable. The color
551 * needs to be a string with three numbers separated by spaces in the range [0,1].
552 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
554 * \param variable The name of the new variable to be declared.
555 * \param color The color for the new variable.
557 void TRACE_host_variable_declare_with_color (const char *variable, const char *color)
559 instr_user_variable(0, nullptr, variable, "HOST", 0, INSTR_US_DECLARE, color, user_host_variables);
562 /** \ingroup TRACE_user_variables
563 * \brief Set the value of a variable of a host.
565 * \param host The name of the host to be considered.
566 * \param variable The name of the variable to be considered.
567 * \param value The new value of the variable.
569 * \see TRACE_host_variable_declare, TRACE_host_variable_add, TRACE_host_variable_sub
571 void TRACE_host_variable_set (const char *host, const char *variable, double value)
573 TRACE_host_variable_set_with_time (MSG_get_clock(), host, variable, value);
576 /** \ingroup TRACE_user_variables
577 * \brief Add a value to a variable of a host.
579 * \param host The name of the host to be considered.
580 * \param variable The name of the variable to be considered.
581 * \param value The value to be added to the variable.
583 * \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_sub
585 void TRACE_host_variable_add (const char *host, const char *variable, double value)
587 TRACE_host_variable_add_with_time (MSG_get_clock(), host, variable, value);
590 /** \ingroup TRACE_user_variables
591 * \brief Subtract a value from a variable of a host.
593 * \param host The name of the host to be considered.
594 * \param variable The name of the variable to be considered.
595 * \param value The value to be subtracted from the variable.
597 * \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_add
599 void TRACE_host_variable_sub (const char *host, const char *variable, double value)
601 TRACE_host_variable_sub_with_time (MSG_get_clock(), host, variable, value);
604 /** \ingroup TRACE_user_variables
605 * \brief Set the value of a variable of a host at a given timestamp.
607 * Same as #TRACE_host_variable_set, but let user specify the time used to trace it. Users can specify a time that
608 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
609 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
612 * \param time The timestamp to be used to tag this change of value.
613 * \param host The name of the host to be considered.
614 * \param variable The name of the variable to be considered.
615 * \param value The new value of the variable.
617 * \see TRACE_host_variable_declare, TRACE_host_variable_add_with_time, TRACE_host_variable_sub_with_time
619 void TRACE_host_variable_set_with_time (double time, const char *host, const char *variable, double value)
621 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SET, nullptr, user_host_variables);
624 /** \ingroup TRACE_user_variables
625 * \brief Add a value to a variable of a host at a given timestamp.
627 * Same as #TRACE_host_variable_add, but let user specify the time used to trace it. Users can specify a time that
628 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
629 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
632 * \param time The timestamp to be used to tag this change of value.
633 * \param host The name of the host to be considered.
634 * \param variable The name of the variable to be considered.
635 * \param value The value to be added to the variable.
637 * \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_sub_with_time
639 void TRACE_host_variable_add_with_time (double time, const char *host, const char *variable, double value)
641 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_ADD, nullptr, user_host_variables);
644 /** \ingroup TRACE_user_variables
645 * \brief Subtract a value from a variable of a host at a given timestamp.
647 * Same as #TRACE_host_variable_sub, but let user specify the time used to trace it. Users can specify a time that
648 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
649 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
652 * \param time The timestamp to be used to tag this change of value.
653 * \param host The name of the host to be considered.
654 * \param variable The name of the variable to be considered.
655 * \param value The value to be subtracted from the variable.
657 * \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_add_with_time
659 void TRACE_host_variable_sub_with_time (double time, const char *host, const char *variable, double value)
661 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SUB, nullptr, user_host_variables);
664 /** \ingroup TRACE_user_variables
665 * \brief Get declared user host variables
667 * This function should be used to get host variables that were already declared with #TRACE_host_variable_declare or
668 * with #TRACE_host_variable_declare_with_color.
670 * \return A dynar with the declared host variables, must be freed with xbt_dynar_free.
672 xbt_dynar_t TRACE_get_host_variables (void)
674 return instr_dict_to_dynar (user_host_variables);
677 /* for link variables */
678 /** \ingroup TRACE_user_variables
679 * \brief Declare a new user variable associated to links.
681 * Declare a user variable that will be associated to links.
682 * A user link variable can be used, for example, to trace user variables such as the number of messages being
683 * transferred through network links. The color associated to this new variable will be random.
685 * \param variable The name of the new variable to be declared.
687 * \see TRACE_link_variable_declare_with_color
689 void TRACE_link_variable_declare (const char *variable)
691 instr_user_variable (0, nullptr, variable, "LINK", 0, INSTR_US_DECLARE, nullptr, user_link_variables);
694 /** \ingroup TRACE_user_variables
695 * \brief Declare a new user variable associated to links with a color.
697 * Same as #TRACE_link_variable_declare, but associated a color to the newly created user link variable. The color
698 * needs to be a string with three numbers separated by spaces in the range [0,1].
699 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
701 * \param variable The name of the new variable to be declared.
702 * \param color The color for the new variable.
704 void TRACE_link_variable_declare_with_color (const char *variable, const char *color)
706 instr_user_variable (0, nullptr, variable, "LINK", 0, INSTR_US_DECLARE, color, user_link_variables);
709 /** \ingroup TRACE_user_variables
710 * \brief Set the value of a variable of a link.
712 * \param link The name of the link to be considered.
713 * \param variable The name of the variable to be considered.
714 * \param value The new value of the variable.
716 * \see TRACE_link_variable_declare, TRACE_link_variable_add, TRACE_link_variable_sub
718 void TRACE_link_variable_set (const char *link, const char *variable, double value)
720 TRACE_link_variable_set_with_time (MSG_get_clock(), link, variable, value);
723 /** \ingroup TRACE_user_variables
724 * \brief Add a value to a variable of a link.
726 * \param link The name of the link to be considered.
727 * \param variable The name of the variable to be considered.
728 * \param value The value to be added to the variable.
730 * \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_sub
732 void TRACE_link_variable_add (const char *link, const char *variable, double value)
734 TRACE_link_variable_add_with_time (MSG_get_clock(), link, variable, value);
737 /** \ingroup TRACE_user_variables
738 * \brief Subtract a value from a variable of a link.
740 * \param link The name of the link to be considered.
741 * \param variable The name of the variable to be considered.
742 * \param value The value to be subtracted from the variable.
744 * \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_add
746 void TRACE_link_variable_sub (const char *link, const char *variable, double value)
748 TRACE_link_variable_sub_with_time (MSG_get_clock(), link, variable, value);
751 /** \ingroup TRACE_user_variables
752 * \brief Set the value of a variable of a link at a given timestamp.
754 * Same as #TRACE_link_variable_set, but let user specify the time used to trace it. Users can specify a time that
755 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
756 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
759 * \param time The timestamp to be used to tag this change of value.
760 * \param link The name of the link to be considered.
761 * \param variable The name of the variable to be considered.
762 * \param value The new value of the variable.
764 * \see TRACE_link_variable_declare, TRACE_link_variable_add_with_time, TRACE_link_variable_sub_with_time
766 void TRACE_link_variable_set_with_time (double time, const char *link, const char *variable, double value)
768 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SET, nullptr, user_link_variables);
771 /** \ingroup TRACE_user_variables
772 * \brief Add a value to a variable of a link at a given timestamp.
774 * Same as #TRACE_link_variable_add, but let user specify the time used to trace it. Users can specify a time that
775 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
776 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
779 * \param time The timestamp to be used to tag this change of value.
780 * \param link The name of the link to be considered.
781 * \param variable The name of the variable to be considered.
782 * \param value The value to be added to the variable.
784 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_sub_with_time
786 void TRACE_link_variable_add_with_time (double time, const char *link, const char *variable, double value)
788 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_ADD, nullptr, user_link_variables);
791 /** \ingroup TRACE_user_variables
792 * \brief Subtract a value from a variable of a link at a given timestamp.
794 * Same as #TRACE_link_variable_sub, but let user specify the time used to trace it. Users can specify a time that
795 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
796 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
799 * \param time The timestamp to be used to tag this change of value.
800 * \param link The name of the link to be considered.
801 * \param variable The name of the variable to be considered.
802 * \param value The value to be subtracted from the variable.
804 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_add_with_time
806 void TRACE_link_variable_sub_with_time (double time, const char *link, const char *variable, double value)
808 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SUB, nullptr, user_link_variables);
811 /* for link variables, but with src and dst used for get_route */
812 /** \ingroup TRACE_user_variables
813 * \brief Set the value of the variable present in the links connecting source and destination.
815 * Same as #TRACE_link_variable_set, but instead of providing the name of link to be considered, provide the source
816 * and destination hosts. All links that are part of the route between source and destination will have the variable
817 * set to the provided value.
819 * \param src The name of the source host for get route.
820 * \param dst The name of the destination host for get route.
821 * \param variable The name of the variable to be considered.
822 * \param value The new value of the variable.
824 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add, TRACE_link_srcdst_variable_sub
826 void TRACE_link_srcdst_variable_set (const char *src, const char *dst, const char *variable, double value)
828 TRACE_link_srcdst_variable_set_with_time (MSG_get_clock(), src, dst, variable, value);
831 /** \ingroup TRACE_user_variables
832 * \brief Add a value to the variable present in the links connecting source and destination.
834 * Same as #TRACE_link_variable_add, but instead of providing the name of link to be considered, provide the source
835 * and destination hosts. All links that are part of the route between source and destination will have the value
836 * passed as parameter added to the current value of the variable name to be considered.
838 * \param src The name of the source host for get route.
839 * \param dst The name of the destination host for get route.
840 * \param variable The name of the variable to be considered.
841 * \param value The value to be added to the variable.
843 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_sub
845 void TRACE_link_srcdst_variable_add (const char *src, const char *dst, const char *variable, double value)
847 TRACE_link_srcdst_variable_add_with_time (MSG_get_clock(), src, dst, variable, value);
850 /** \ingroup TRACE_user_variables
851 * \brief Subtract a value from the variable present in the links connecting source and destination.
853 * Same as #TRACE_link_variable_sub, but instead of providing the name of link to be considered, provide the source
854 * and destination hosts. All links that are part of the route between source and destination will have the value
855 * passed as parameter subtracted from the current value of the variable name to be considered.
857 * \param src The name of the source host for get route.
858 * \param dst The name of the destination host for get route.
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_srcdst_variable_set, TRACE_link_srcdst_variable_add
864 void TRACE_link_srcdst_variable_sub (const char *src, const char *dst, const char *variable, double value)
866 TRACE_link_srcdst_variable_sub_with_time (MSG_get_clock(), src, dst, variable, value);
869 /** \ingroup TRACE_user_variables
870 * \brief Set the value of the variable present in the links connecting source and destination at a given timestamp.
872 * Same as #TRACE_link_srcdst_variable_set, but let user specify the time used to trace it. Users can specify a time
873 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
874 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
877 * \param time The timestamp to be used to tag this change of 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_with_time, TRACE_link_srcdst_variable_sub_with_time
885 void TRACE_link_srcdst_variable_set_with_time (double time, const char *src, const char *dst, const char *variable,
888 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SET);
891 /** \ingroup TRACE_user_variables
892 * \brief Add a value to the variable present in the links connecting source and destination at a given timestamp.
894 * Same as #TRACE_link_srcdst_variable_add, but let user specify the time used to trace it. Users can specify a time
895 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
896 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
899 * \param time The timestamp to be used to tag this change of value.
900 * \param src The name of the source host for get route.
901 * \param dst The name of the destination host for get route.
902 * \param variable The name of the variable to be considered.
903 * \param value The value to be added to the variable.
905 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_sub_with_time
907 void TRACE_link_srcdst_variable_add_with_time (double time, const char *src, const char *dst, const char *variable,
910 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_ADD);
913 /** \ingroup TRACE_user_variables
914 * \brief Subtract a value from the variable present in the links connecting source and dest. at a given timestamp.
916 * Same as #TRACE_link_srcdst_variable_sub, but let user specify the time used to trace it. Users can specify a time
917 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
918 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
921 * \param time The timestamp to be used to tag this change of value.
922 * \param src The name of the source host for get route.
923 * \param dst The name of the destination host for get route.
924 * \param variable The name of the variable to be considered.
925 * \param value The value to be subtracted from the variable.
927 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_add_with_time
929 void TRACE_link_srcdst_variable_sub_with_time (double time, const char *src, const char *dst, const char *variable,
932 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SUB);
935 /** \ingroup TRACE_user_variables
936 * \brief Get declared user link variables
938 * This function should be used to get link variables that were already declared with #TRACE_link_variable_declare or
939 * with #TRACE_link_variable_declare_with_color.
941 * \return A dynar with the declared link variables, must be freed with xbt_dynar_free.
943 xbt_dynar_t TRACE_get_link_variables (void)
945 return instr_dict_to_dynar (user_link_variables);
948 /** \ingroup TRACE_user_variables
949 * \brief Declare a new user state associated to hosts.
951 * Declare a user state that will be associated to hosts.
952 * A user host state can be used to trace application states.
954 * \param state The name of the new state to be declared.
956 * \see TRACE_host_state_declare_value
958 void TRACE_host_state_declare (const char *state)
960 instr_new_user_state_type("HOST", state);
963 /** \ingroup TRACE_user_variables
964 * \brief Declare a new value for a user state associated to hosts.
966 * Declare a value for a state. The color needs to be a string with 3 numbers separated by spaces in the range [0,1].
967 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
969 * \param state The name of the new state to be declared.
970 * \param value The name of the value
971 * \param color The color of the value
973 * \see TRACE_host_state_declare
975 void TRACE_host_state_declare_value (const char *state, const char *value, const char *color)
977 instr_new_value_for_user_state_type (state, value, color);
980 /** \ingroup TRACE_user_variables
981 * \brief Set the user state to the given value.
983 * Change a user state previously declared to the given value.
985 * \param host The name of the host to be considered.
986 * \param state The name of the state previously declared.
987 * \param value The new value of the state.
989 * \see TRACE_host_state_declare, TRACE_host_push_state, TRACE_host_pop_state, TRACE_host_reset_state
991 void TRACE_host_set_state (const char *host, const char *state, const char *value)
993 container_t container = PJ_container_get(host);
994 type_t type = PJ_type_get (state, container->type);
995 val_t val = PJ_value_get_or_new (value, nullptr, type); /* if user didn't declare a value with a color, use nullptr color */
996 new_pajeSetState(MSG_get_clock(), container, type, val);
999 /** \ingroup TRACE_user_variables
1000 * \brief Push a new value for a state of a given host.
1002 * Change a user state previously declared by pushing the new value to the state.
1004 * \param host The name of the host to be considered.
1005 * \param state The name of the state previously declared.
1006 * \param value The value to be pushed.
1008 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_pop_state, TRACE_host_reset_state
1010 void TRACE_host_push_state (const char *host, const char *state, const char *value)
1012 container_t container = PJ_container_get(host);
1013 type_t type = PJ_type_get (state, container->type);
1014 val_t val = PJ_value_get_or_new (value, nullptr, type); /* if user didn't declare a value with a color, use nullptr color */
1015 new_pajePushState(MSG_get_clock(), container, type, val);
1018 /** \ingroup TRACE_user_variables
1019 * \brief Pop the last value of a state of a given host.
1021 * Change a user state previously declared by removing the last value of the state.
1023 * \param host The name of the host to be considered.
1024 * \param state The name of the state to be popped.
1026 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_reset_state
1028 void TRACE_host_pop_state (const char *host, const char *state)
1030 container_t container = PJ_container_get(host);
1031 type_t type = PJ_type_get (state, container->type);
1032 new_pajePopState(MSG_get_clock(), container, type);
1035 /** \ingroup TRACE_user_variables
1036 * \brief Reset the state of a given host.
1038 * Clear all previous values of a user state.
1040 * \param host The name of the host to be considered.
1041 * \param state The name of the state to be cleared.
1043 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_pop_state
1045 void TRACE_host_reset_state (const char *host, const char *state)
1047 container_t container = PJ_container_get(host);
1048 type_t type = PJ_type_get (state, container->type);
1049 new_pajeResetState(MSG_get_clock(), container, type);
1052 /** \ingroup TRACE_API
1053 * \brief Get Paje container types that can be mapped to the nodes of a graph.
1055 * This function can be used to create a user made graph configuration file for Triva. Normally, it is used with the
1056 * functions defined in \ref TRACE_user_variables.
1058 * \return A dynar with the types, must be freed with xbt_dynar_free.
1060 xbt_dynar_t TRACE_get_node_types ()
1062 return instr_dict_to_dynar (trivaNodeTypes);
1065 /** \ingroup TRACE_API
1066 * \brief Get Paje container types that can be mapped to the edges of a graph.
1068 * This function can be used to create a user made graph configuration file for Triva. Normally, it is used with the
1069 * functions defined in \ref TRACE_user_variables.
1071 * \return A dynar with the types, must be freed with xbt_dynar_free.
1073 xbt_dynar_t TRACE_get_edge_types ()
1075 return instr_dict_to_dynar (trivaEdgeTypes);
1078 /** \ingroup TRACE_API
1079 * \brief Pauses all tracing activities.
1084 instr_pause_tracing();
1087 /** \ingroup TRACE_API
1088 * \brief Resumes all tracing activities.
1091 void TRACE_resume ()
1093 instr_resume_tracing();