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/NetPoint.hpp"
10 #include "src/surf/network_interface.hpp"
11 #include "src/surf/surf_private.h"
12 #include "surf/surf.h"
22 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API");
24 std::set<std::string> created_categories;
25 std::set<std::string> declared_marks;
26 std::set<std::string> user_host_variables;
27 std::set<std::string> user_vm_variables;
28 std::set<std::string> user_link_variables;
29 extern std::set<std::string> trivaNodeTypes;
30 extern std::set<std::string> trivaEdgeTypes;
32 static xbt_dynar_t instr_set_to_dynar(std::set<std::string>* filter)
34 if (not TRACE_is_enabled() || not TRACE_needs_platform())
37 xbt_dynar_t ret = xbt_dynar_new (sizeof(char*), &xbt_free_ref);
38 for (auto const& name : *filter)
39 xbt_dynar_push_as(ret, char*, xbt_strdup(name.c_str()));
44 /** \ingroup TRACE_category
45 * \brief Declare a new category with a random color.
47 * This function should be used to define a user category. The category can be used to differentiate the tasks that
48 * are created during the simulation (for example, tasks from server1, server2, or request tasks, computation tasks,
49 * communication tasks). All resource utilization (host power and link bandwidth) will be classified according to the
50 * task category. Tasks that do not belong to a category are not traced. The color for the category that is being
51 * declared is random. This function has no effect if a category with the same name has been already declared.
53 * See \ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
55 * \param category The name of the new tracing category to be created.
57 * \see TRACE_category_with_color, MSG_task_set_category, SD_task_set_category
59 void TRACE_category(const char *category)
61 TRACE_category_with_color (category, nullptr);
64 /** \ingroup TRACE_category
65 * \brief Declare a new category with a color.
67 * Same as #TRACE_category, but let user specify a color encoded as a RGB-like string with three floats from 0 to 1.
68 * 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"
69 * as color. This function has no effect if a category with the same name has been already declared.
71 * See \ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
73 * \param category The name of the new tracing category to be created.
74 * \param color The color of the category (see \ref outcomes_vizu to
75 * know how to correctly specify the color)
77 * \see MSG_task_set_category, SD_task_set_category
79 void TRACE_category_with_color (const char *category, const char *color)
81 /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with categories */
82 if (not TRACE_is_enabled() || not TRACE_needs_platform())
85 if (not(TRACE_categorized() && category != nullptr))
88 //check if category is already created
89 if (created_categories.find(category) != created_categories.end())
92 created_categories.insert(category);
95 char final_color[INSTR_DEFAULT_STR_SIZE];
97 //generate a random color
98 double red = drand48();
99 double green = drand48();
100 double blue = drand48();
101 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%f %f %f", red, green, blue);
103 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
106 XBT_DEBUG("CAT,declare %s, \"%s\" \"%s\"", category, color, final_color);
108 //define the type of this category on top of hosts and links
109 instr_new_variable_type (category, final_color);
112 /** \ingroup TRACE_category
113 * \brief Get declared categories
115 * This function should be used to get categories that were already declared with #TRACE_category or with
116 * #TRACE_category_with_color.
118 * See \ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
120 * \return A dynar with the declared categories, must be freed with xbt_dynar_free.
122 * \see MSG_task_set_category, SD_task_set_category
124 xbt_dynar_t TRACE_get_categories ()
126 if (not TRACE_is_enabled() || not TRACE_categorized())
128 return instr_set_to_dynar(&created_categories);
131 /** \ingroup TRACE_mark
132 * \brief Declare a new type for tracing mark.
134 * This function declares a new Paje event type in the trace file that can be used by simulators to declare
135 * application-level marks. This function is independent of which API is used in SimGrid.
137 * \param mark_type The name of the new type.
141 void TRACE_declare_mark(const char *mark_type)
143 /* safe switchs. tracing has to be activated and if platform is not traced, we can't deal with marks */
144 if (not TRACE_is_enabled() || not TRACE_needs_platform())
148 THROWF (tracing_error, 1, "mark_type is nullptr");
150 //check if mark_type is already declared
151 if (declared_marks.find(mark_type) != declared_marks.end()) {
152 THROWF (tracing_error, 1, "mark_type with name (%s) is already declared", mark_type);
155 XBT_DEBUG("MARK,declare %s", mark_type);
156 Type::eventNew(mark_type, PJ_type_get_root());
157 declared_marks.insert(mark_type);
160 /** \ingroup TRACE_mark
161 * \brief Declare a new colored value for a previously declared mark type.
163 * This function declares a new colored value for a Paje event type in the trace file that can be used by simulators to
164 * declare application-level marks. This function is independent of which API is used in SimGrid. The color needs to be
165 * a string with three numbers separated by spaces in the range [0,1].
166 * 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
167 * be white ("1 1 1").
169 * \param mark_type The name of the new type.
170 * \param mark_value The name of the new value for this type.
171 * \param mark_color The color of the new value for this type.
175 void TRACE_declare_mark_value_with_color (const char *mark_type, const char *mark_value, const char *mark_color)
177 /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
178 if (not TRACE_is_enabled() || not TRACE_needs_platform())
182 THROWF (tracing_error, 1, "mark_type is nullptr");
184 THROWF (tracing_error, 1, "mark_value is nullptr");
186 Type* type = PJ_type_get (mark_type, PJ_type_get_root());
188 THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
191 char white[INSTR_DEFAULT_STR_SIZE] = "1.0 1.0 1.0";
195 XBT_DEBUG("MARK,declare_value %s %s %s", mark_type, mark_value, mark_color);
196 Value rett(mark_value, mark_color, type);
199 /** \ingroup TRACE_mark
200 * \brief Declare a new value for a previously declared mark type.
202 * This function declares a new value for a Paje event type in the trace file that can be used by simulators to declare
203 * application-level marks. This function is independent of which API is used in SimGrid. Calling this function is the
204 * same as calling \ref TRACE_declare_mark_value_with_color with a nullptr color.
206 * \param mark_type The name of the new type.
207 * \param mark_value The name of the new value for this type.
211 void TRACE_declare_mark_value (const char *mark_type, const char *mark_value)
213 TRACE_declare_mark_value_with_color (mark_type, mark_value, nullptr);
217 * \ingroup TRACE_mark
218 * \brief Create a new instance of a tracing mark type.
220 * This function creates a mark in the trace file. The first parameter had to be previously declared using
221 * #TRACE_declare_mark, the second is the identifier for this mark instance. We recommend that the mark_value is a
222 * unique value for the whole simulation. Nevertheless, this is not a strong requirement: the trace will be valid even
223 * if there are multiple mark identifiers for the same trace.
225 * \param mark_type The name of the type for which the new instance will belong.
226 * \param mark_value The name of the new instance mark.
228 * \see TRACE_declare_mark
230 void TRACE_mark(const char *mark_type, const char *mark_value)
232 /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
233 if (not TRACE_is_enabled() || not TRACE_needs_platform())
237 THROWF (tracing_error, 1, "mark_type is nullptr");
239 THROWF (tracing_error, 1, "mark_value is nullptr");
241 //check if mark_type is already declared
242 Type* type = PJ_type_get (mark_type, PJ_type_get_root());
244 THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
247 XBT_DEBUG("MARK %s %s", mark_type, mark_value);
248 new NewEvent(MSG_get_clock(), PJ_container_get_root(), type, Value::get(mark_value, type));
251 /** \ingroup TRACE_mark
252 * \brief Get declared marks
254 * This function should be used to get marks that were already declared with #TRACE_declare_mark.
256 * \return A dynar with the declared marks, must be freed with xbt_dynar_free.
258 xbt_dynar_t TRACE_get_marks ()
260 if (not TRACE_is_enabled())
263 return instr_set_to_dynar(&declared_marks);
266 static void instr_user_variable(double time, const char* resource, const char* variable, const char* father_type,
267 double value, InstrUserVariable what, const char* color, std::set<std::string>* filter)
269 /* safe switches. tracing has to be activated and if platform is not traced, we don't allow user variables */
270 if (not TRACE_is_enabled() || not TRACE_needs_platform())
273 //check if variable is already declared
274 auto created = filter->find(variable);
275 if (what == INSTR_US_DECLARE){
276 if (created == filter->end()) { // not declared yet
277 filter->insert(variable);
278 instr_new_user_variable_type (father_type, variable, color);
281 if (created != filter->end()) { // declared, let's work
283 snprintf(valuestr, 100, "%g", value);
284 container_t container = PJ_container_get(resource);
285 Type* type = PJ_type_get (variable, container->type);
288 new SetVariableEvent(time, container, type, value);
291 new AddVariableEvent(time, container, type, value);
294 new SubVariableEvent(time, container, type, value);
304 static void instr_user_srcdst_variable(double time, const char *src, const char *dst, const char *variable,
305 const char *father_type, double value, InstrUserVariable what)
307 sg_netpoint_t src_elm = sg_netpoint_by_name_or_null(src);
309 xbt_die("Element '%s' not found!",src);
311 sg_netpoint_t dst_elm = sg_netpoint_by_name_or_null(dst);
313 xbt_die("Element '%s' not found!",dst);
315 std::vector<simgrid::surf::LinkImpl*> route;
316 simgrid::kernel::routing::NetZoneImpl::getGlobalRoute(src_elm, dst_elm, &route, nullptr);
317 for (auto const& link : route)
318 instr_user_variable(time, link->cname(), variable, father_type, value, what, nullptr, &user_link_variables);
321 /** \ingroup TRACE_API
322 * \brief Creates a file with the topology of the platform file used for the simulator.
324 * The graph topology will have the following properties: all hosts, links and routers of the platform file are mapped
325 * to graph nodes; routes are mapped to edges.
326 * The platform's AS are not represented in the output.
328 * \param filename The name of the file that will hold the graph.
330 * \return 1 of successful, 0 otherwise.
332 int TRACE_platform_graph_export_graphviz (const char *filename)
334 /* returns 1 if successful, 0 otherwise */
335 if (not TRACE_is_enabled())
337 xbt_graph_t g = instr_routing_platform_graph();
340 instr_routing_platform_graph_export_graphviz (g, filename);
341 xbt_graph_free_graph(g, xbt_free_f, xbt_free_f, nullptr);
346 * Derived functions that use instr_user_variable and TRACE_user_srcdst_variable. They were previously defined as
347 * pre-processors directives, but were transformed into functions so the user can track them using gdb.
350 /* for VM variables */
351 /** \ingroup TRACE_user_variables
352 * \brief Declare a new user variable associated to VMs.
354 * Declare a user variable that will be associated to VMs. A user vm variable can be used to trace user variables
355 * such as the number of tasks in a VM, the number of clients in an application (for VMs), and so on. The color
356 * associated to this new variable will be random.
358 * \param variable The name of the new variable to be declared.
360 * \see TRACE_vm_variable_declare_with_color
362 void TRACE_vm_variable_declare (const char *variable)
364 instr_user_variable(0, nullptr, variable, "MSG_VM", 0, INSTR_US_DECLARE, nullptr, &user_vm_variables);
367 /** \ingroup TRACE_user_variables
368 * \brief Declare a new user variable associated to VMs with a color.
370 * Same as #TRACE_vm_variable_declare, but associated a color to the newly created user host variable. The color needs
371 * to be a string with three numbers separated by spaces in the range [0,1].
372 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
374 * \param variable The name of the new variable to be declared.
375 * \param color The color for the new variable.
377 void TRACE_vm_variable_declare_with_color (const char *variable, const char *color)
379 instr_user_variable(0, nullptr, variable, "MSG_VM", 0, INSTR_US_DECLARE, color, &user_vm_variables);
382 /** \ingroup TRACE_user_variables
383 * \brief Set the value of a variable of a host.
385 * \param vm The name of the VM to be considered.
386 * \param variable The name of the variable to be considered.
387 * \param value The new value of the variable.
389 * \see TRACE_vm_variable_declare, TRACE_vm_variable_add, TRACE_vm_variable_sub
391 void TRACE_vm_variable_set (const char *vm, const char *variable, double value)
393 TRACE_vm_variable_set_with_time (MSG_get_clock(), vm, variable, value);
396 /** \ingroup TRACE_user_variables
397 * \brief Add a value to a variable of a VM.
399 * \param vm The name of the VM to be considered.
400 * \param variable The name of the variable to be considered.
401 * \param value The value to be added to the variable.
403 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_sub
405 void TRACE_vm_variable_add (const char *vm, const char *variable, double value)
407 TRACE_vm_variable_add_with_time (MSG_get_clock(), vm, variable, value);
410 /** \ingroup TRACE_user_variables
411 * \brief Subtract a value from a variable of a VM.
413 * \param vm The name of the vm to be considered.
414 * \param variable The name of the variable to be considered.
415 * \param value The value to be subtracted from the variable.
417 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_add
419 void TRACE_vm_variable_sub (const char *vm, const char *variable, double value)
421 TRACE_vm_variable_sub_with_time (MSG_get_clock(), vm, variable, value);
424 /** \ingroup TRACE_user_variables
425 * \brief Set the value of a variable of a VM at a given timestamp.
427 * Same as #TRACE_vm_variable_set, but let user specify the time used to trace it. Users can specify a time that
428 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
429 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
432 * \param time The timestamp to be used to tag this change of value.
433 * \param vm The name of the VM to be considered.
434 * \param variable The name of the variable to be considered.
435 * \param value The new value of the variable.
437 * \see TRACE_vm_variable_declare, TRACE_vm_variable_add_with_time, TRACE_vm_variable_sub_with_time
439 void TRACE_vm_variable_set_with_time (double time, const char *vm, const char *variable, double value)
441 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_SET, nullptr, &user_vm_variables);
444 /** \ingroup TRACE_user_variables
445 * \brief Add a value to a variable of a VM at a given timestamp.
447 * Same as #TRACE_vm_variable_add, but let user specify the time used to trace it. Users can specify a time that
448 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
449 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
452 * \param time The timestamp to be used to tag this change of value.
453 * \param vm The name of the VM to be considered.
454 * \param variable The name of the variable to be considered.
455 * \param value The value to be added to the variable.
457 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_sub_with_time
459 void TRACE_vm_variable_add_with_time (double time, const char *vm, const char *variable, double value)
461 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_ADD, nullptr, &user_vm_variables);
464 /** \ingroup TRACE_user_variables
465 * \brief Subtract a value from a variable of a VM at a given timestamp.
467 * Same as #TRACE_vm_variable_sub, but let user specify the time used to trace it. Users can specify a time that
468 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
469 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
472 * \param time The timestamp to be used to tag this change of value.
473 * \param vm The name of the VM to be considered.
474 * \param variable The name of the variable to be considered.
475 * \param value The value to be subtracted from the variable.
477 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_add_with_time
479 void TRACE_vm_variable_sub_with_time (double time, const char *vm, const char *variable, double value)
481 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_SUB, nullptr, &user_vm_variables);
484 /* for host variables */
485 /** \ingroup TRACE_user_variables
486 * \brief Declare a new user variable associated to hosts.
488 * Declare a user variable that will be associated to hosts.
489 * A user host variable can be used to trace user variables such as the number of tasks in a server, the number of
490 * clients in an application (for hosts), and so on. The color associated to this new variable will be random.
492 * \param variable The name of the new variable to be declared.
494 * \see TRACE_host_variable_declare_with_color
496 void TRACE_host_variable_declare (const char *variable)
498 instr_user_variable(0, nullptr, variable, "HOST", 0, INSTR_US_DECLARE, nullptr, &user_host_variables);
501 /** \ingroup TRACE_user_variables
502 * \brief Declare a new user variable associated to hosts with a color.
504 * Same as #TRACE_host_variable_declare, but associated a color to the newly created user host variable. The color
505 * needs to be a string with three numbers separated by spaces in the range [0,1].
506 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
508 * \param variable The name of the new variable to be declared.
509 * \param color The color for the new variable.
511 void TRACE_host_variable_declare_with_color (const char *variable, const char *color)
513 instr_user_variable(0, nullptr, variable, "HOST", 0, INSTR_US_DECLARE, color, &user_host_variables);
516 /** \ingroup TRACE_user_variables
517 * \brief Set the value of a variable of a host.
519 * \param host The name of the host to be considered.
520 * \param variable The name of the variable to be considered.
521 * \param value The new value of the variable.
523 * \see TRACE_host_variable_declare, TRACE_host_variable_add, TRACE_host_variable_sub
525 void TRACE_host_variable_set (const char *host, const char *variable, double value)
527 TRACE_host_variable_set_with_time (MSG_get_clock(), host, variable, value);
530 /** \ingroup TRACE_user_variables
531 * \brief Add a value to a variable of a host.
533 * \param host The name of the host to be considered.
534 * \param variable The name of the variable to be considered.
535 * \param value The value to be added to the variable.
537 * \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_sub
539 void TRACE_host_variable_add (const char *host, const char *variable, double value)
541 TRACE_host_variable_add_with_time (MSG_get_clock(), host, variable, value);
544 /** \ingroup TRACE_user_variables
545 * \brief Subtract a value from a variable of a host.
547 * \param host The name of the host to be considered.
548 * \param variable The name of the variable to be considered.
549 * \param value The value to be subtracted from the variable.
551 * \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_add
553 void TRACE_host_variable_sub (const char *host, const char *variable, double value)
555 TRACE_host_variable_sub_with_time (MSG_get_clock(), host, variable, value);
558 /** \ingroup TRACE_user_variables
559 * \brief Set the value of a variable of a host at a given timestamp.
561 * Same as #TRACE_host_variable_set, but let user specify the time used to trace it. Users can specify a time that
562 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
563 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
566 * \param time The timestamp to be used to tag this change of value.
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 new value of the variable.
571 * \see TRACE_host_variable_declare, TRACE_host_variable_add_with_time, TRACE_host_variable_sub_with_time
573 void TRACE_host_variable_set_with_time (double time, const char *host, const char *variable, double value)
575 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SET, nullptr, &user_host_variables);
578 /** \ingroup TRACE_user_variables
579 * \brief Add a value to a variable of a host at a given timestamp.
581 * Same as #TRACE_host_variable_add, 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 value to be added to the variable.
591 * \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_sub_with_time
593 void TRACE_host_variable_add_with_time (double time, const char *host, const char *variable, double value)
595 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_ADD, nullptr, &user_host_variables);
598 /** \ingroup TRACE_user_variables
599 * \brief Subtract a value from a variable of a host at a given timestamp.
601 * Same as #TRACE_host_variable_sub, 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 subtracted from the variable.
611 * \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_add_with_time
613 void TRACE_host_variable_sub_with_time (double time, const char *host, const char *variable, double value)
615 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SUB, nullptr, &user_host_variables);
618 /** \ingroup TRACE_user_variables
619 * \brief Get declared user host variables
621 * This function should be used to get host variables that were already declared with #TRACE_host_variable_declare or
622 * with #TRACE_host_variable_declare_with_color.
624 * \return A dynar with the declared host variables, must be freed with xbt_dynar_free.
626 xbt_dynar_t TRACE_get_host_variables ()
628 return instr_set_to_dynar(&user_host_variables);
631 /* for link variables */
632 /** \ingroup TRACE_user_variables
633 * \brief Declare a new user variable associated to links.
635 * Declare a user variable that will be associated to links.
636 * A user link variable can be used, for example, to trace user variables such as the number of messages being
637 * transferred through network links. The color associated to this new variable will be random.
639 * \param variable The name of the new variable to be declared.
641 * \see TRACE_link_variable_declare_with_color
643 void TRACE_link_variable_declare (const char *variable)
645 instr_user_variable(0, nullptr, variable, "LINK", 0, INSTR_US_DECLARE, nullptr, &user_link_variables);
648 /** \ingroup TRACE_user_variables
649 * \brief Declare a new user variable associated to links with a color.
651 * Same as #TRACE_link_variable_declare, but associated a color to the newly created user link variable. The color
652 * needs to be a string with three numbers separated by spaces in the range [0,1].
653 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
655 * \param variable The name of the new variable to be declared.
656 * \param color The color for the new variable.
658 void TRACE_link_variable_declare_with_color (const char *variable, const char *color)
660 instr_user_variable(0, nullptr, variable, "LINK", 0, INSTR_US_DECLARE, color, &user_link_variables);
663 /** \ingroup TRACE_user_variables
664 * \brief Set the value of a variable of a link.
666 * \param link The name of the link to be considered.
667 * \param variable The name of the variable to be considered.
668 * \param value The new value of the variable.
670 * \see TRACE_link_variable_declare, TRACE_link_variable_add, TRACE_link_variable_sub
672 void TRACE_link_variable_set (const char *link, const char *variable, double value)
674 TRACE_link_variable_set_with_time (MSG_get_clock(), link, variable, value);
677 /** \ingroup TRACE_user_variables
678 * \brief Add a value to a variable of a link.
680 * \param link The name of the link to be considered.
681 * \param variable The name of the variable to be considered.
682 * \param value The value to be added to the variable.
684 * \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_sub
686 void TRACE_link_variable_add (const char *link, const char *variable, double value)
688 TRACE_link_variable_add_with_time (MSG_get_clock(), link, variable, value);
691 /** \ingroup TRACE_user_variables
692 * \brief Subtract a value from a variable of a link.
694 * \param link The name of the link to be considered.
695 * \param variable The name of the variable to be considered.
696 * \param value The value to be subtracted from the variable.
698 * \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_add
700 void TRACE_link_variable_sub (const char *link, const char *variable, double value)
702 TRACE_link_variable_sub_with_time (MSG_get_clock(), link, variable, value);
705 /** \ingroup TRACE_user_variables
706 * \brief Set the value of a variable of a link at a given timestamp.
708 * Same as #TRACE_link_variable_set, but let user specify the time used to trace it. Users can specify a time that
709 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
710 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
713 * \param time The timestamp to be used to tag this change of value.
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 new value of the variable.
718 * \see TRACE_link_variable_declare, TRACE_link_variable_add_with_time, TRACE_link_variable_sub_with_time
720 void TRACE_link_variable_set_with_time (double time, const char *link, const char *variable, double value)
722 instr_user_variable(time, link, variable, "LINK", value, INSTR_US_SET, nullptr, &user_link_variables);
725 /** \ingroup TRACE_user_variables
726 * \brief Add a value to a variable of a link at a given timestamp.
728 * Same as #TRACE_link_variable_add, 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 value to be added to the variable.
738 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_sub_with_time
740 void TRACE_link_variable_add_with_time (double time, const char *link, const char *variable, double value)
742 instr_user_variable(time, link, variable, "LINK", value, INSTR_US_ADD, nullptr, &user_link_variables);
745 /** \ingroup TRACE_user_variables
746 * \brief Subtract a value from a variable of a link at a given timestamp.
748 * Same as #TRACE_link_variable_sub, 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 subtracted from the variable.
758 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_add_with_time
760 void TRACE_link_variable_sub_with_time (double time, const char *link, const char *variable, double value)
762 instr_user_variable(time, link, variable, "LINK", value, INSTR_US_SUB, nullptr, &user_link_variables);
765 /* for link variables, but with src and dst used for get_route */
766 /** \ingroup TRACE_user_variables
767 * \brief Set the value of the variable present in the links connecting source and destination.
769 * Same as #TRACE_link_variable_set, but instead of providing the name of link to be considered, provide the source
770 * and destination hosts. All links that are part of the route between source and destination will have the variable
771 * set to the provided value.
773 * \param src The name of the source host for get route.
774 * \param dst The name of the destination host for get route.
775 * \param variable The name of the variable to be considered.
776 * \param value The new value of the variable.
778 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add, TRACE_link_srcdst_variable_sub
780 void TRACE_link_srcdst_variable_set (const char *src, const char *dst, const char *variable, double value)
782 TRACE_link_srcdst_variable_set_with_time (MSG_get_clock(), src, dst, variable, value);
785 /** \ingroup TRACE_user_variables
786 * \brief Add a value to the variable present in the links connecting source and destination.
788 * Same as #TRACE_link_variable_add, but instead of providing the name of link to be considered, provide the source
789 * and destination hosts. All links that are part of the route between source and destination will have the value
790 * passed as parameter added to the current value of the variable name to be considered.
792 * \param src The name of the source host for get route.
793 * \param dst The name of the destination host for get route.
794 * \param variable The name of the variable to be considered.
795 * \param value The value to be added to the variable.
797 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_sub
799 void TRACE_link_srcdst_variable_add (const char *src, const char *dst, const char *variable, double value)
801 TRACE_link_srcdst_variable_add_with_time (MSG_get_clock(), src, dst, variable, value);
804 /** \ingroup TRACE_user_variables
805 * \brief Subtract a value from the variable present in the links connecting source and destination.
807 * Same as #TRACE_link_variable_sub, but instead of providing the name of link to be considered, provide the source
808 * and destination hosts. All links that are part of the route between source and destination will have the value
809 * passed as parameter subtracted from the current value of the variable name to be considered.
811 * \param src The name of the source host for get route.
812 * \param dst The name of the destination host for get route.
813 * \param variable The name of the variable to be considered.
814 * \param value The value to be subtracted from the variable.
816 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_add
818 void TRACE_link_srcdst_variable_sub (const char *src, const char *dst, const char *variable, double value)
820 TRACE_link_srcdst_variable_sub_with_time (MSG_get_clock(), src, dst, variable, value);
823 /** \ingroup TRACE_user_variables
824 * \brief Set the value of the variable present in the links connecting source and destination at a given timestamp.
826 * Same as #TRACE_link_srcdst_variable_set, but let user specify the time used to trace it. Users can specify a time
827 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
828 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
831 * \param time The timestamp to be used to tag this change of value.
832 * \param src The name of the source host for get route.
833 * \param dst The name of the destination host for get route.
834 * \param variable The name of the variable to be considered.
835 * \param value The new value of the variable.
837 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add_with_time, TRACE_link_srcdst_variable_sub_with_time
839 void TRACE_link_srcdst_variable_set_with_time (double time, const char *src, const char *dst, const char *variable,
842 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SET);
845 /** \ingroup TRACE_user_variables
846 * \brief Add a value to the variable present in the links connecting source and destination at a given timestamp.
848 * Same as #TRACE_link_srcdst_variable_add, but let user specify the time used to trace it. Users can specify a time
849 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
850 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
853 * \param time The timestamp to be used to tag this change of value.
854 * \param src The name of the source host for get route.
855 * \param dst The name of the destination host for get route.
856 * \param variable The name of the variable to be considered.
857 * \param value The value to be added to the variable.
859 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_sub_with_time
861 void TRACE_link_srcdst_variable_add_with_time (double time, const char *src, const char *dst, const char *variable,
864 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_ADD);
867 /** \ingroup TRACE_user_variables
868 * \brief Subtract a value from the variable present in the links connecting source and dest. at a given timestamp.
870 * Same as #TRACE_link_srcdst_variable_sub, but let user specify the time used to trace it. Users can specify a time
871 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
872 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
875 * \param time The timestamp to be used to tag this change of value.
876 * \param src The name of the source host for get route.
877 * \param dst The name of the destination host for get route.
878 * \param variable The name of the variable to be considered.
879 * \param value The value to be subtracted from the variable.
881 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_add_with_time
883 void TRACE_link_srcdst_variable_sub_with_time (double time, const char *src, const char *dst, const char *variable,
886 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SUB);
889 /** \ingroup TRACE_user_variables
890 * \brief Get declared user link variables
892 * This function should be used to get link variables that were already declared with #TRACE_link_variable_declare or
893 * with #TRACE_link_variable_declare_with_color.
895 * \return A dynar with the declared link variables, must be freed with xbt_dynar_free.
897 xbt_dynar_t TRACE_get_link_variables ()
899 return instr_set_to_dynar(&user_link_variables);
902 /** \ingroup TRACE_user_variables
903 * \brief Declare a new user state associated to hosts.
905 * Declare a user state that will be associated to hosts.
906 * A user host state can be used to trace application states.
908 * \param state The name of the new state to be declared.
910 * \see TRACE_host_state_declare_value
912 void TRACE_host_state_declare (const char *state)
914 instr_new_user_state_type("HOST", state);
917 /** \ingroup TRACE_user_variables
918 * \brief Declare a new value for a user state associated to hosts.
920 * Declare a value for a state. The color needs to be a string with 3 numbers separated by spaces in the range [0,1].
921 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
923 * \param state The name of the new state to be declared.
924 * \param value The name of the value
925 * \param color The color of the value
927 * \see TRACE_host_state_declare
929 void TRACE_host_state_declare_value (const char *state, const char *value, const char *color)
931 instr_new_value_for_user_state_type (state, value, color);
934 /** \ingroup TRACE_user_variables
935 * \brief Set the user state to the given value.
937 * Change a user state previously declared to the given value.
939 * \param host The name of the host to be considered.
940 * \param state The name of the state previously declared.
941 * \param value The new value of the state.
943 * \see TRACE_host_state_declare, TRACE_host_push_state, TRACE_host_pop_state, TRACE_host_reset_state
945 void TRACE_host_set_state(const char* host, const char* state, const char* value_str)
947 container_t container = PJ_container_get(host);
948 Type* type = PJ_type_get (state, container->type);
950 Value::get_or_new(value_str, nullptr, type); /* if user didn't declare a value with a color, use nullptr color */
951 new SetStateEvent(MSG_get_clock(), container, type, val);
954 /** \ingroup TRACE_user_variables
955 * \brief Push a new value for a state of a given host.
957 * Change a user state previously declared by pushing the new value to the state.
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 value to be pushed.
963 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_pop_state, TRACE_host_reset_state
965 void TRACE_host_push_state(const char* host, const char* state, const char* value_str)
967 container_t container = PJ_container_get(host);
968 Type* type = PJ_type_get (state, container->type);
970 Value::get_or_new(value_str, nullptr, type); /* if user didn't declare a value with a color, use nullptr color */
971 new PushStateEvent(MSG_get_clock(), container, type, val);
974 /** \ingroup TRACE_user_variables
975 * \brief Pop the last value of a state of a given host.
977 * Change a user state previously declared by removing the last value of the state.
979 * \param host The name of the host to be considered.
980 * \param state The name of the state to be popped.
982 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_reset_state
984 void TRACE_host_pop_state (const char *host, const char *state)
986 container_t container = PJ_container_get(host);
987 Type* type = PJ_type_get (state, container->type);
988 new PopStateEvent(MSG_get_clock(), container, type);
991 /** \ingroup TRACE_API
992 * \brief Get Paje container types that can be mapped to the nodes of a graph.
994 * This function can be used to create a user made graph configuration file for Triva. Normally, it is used with the
995 * functions defined in \ref TRACE_user_variables.
997 * \return A dynar with the types, must be freed with xbt_dynar_free.
999 xbt_dynar_t TRACE_get_node_types ()
1001 return instr_set_to_dynar(&trivaNodeTypes);
1004 /** \ingroup TRACE_API
1005 * \brief Get Paje container types that can be mapped to the edges of a graph.
1007 * This function can be used to create a user made graph configuration file for Triva. Normally, it is used with the
1008 * functions defined in \ref TRACE_user_variables.
1010 * \return A dynar with the types, must be freed with xbt_dynar_free.
1012 xbt_dynar_t TRACE_get_edge_types ()
1014 return instr_set_to_dynar(&trivaEdgeTypes);