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/instr/instr_private.h"
9 #include "src/kernel/routing/NetCard.hpp"
10 #include "src/surf/network_interface.hpp"
11 #include "src/surf/surf_private.h"
12 #include "surf/surf.h"
21 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API");
23 xbt_dict_t created_categories = nullptr;
24 xbt_dict_t declared_marks = nullptr;
25 xbt_dict_t user_host_variables = nullptr;
26 xbt_dict_t user_vm_variables = nullptr;
27 xbt_dict_t user_link_variables = nullptr;
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() || !TRACE_needs_platform())
36 xbt_dynar_t ret = xbt_dynar_new (sizeof(char*), &xbt_free_ref);
37 xbt_dict_cursor_t cursor = nullptr;
40 xbt_dict_foreach(filter, cursor, name, value) {
41 xbt_dynar_push_as (ret, char*, xbt_strdup(name));
46 /** \ingroup TRACE_category
47 * \brief Declare a new category with a random color.
49 * This function should be used to define a user category. The category can be used to differentiate the tasks that
50 * are created during the simulation (for example, tasks from server1, server2, or request tasks, computation tasks,
51 * communication tasks). All resource utilization (host power and link bandwidth) will be classified according to the
52 * task category. Tasks that do not belong to a category are not traced. The color for the category that is being
53 * declared is random. This function has no effect if a category with the same name has been already declared.
55 * See \ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
57 * \param category The name of the new tracing category to be created.
59 * \see TRACE_category_with_color, MSG_task_set_category
61 void TRACE_category(const char *category)
63 TRACE_category_with_color (category, nullptr);
66 /** \ingroup TRACE_category
67 * \brief Declare a new category with a color.
69 * Same as #TRACE_category, but let user specify a color encoded as a RGB-like string with three floats from 0 to 1.
70 * 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"
71 * as color. This function has no effect if a category with the same name has been already declared.
73 * See \ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
75 * \param category The name of the new tracing category to be created.
76 * \param color The color of the category (see \ref outcomes_vizu to
77 * know how to correctly specify the color)
79 * \see MSG_task_set_category
81 void TRACE_category_with_color (const char *category, const char *color)
83 /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with categories */
84 if (!TRACE_is_enabled() || !TRACE_needs_platform())
87 if (!(TRACE_categorized() && category != nullptr))
90 //check if category is already created
91 if (xbt_dict_get_or_null(created_categories, category) != nullptr)
94 xbt_dict_set (created_categories, category, xbt_strdup("1"), nullptr);
97 char final_color[INSTR_DEFAULT_STR_SIZE];
99 //generate a random color
100 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%f %f %f", /*red*/drand48(), /*green*/drand48(), /*blue*/drand48());
102 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
105 XBT_DEBUG("CAT,declare %s, \"%s\" \"%s\"", category, color, final_color);
107 //define the type of this category on top of hosts and links
108 instr_new_variable_type (category, final_color);
111 /** \ingroup TRACE_category
112 * \brief Get declared categories
114 * This function should be used to get categories declared with #TRACE_category or with #TRACE_category_with_color.
116 * See \ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
118 * \return A dynar with the declared categories, must be freed with xbt_dynar_free.
120 * \see MSG_task_set_category
122 xbt_dynar_t TRACE_get_categories ()
124 if (!TRACE_is_enabled() || !TRACE_categorized())
127 return instr_dict_to_dynar (created_categories);
130 /** \ingroup TRACE_mark
131 * \brief Declare a new type for tracing mark.
133 * This function declares a new Paje event type in the trace file that can be used by simulators to declare
134 * application-level marks. This function is independent of which API is used in SimGrid.
136 * \param mark_type The name of the new type.
140 void TRACE_declare_mark(const char *mark_type)
142 /* safe switchs. tracing has to be activated and if platform is not traced, we can't deal with marks */
143 if (!TRACE_is_enabled() || !TRACE_needs_platform())
147 THROWF (tracing_error, 1, "mark_type is nullptr");
149 //check if mark_type is already declared
150 if (xbt_dict_get_or_null(declared_marks, mark_type) != nullptr)
151 THROWF (tracing_error, 1, "mark_type with name (%s) is already declared", mark_type);
153 XBT_DEBUG("MARK,declare %s", mark_type);
154 PJ_type_event_new(mark_type, PJ_type_get_root());
155 xbt_dict_set (declared_marks, mark_type, xbt_strdup("1"), nullptr);
158 /** \ingroup TRACE_mark
159 * \brief Declare a new colored value for a previously declared mark type.
161 * This function declares a new colored value for a Paje event type in the trace file that can be used by simulators to
162 * declare application-level marks. This function is independent of which API is used in SimGrid. The color needs to be
163 * a string with three numbers separated by spaces in the range [0,1]. A light-gray color can be specified using
164 * "0.7 0.7 0.7" as color. If a nullptr color is provided, the color used will be white ("1 1 1").
166 * \param mark_type The name of the new type.
167 * \param mark_value The name of the new value for this type.
168 * \param mark_color The color of the new value for this type.
172 void TRACE_declare_mark_value_with_color (const char *mark_type, const char *mark_value, const char *mark_color)
174 /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
175 if (!TRACE_is_enabled() || !TRACE_needs_platform())
179 THROWF (tracing_error, 1, "mark_type is nullptr");
181 THROWF (tracing_error, 1, "mark_value is nullptr");
183 type_t type = PJ_type_get (mark_type, PJ_type_get_root());
185 THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
187 char white[INSTR_DEFAULT_STR_SIZE] = "1.0 1.0 1.0";
191 XBT_DEBUG("MARK,declare_value %s %s %s", mark_type, mark_value, mark_color);
192 PJ_value_new (mark_value, mark_color, type);
195 /** \ingroup TRACE_mark
196 * \brief Declare a new value for a previously declared mark type.
198 * This function declares a new value for a Paje event type in the trace file that can be used by simulators to declare
199 * application-level marks. This function is independent of which API is used in SimGrid.
201 * \param mark_type The name of the new type.
202 * \param mark_value The name of the new value for this type.
206 void TRACE_declare_mark_value (const char *mark_type, const char *mark_value)
208 TRACE_declare_mark_value_with_color (mark_type, mark_value, nullptr);
212 * \ingroup TRACE_mark
213 * \brief Create a new instance of a tracing mark type.
215 * This function creates a mark in the trace file. The first parameter had to be previously declared using
216 * #TRACE_declare_mark, the second is the identifier for this mark instance. We recommend that the mark_value is a
217 * unique value for the whole simulation. Nevertheless, this is not a strong requirement: the trace will be valid even
218 * if there are multiple mark identifiers for the same trace.
220 * \param mark_type The name of the type for which the new instance will belong.
221 * \param mark_value The name of the new instance mark.
223 * \see TRACE_declare_mark
225 void TRACE_mark(const char *mark_type, const char *mark_value)
227 /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
228 if (!TRACE_is_enabled() || !TRACE_needs_platform())
232 THROWF (tracing_error, 1, "mark_type is nullptr");
234 THROWF (tracing_error, 1, "mark_value is nullptr");
236 //check if mark_type is already declared
237 type_t type = PJ_type_get (mark_type, PJ_type_get_root());
239 THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
241 val_t value = PJ_value_get (mark_value, type);
242 XBT_DEBUG("MARK %s %s", mark_type, mark_value);
243 new_pajeNewEvent (MSG_get_clock(), PJ_container_get_root(), type, value);
246 /** \ingroup TRACE_mark
247 * \brief Get declared marks
249 * This function should be used to get marks that were already declared with #TRACE_declare_mark.
251 * \return A dynar with the declared marks, must be freed with xbt_dynar_free.
253 xbt_dynar_t TRACE_get_marks ()
255 if (!TRACE_is_enabled())
258 return instr_dict_to_dynar (declared_marks);
261 static void instr_user_variable(double time, const char *resource, const char *variable, const char *father_type,
262 double value, InstrUserVariable what, const char *color, xbt_dict_t filter)
264 /* safe switches. tracing has to be activated and if platform is not traced, we don't allow user variables */
265 if (!TRACE_is_enabled() || !TRACE_needs_platform())
268 //check if variable is already declared
269 char *created = (char*)xbt_dict_get_or_null(filter, variable);
270 if (what == INSTR_US_DECLARE){
271 if (created){//already declared
274 xbt_dict_set (filter, variable, xbt_strdup("1"), nullptr);
275 instr_new_user_variable_type (father_type, variable, color);
278 if (!created){//not declared, ignore
282 snprintf(valuestr, 100, "%g", value);
283 container_t container = PJ_container_get(resource);
284 type_t type = PJ_type_get (variable, container->type);
287 new_pajeSetVariable(time, container, type, value);
290 new_pajeAddVariable(time, container, type, value);
293 new_pajeSubVariable(time, container, type, value);
303 static void instr_user_srcdst_variable(double time, const char *src, const char *dst, const char *variable,
304 const char *father_type, double value, InstrUserVariable what)
306 sg_netcard_t src_elm = sg_netcard_by_name_or_null(src);
308 xbt_die("Element '%s' not found!",src);
310 sg_netcard_t dst_elm = sg_netcard_by_name_or_null(dst);
312 xbt_die("Element '%s' not found!",dst);
314 std::vector<Link*> route;
315 simgrid::kernel::routing::NetZoneImpl::getGlobalRoute(src_elm, dst_elm, &route, nullptr);
316 for (auto link : route)
317 instr_user_variable (time, link->getName(), variable, father_type, value, what, nullptr, user_link_variables);
320 /** \ingroup TRACE_API
321 * \brief Creates a file with the topology of the platform file used for the simulator.
323 * The graph topology will have the following properties: all hosts, links and routers of the platform file are mapped
324 * to graph nodes; routes are mapped to edges.
325 * The platform's AS are not represented in the output.
327 * \param filename The name of the file that will hold the graph.
329 * \return 1 of successful, 0 otherwise.
331 int TRACE_platform_graph_export_graphviz (const char *filename)
333 /* returns 1 if successful, 0 otherwise */
334 if (!TRACE_is_enabled())
336 xbt_graph_t g = instr_routing_platform_graph();
339 instr_routing_platform_graph_export_graphviz (g, filename);
340 xbt_graph_free_graph(g, xbt_free_f, xbt_free_f, nullptr);
345 * Derived functions that use instr_user_variable and TRACE_user_srcdst_variable. They were previously defined as
346 * pre-processors directives, but were transformed into functions so the user can track them using gdb.
349 /* for VM variables */
350 /** \ingroup TRACE_user_variables
351 * \brief Declare a new user variable associated to VMs.
353 * Declare a user variable that will be associated to VMs. A user vm variable can be used to trace user variables
354 * such as the number of tasks in a VM, the number of clients in an application (for VMs), and so on. The color
355 * associated to this new variable will be random.
357 * \param variable The name of the new variable to be declared.
359 * \see TRACE_vm_variable_declare_with_color
361 void TRACE_vm_variable_declare (const char *variable)
363 instr_user_variable(0, nullptr, variable, "MSG_VM", 0, INSTR_US_DECLARE, nullptr, user_vm_variables);
366 /** \ingroup TRACE_user_variables
367 * \brief Declare a new user variable associated to VMs with a color.
369 * Same as #TRACE_vm_variable_declare, but associated a color to the newly created user host variable. The color needs
370 * to be a string with three numbers separated by spaces in the range [0,1].
371 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
373 * \param variable The name of the new variable to be declared.
374 * \param color The color for the new variable.
376 void TRACE_vm_variable_declare_with_color (const char *variable, const char *color)
378 instr_user_variable(0, nullptr, variable, "MSG_VM", 0, INSTR_US_DECLARE, color, user_vm_variables);
381 /** \ingroup TRACE_user_variables
382 * \brief Set the value of a variable of a host.
384 * \param vm The name of the VM to be considered.
385 * \param variable The name of the variable to be considered.
386 * \param value The new value of the variable.
388 * \see TRACE_vm_variable_declare, TRACE_vm_variable_add, TRACE_vm_variable_sub
390 void TRACE_vm_variable_set (const char *vm, const char *variable, double value)
392 TRACE_vm_variable_set_with_time (MSG_get_clock(), vm, variable, value);
395 /** \ingroup TRACE_user_variables
396 * \brief Add a value to a variable of a VM.
398 * \param vm The name of the VM to be considered.
399 * \param variable The name of the variable to be considered.
400 * \param value The value to be added to the variable.
402 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_sub
404 void TRACE_vm_variable_add (const char *vm, const char *variable, double value)
406 TRACE_vm_variable_add_with_time (MSG_get_clock(), vm, variable, value);
409 /** \ingroup TRACE_user_variables
410 * \brief Subtract a value from a variable of a VM.
412 * \param vm The name of the vm to be considered.
413 * \param variable The name of the variable to be considered.
414 * \param value The value to be subtracted from the variable.
416 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_add
418 void TRACE_vm_variable_sub (const char *vm, const char *variable, double value)
420 TRACE_vm_variable_sub_with_time (MSG_get_clock(), vm, variable, value);
423 /** \ingroup TRACE_user_variables
424 * \brief Set the value of a variable of a VM at a given timestamp.
426 * Same as #TRACE_vm_variable_set, but let user specify the time used to trace it. Users can specify a time that
427 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
428 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
431 * \param time The timestamp to be used to tag this change of value.
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 new value of the variable.
436 * \see TRACE_vm_variable_declare, TRACE_vm_variable_add_with_time, TRACE_vm_variable_sub_with_time
438 void TRACE_vm_variable_set_with_time (double time, const char *vm, const char *variable, double value)
440 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_SET, nullptr, user_vm_variables);
443 /** \ingroup TRACE_user_variables
444 * \brief Add a value to a variable of a VM at a given timestamp.
446 * Same as #TRACE_vm_variable_add, but let user specify the time used to trace it. Users can specify a time that
447 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
448 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
451 * \param time The timestamp to be used to tag this change of value.
452 * \param vm The name of the VM to be considered.
453 * \param variable The name of the variable to be considered.
454 * \param value The value to be added to the variable.
456 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_sub_with_time
458 void TRACE_vm_variable_add_with_time (double time, const char *vm, const char *variable, double value)
460 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_ADD, nullptr, user_vm_variables);
463 /** \ingroup TRACE_user_variables
464 * \brief Subtract a value from a variable of a VM at a given timestamp.
466 * Same as #TRACE_vm_variable_sub, but let user specify the time used to trace it. Users can specify a time that
467 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
468 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
471 * \param time The timestamp to be used to tag this change of value.
472 * \param vm The name of the VM to be considered.
473 * \param variable The name of the variable to be considered.
474 * \param value The value to be subtracted from the variable.
476 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_add_with_time
478 void TRACE_vm_variable_sub_with_time (double time, const char *vm, const char *variable, double value)
480 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_SUB, nullptr, user_vm_variables);
483 /** \ingroup TRACE_user_variables
484 * \brief Get declared user vm variables
486 * This function should be used to get VM variables that were already declared with #TRACE_vm_variable_declare or with
487 * #TRACE_vm_variable_declare_with_color.
489 * \return A dynar with the declared host variables, must be freed with xbt_dynar_free.
491 xbt_dynar_t TRACE_get_vm_variables ()
493 return instr_dict_to_dynar (user_vm_variables);
496 /* for host variables */
497 /** \ingroup TRACE_user_variables
498 * \brief Declare a new user variable associated to hosts.
500 * Declare a user variable that will be associated to hosts.
501 * A user host variable can be used to trace user variables such as the number of tasks in a server, the number of
502 * clients in an application (for hosts), and so on. The color associated to this new variable will be random.
504 * \param variable The name of the new variable to be declared.
506 * \see TRACE_host_variable_declare_with_color
508 void TRACE_host_variable_declare (const char *variable)
510 instr_user_variable(0, nullptr, variable, "HOST", 0, INSTR_US_DECLARE, nullptr, user_host_variables);
513 /** \ingroup TRACE_user_variables
514 * \brief Declare a new user variable associated to hosts with a color.
516 * Same as #TRACE_host_variable_declare, but associated a color to the newly created user host variable. The color
517 * needs to be a string with three numbers separated by spaces in the range [0,1].
518 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
520 * \param variable The name of the new variable to be declared.
521 * \param color The color for the new variable.
523 void TRACE_host_variable_declare_with_color (const char *variable, const char *color)
525 instr_user_variable(0, nullptr, variable, "HOST", 0, INSTR_US_DECLARE, color, user_host_variables);
528 /** \ingroup TRACE_user_variables
529 * \brief Set the value of a variable of a host.
531 * \param host The name of the host to be considered.
532 * \param variable The name of the variable to be considered.
533 * \param value The new value of the variable.
535 * \see TRACE_host_variable_declare, TRACE_host_variable_add, TRACE_host_variable_sub
537 void TRACE_host_variable_set (const char *host, const char *variable, double value)
539 TRACE_host_variable_set_with_time (MSG_get_clock(), host, variable, value);
542 /** \ingroup TRACE_user_variables
543 * \brief Add a value to a variable of a host.
545 * \param host The name of the host to be considered.
546 * \param variable The name of the variable to be considered.
547 * \param value The value to be added to the variable.
549 * \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_sub
551 void TRACE_host_variable_add (const char *host, const char *variable, double value)
553 TRACE_host_variable_add_with_time (MSG_get_clock(), host, variable, value);
556 /** \ingroup TRACE_user_variables
557 * \brief Subtract a value from a variable of a host.
559 * \param host The name of the host to be considered.
560 * \param variable The name of the variable to be considered.
561 * \param value The value to be subtracted from the variable.
563 * \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_add
565 void TRACE_host_variable_sub (const char *host, const char *variable, double value)
567 TRACE_host_variable_sub_with_time (MSG_get_clock(), host, variable, value);
570 /** \ingroup TRACE_user_variables
571 * \brief Set the value of a variable of a host at a given timestamp.
573 * Same as #TRACE_host_variable_set, but let user specify the time used to trace it. Users can specify a time that
574 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
575 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
578 * \param time The timestamp to be used to tag this change of value.
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 new value of the variable.
583 * \see TRACE_host_variable_declare, TRACE_host_variable_add_with_time, TRACE_host_variable_sub_with_time
585 void TRACE_host_variable_set_with_time (double time, const char *host, const char *variable, double value)
587 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SET, nullptr, user_host_variables);
590 /** \ingroup TRACE_user_variables
591 * \brief Add a value to a variable of a host at a given timestamp.
593 * Same as #TRACE_host_variable_add, but let user specify the time used to trace it. Users can specify a time that
594 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
595 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
598 * \param time The timestamp to be used to tag this change of value.
599 * \param host The name of the host to be considered.
600 * \param variable The name of the variable to be considered.
601 * \param value The value to be added to the variable.
603 * \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_sub_with_time
605 void TRACE_host_variable_add_with_time (double time, const char *host, const char *variable, double value)
607 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_ADD, nullptr, user_host_variables);
610 /** \ingroup TRACE_user_variables
611 * \brief Subtract a value from a variable of a host at a given timestamp.
613 * Same as #TRACE_host_variable_sub, but let user specify the time used to trace it. Users can specify a time that
614 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
615 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
618 * \param time The timestamp to be used to tag this change of value.
619 * \param host The name of the host to be considered.
620 * \param variable The name of the variable to be considered.
621 * \param value The value to be subtracted from the variable.
623 * \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_add_with_time
625 void TRACE_host_variable_sub_with_time (double time, const char *host, const char *variable, double value)
627 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SUB, nullptr, user_host_variables);
630 /** \ingroup TRACE_user_variables
631 * \brief Get declared user host variables
633 * This function should be used to get host variables that were already declared with #TRACE_host_variable_declare or
634 * with #TRACE_host_variable_declare_with_color.
636 * \return A dynar with the declared host variables, must be freed with xbt_dynar_free.
638 xbt_dynar_t TRACE_get_host_variables ()
640 return instr_dict_to_dynar (user_host_variables);
643 /* for link variables */
644 /** \ingroup TRACE_user_variables
645 * \brief Declare a new user variable associated to links.
647 * Declare a user variable that will be associated to links.
648 * A user link variable can be used, for example, to trace user variables such as the number of messages being
649 * transferred through network links. The color associated to this new variable will be random.
651 * \param variable The name of the new variable to be declared.
653 * \see TRACE_link_variable_declare_with_color
655 void TRACE_link_variable_declare (const char *variable)
657 instr_user_variable (0, nullptr, variable, "LINK", 0, INSTR_US_DECLARE, nullptr, user_link_variables);
660 /** \ingroup TRACE_user_variables
661 * \brief Declare a new user variable associated to links with a color.
663 * Same as #TRACE_link_variable_declare, but associated a color to the newly created user link variable. The color
664 * needs to be a string with three numbers separated by spaces in the range [0,1].
665 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
667 * \param variable The name of the new variable to be declared.
668 * \param color The color for the new variable.
670 void TRACE_link_variable_declare_with_color (const char *variable, const char *color)
672 instr_user_variable (0, nullptr, variable, "LINK", 0, INSTR_US_DECLARE, color, user_link_variables);
675 /** \ingroup TRACE_user_variables
676 * \brief Set the value of a variable of a link.
678 * \param link The name of the link to be considered.
679 * \param variable The name of the variable to be considered.
680 * \param value The new value of the variable.
682 * \see TRACE_link_variable_declare, TRACE_link_variable_add, TRACE_link_variable_sub
684 void TRACE_link_variable_set (const char *link, const char *variable, double value)
686 TRACE_link_variable_set_with_time (MSG_get_clock(), link, variable, value);
689 /** \ingroup TRACE_user_variables
690 * \brief Add a value to a variable of a link.
692 * \param link The name of the link to be considered.
693 * \param variable The name of the variable to be considered.
694 * \param value The value to be added to the variable.
696 * \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_sub
698 void TRACE_link_variable_add (const char *link, const char *variable, double value)
700 TRACE_link_variable_add_with_time (MSG_get_clock(), link, variable, value);
703 /** \ingroup TRACE_user_variables
704 * \brief Subtract a value from a variable of a link.
706 * \param link The name of the link to be considered.
707 * \param variable The name of the variable to be considered.
708 * \param value The value to be subtracted from the variable.
710 * \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_add
712 void TRACE_link_variable_sub (const char *link, const char *variable, double value)
714 TRACE_link_variable_sub_with_time (MSG_get_clock(), link, variable, value);
717 /** \ingroup TRACE_user_variables
718 * \brief Set the value of a variable of a link at a given timestamp.
720 * Same as #TRACE_link_variable_set, but let user specify the time used to trace it. Users can specify a time that
721 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
722 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
725 * \param time The timestamp to be used to tag this change of value.
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 new value of the variable.
730 * \see TRACE_link_variable_declare, TRACE_link_variable_add_with_time, TRACE_link_variable_sub_with_time
732 void TRACE_link_variable_set_with_time (double time, const char *link, const char *variable, double value)
734 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SET, nullptr, user_link_variables);
737 /** \ingroup TRACE_user_variables
738 * \brief Add a value to a variable of a link at a given timestamp.
740 * Same as #TRACE_link_variable_add, but let user specify the time used to trace it. Users can specify a time that
741 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
742 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
745 * \param time The timestamp to be used to tag this change of value.
746 * \param link The name of the link to be considered.
747 * \param variable The name of the variable to be considered.
748 * \param value The value to be added to the variable.
750 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_sub_with_time
752 void TRACE_link_variable_add_with_time (double time, const char *link, const char *variable, double value)
754 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_ADD, nullptr, user_link_variables);
757 /** \ingroup TRACE_user_variables
758 * \brief Subtract a value from a variable of a link at a given timestamp.
760 * Same as #TRACE_link_variable_sub, but let user specify the time used to trace it. Users can specify a time that
761 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
762 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
765 * \param time The timestamp to be used to tag this change of value.
766 * \param link The name of the link to be considered.
767 * \param variable The name of the variable to be considered.
768 * \param value The value to be subtracted from the variable.
770 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_add_with_time
772 void TRACE_link_variable_sub_with_time (double time, const char *link, const char *variable, double value)
774 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SUB, nullptr, user_link_variables);
777 /* for link variables, but with src and dst used for get_route */
778 /** \ingroup TRACE_user_variables
779 * \brief Set the value of the variable present in the links connecting source and destination.
781 * Same as #TRACE_link_variable_set, but instead of providing the name of link to be considered, provide the source
782 * and destination hosts. All links that are part of the route between source and destination will have the variable
783 * set to the provided value.
785 * \param src The name of the source host for get route.
786 * \param dst The name of the destination host for get route.
787 * \param variable The name of the variable to be considered.
788 * \param value The new value of the variable.
790 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add, TRACE_link_srcdst_variable_sub
792 void TRACE_link_srcdst_variable_set (const char *src, const char *dst, const char *variable, double value)
794 TRACE_link_srcdst_variable_set_with_time (MSG_get_clock(), src, dst, variable, value);
797 /** \ingroup TRACE_user_variables
798 * \brief Add a value to the variable present in the links connecting source and destination.
800 * Same as #TRACE_link_variable_add, but instead of providing the name of link to be considered, provide the source
801 * and destination hosts. All links that are part of the route between source and destination will have the value
802 * passed as parameter added to the current value of the variable name to be considered.
804 * \param src The name of the source host for get route.
805 * \param dst The name of the destination host for get route.
806 * \param variable The name of the variable to be considered.
807 * \param value The value to be added to the variable.
809 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_sub
811 void TRACE_link_srcdst_variable_add (const char *src, const char *dst, const char *variable, double value)
813 TRACE_link_srcdst_variable_add_with_time (MSG_get_clock(), src, dst, variable, value);
816 /** \ingroup TRACE_user_variables
817 * \brief Subtract a value from the variable present in the links connecting source and destination.
819 * Same as #TRACE_link_variable_sub, but instead of providing the name of link to be considered, provide the source
820 * and destination hosts. All links that are part of the route between source and destination will have the value
821 * passed as parameter subtracted from the current value of the variable name to be considered.
823 * \param src The name of the source host for get route.
824 * \param dst The name of the destination host for get route.
825 * \param variable The name of the variable to be considered.
826 * \param value The value to be subtracted from the variable.
828 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_add
830 void TRACE_link_srcdst_variable_sub (const char *src, const char *dst, const char *variable, double value)
832 TRACE_link_srcdst_variable_sub_with_time (MSG_get_clock(), src, dst, variable, value);
835 /** \ingroup TRACE_user_variables
836 * \brief Set the value of the variable present in the links connecting source and destination at a given timestamp.
838 * Same as #TRACE_link_srcdst_variable_set, but let user specify the time used to trace it. Users can specify a time
839 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
840 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
843 * \param time The timestamp to be used to tag this change of value.
844 * \param src The name of the source host for get route.
845 * \param dst The name of the destination host for get route.
846 * \param variable The name of the variable to be considered.
847 * \param value The new value of the variable.
849 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add_with_time, TRACE_link_srcdst_variable_sub_with_time
851 void TRACE_link_srcdst_variable_set_with_time (double time, const char *src, const char *dst, const char *variable,
854 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SET);
857 /** \ingroup TRACE_user_variables
858 * \brief Add a value to the variable present in the links connecting source and destination at a given timestamp.
860 * Same as #TRACE_link_srcdst_variable_add, but let user specify the time used to trace it. Users can specify a time
861 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
862 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
865 * \param time The timestamp to be used to tag this change of value.
866 * \param src The name of the source host for get route.
867 * \param dst The name of the destination host for get route.
868 * \param variable The name of the variable to be considered.
869 * \param value The value to be added to the variable.
871 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_sub_with_time
873 void TRACE_link_srcdst_variable_add_with_time (double time, const char *src, const char *dst, const char *variable,
876 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_ADD);
879 /** \ingroup TRACE_user_variables
880 * \brief Subtract a value from the variable present in the links connecting source and dest. at a given timestamp.
882 * Same as #TRACE_link_srcdst_variable_sub, but let user specify the time used to trace it. Users can specify a time
883 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
884 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
887 * \param time The timestamp to be used to tag this change of value.
888 * \param src The name of the source host for get route.
889 * \param dst The name of the destination host for get route.
890 * \param variable The name of the variable to be considered.
891 * \param value The value to be subtracted from the variable.
893 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_add_with_time
895 void TRACE_link_srcdst_variable_sub_with_time (double time, const char *src, const char *dst, const char *variable,
898 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SUB);
901 /** \ingroup TRACE_user_variables
902 * \brief Get declared user link variables
904 * This function should be used to get link variables that were already declared with #TRACE_link_variable_declare or
905 * with #TRACE_link_variable_declare_with_color.
907 * \return A dynar with the declared link variables, must be freed with xbt_dynar_free.
909 xbt_dynar_t TRACE_get_link_variables ()
911 return instr_dict_to_dynar (user_link_variables);
914 /** \ingroup TRACE_user_variables
915 * \brief Declare a new user state associated to hosts.
917 * Declare a user state that will be associated to hosts.
918 * A user host state can be used to trace application states.
920 * \param state The name of the new state to be declared.
922 * \see TRACE_host_state_declare_value
924 void TRACE_host_state_declare (const char *state)
926 instr_new_user_state_type("HOST", state);
929 /** \ingroup TRACE_user_variables
930 * \brief Declare a new value for a user state associated to hosts.
932 * Declare a value for a state. The color needs to be a string with 3 numbers separated by spaces in the range [0,1].
933 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
935 * \param state The name of the new state to be declared.
936 * \param value The name of the value
937 * \param color The color of the value
939 * \see TRACE_host_state_declare
941 void TRACE_host_state_declare_value (const char *state, const char *value, const char *color)
943 instr_new_value_for_user_state_type (state, value, color);
946 /** \ingroup TRACE_user_variables
947 * \brief Set the user state to the given value.
949 * Change a user state previously declared to the given value.
951 * \param host The name of the host to be considered.
952 * \param state The name of the state previously declared.
953 * \param value The new value of the state.
955 * \see TRACE_host_state_declare, TRACE_host_push_state, TRACE_host_pop_state, TRACE_host_reset_state
957 void TRACE_host_set_state (const char *host, const char *state, const char *value)
959 container_t container = PJ_container_get(host);
960 type_t type = PJ_type_get (state, container->type);
961 val_t val = PJ_value_get_or_new (value, nullptr, type); /* if user didn't declare a value with a color, use nullptr color */
962 new_pajeSetState(MSG_get_clock(), container, type, val);
965 /** \ingroup TRACE_user_variables
966 * \brief Push a new value for a state of a given host.
968 * Change a user state previously declared by pushing the new value to the state.
970 * \param host The name of the host to be considered.
971 * \param state The name of the state previously declared.
972 * \param value The value to be pushed.
974 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_pop_state, TRACE_host_reset_state
976 void TRACE_host_push_state (const char *host, const char *state, const char *value)
978 container_t container = PJ_container_get(host);
979 type_t type = PJ_type_get (state, container->type);
980 val_t val = PJ_value_get_or_new (value, nullptr, type); /* if user didn't declare a value with a color, use nullptr color */
981 new_pajePushState(MSG_get_clock(), container, type, val);
984 /** \ingroup TRACE_user_variables
985 * \brief Pop the last value of a state of a given host.
987 * Change a user state previously declared by removing the last value of the state.
989 * \param host The name of the host to be considered.
990 * \param state The name of the state to be popped.
992 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_reset_state
994 void TRACE_host_pop_state (const char *host, const char *state)
996 container_t container = PJ_container_get(host);
997 type_t type = PJ_type_get (state, container->type);
998 new_pajePopState(MSG_get_clock(), container, type);
1001 /** \ingroup TRACE_user_variables
1002 * \brief Reset the state of a given host.
1004 * Clear all previous values of a user state.
1006 * \param host The name of the host to be considered.
1007 * \param state The name of the state to be cleared.
1009 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_pop_state
1011 void TRACE_host_reset_state (const char *host, const char *state)
1013 container_t container = PJ_container_get(host);
1014 type_t type = PJ_type_get (state, container->type);
1015 new_pajeResetState(MSG_get_clock(), container, type);
1018 /** \ingroup TRACE_API
1019 * \brief Get Paje container types that can be mapped to the nodes of a graph.
1021 * This function can be used to create a user made graph configuration file for Triva. Normally, it is used with the
1022 * functions defined in \ref TRACE_user_variables.
1024 * \return A dynar with the types, must be freed with xbt_dynar_free.
1026 xbt_dynar_t TRACE_get_node_types ()
1028 return instr_dict_to_dynar (trivaNodeTypes);
1031 /** \ingroup TRACE_API
1032 * \brief Get Paje container types that can be mapped to the edges of a graph.
1034 * This function can be used to create a user made graph configuration file for Triva. Normally, it is used with the
1035 * functions defined in \ref TRACE_user_variables.
1037 * \return A dynar with the types, must be freed with xbt_dynar_free.
1039 xbt_dynar_t TRACE_get_edge_types ()
1041 return instr_dict_to_dynar (trivaEdgeTypes);
1044 /** \ingroup TRACE_API
1045 * \brief Pauses all tracing activities.
1050 instr_pause_tracing();
1053 /** \ingroup TRACE_API
1054 * \brief Resumes all tracing activities.
1057 void TRACE_resume ()
1059 instr_resume_tracing();