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"
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 (not TRACE_is_enabled() || not 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, SD_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, SD_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 (not TRACE_is_enabled() || not TRACE_needs_platform())
87 if (not(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 double red = drand48();
101 double green = drand48();
102 double blue = drand48();
103 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%f %f %f", red, green, blue);
105 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
108 XBT_DEBUG("CAT,declare %s, \"%s\" \"%s\"", category, color, final_color);
110 //define the type of this category on top of hosts and links
111 instr_new_variable_type (category, final_color);
114 /** \ingroup TRACE_category
115 * \brief Get declared categories
117 * This function should be used to get categories that were already declared with #TRACE_category or with
118 * #TRACE_category_with_color.
120 * See \ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
122 * \return A dynar with the declared categories, must be freed with xbt_dynar_free.
124 * \see MSG_task_set_category, SD_task_set_category
126 xbt_dynar_t TRACE_get_categories ()
128 if (not TRACE_is_enabled() || not TRACE_categorized())
131 return instr_dict_to_dynar (created_categories);
134 /** \ingroup TRACE_mark
135 * \brief Declare a new type for tracing mark.
137 * This function declares a new Paje event type in the trace file that can be used by simulators to declare
138 * application-level marks. This function is independent of which API is used in SimGrid.
140 * \param mark_type The name of the new type.
144 void TRACE_declare_mark(const char *mark_type)
146 /* safe switchs. tracing has to be activated and if platform is not traced, we can't deal with marks */
147 if (not TRACE_is_enabled() || not TRACE_needs_platform())
151 THROWF (tracing_error, 1, "mark_type is nullptr");
153 //check if mark_type is already declared
154 if (xbt_dict_get_or_null(declared_marks, mark_type) != nullptr) {
155 THROWF (tracing_error, 1, "mark_type with name (%s) is already declared", mark_type);
158 XBT_DEBUG("MARK,declare %s", mark_type);
159 PJ_type_event_new(mark_type, PJ_type_get_root());
160 xbt_dict_set (declared_marks, mark_type, xbt_strdup("1"), nullptr);
163 /** \ingroup TRACE_mark
164 * \brief Declare a new colored value for a previously declared mark type.
166 * This function declares a new colored value for a Paje event type in the trace file that can be used by simulators to
167 * declare application-level marks. This function is independent of which API is used in SimGrid. The color needs to be
168 * a string with three numbers separated by spaces in the range [0,1].
169 * 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
170 * be white ("1 1 1").
172 * \param mark_type The name of the new type.
173 * \param mark_value The name of the new value for this type.
174 * \param mark_color The color of the new value for this type.
178 void TRACE_declare_mark_value_with_color (const char *mark_type, const char *mark_value, const char *mark_color)
180 /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
181 if (not TRACE_is_enabled() || not TRACE_needs_platform())
185 THROWF (tracing_error, 1, "mark_type is nullptr");
187 THROWF (tracing_error, 1, "mark_value is nullptr");
189 type_t type = PJ_type_get (mark_type, PJ_type_get_root());
191 THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
194 char white[INSTR_DEFAULT_STR_SIZE] = "1.0 1.0 1.0";
198 XBT_DEBUG("MARK,declare_value %s %s %s", mark_type, mark_value, mark_color);
199 PJ_value_new (mark_value, mark_color, type);
202 /** \ingroup TRACE_mark
203 * \brief Declare a new value for a previously declared mark type.
205 * This function declares a new value for a Paje event type in the trace file that can be used by simulators to declare
206 * application-level marks. This function is independent of which API is used in SimGrid. Calling this function is the
207 * same as calling \ref TRACE_declare_mark_value_with_color with a nullptr color.
209 * \param mark_type The name of the new type.
210 * \param mark_value The name of the new value for this type.
214 void TRACE_declare_mark_value (const char *mark_type, const char *mark_value)
216 TRACE_declare_mark_value_with_color (mark_type, mark_value, nullptr);
220 * \ingroup TRACE_mark
221 * \brief Create a new instance of a tracing mark type.
223 * This function creates a mark in the trace file. The first parameter had to be previously declared using
224 * #TRACE_declare_mark, the second is the identifier for this mark instance. We recommend that the mark_value is a
225 * unique value for the whole simulation. Nevertheless, this is not a strong requirement: the trace will be valid even
226 * if there are multiple mark identifiers for the same trace.
228 * \param mark_type The name of the type for which the new instance will belong.
229 * \param mark_value The name of the new instance mark.
231 * \see TRACE_declare_mark
233 void TRACE_mark(const char *mark_type, const char *mark_value)
235 /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
236 if (not TRACE_is_enabled() || not TRACE_needs_platform())
240 THROWF (tracing_error, 1, "mark_type is nullptr");
242 THROWF (tracing_error, 1, "mark_value is nullptr");
244 //check if mark_type is already declared
245 type_t type = PJ_type_get (mark_type, PJ_type_get_root());
247 THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
250 val_t value = PJ_value_get (mark_value, type);
251 XBT_DEBUG("MARK %s %s", mark_type, mark_value);
252 new NewEvent (MSG_get_clock(), PJ_container_get_root(), type, value);
255 /** \ingroup TRACE_mark
256 * \brief Get declared marks
258 * This function should be used to get marks that were already declared with #TRACE_declare_mark.
260 * \return A dynar with the declared marks, must be freed with xbt_dynar_free.
262 xbt_dynar_t TRACE_get_marks ()
264 if (not TRACE_is_enabled())
267 return instr_dict_to_dynar (declared_marks);
270 static void instr_user_variable(double time, const char *resource, const char *variable, const char *father_type,
271 double value, InstrUserVariable what, const char *color, xbt_dict_t filter)
273 /* safe switches. tracing has to be activated and if platform is not traced, we don't allow user variables */
274 if (not TRACE_is_enabled() || not TRACE_needs_platform())
277 //check if variable is already declared
278 char *created = (char*)xbt_dict_get_or_null(filter, variable);
279 if (what == INSTR_US_DECLARE){
280 if (not created) { // not declared yet
281 xbt_dict_set (filter, variable, xbt_strdup("1"), nullptr);
282 instr_new_user_variable_type (father_type, variable, color);
285 if (created) { // declared, let's work
287 snprintf(valuestr, 100, "%g", value);
288 container_t container = PJ_container_get(resource);
289 type_t type = PJ_type_get (variable, container->type);
292 new SetVariableEvent(time, container, type, value);
295 new AddVariableEvent(time, container, type, value);
298 new SubVariableEvent(time, container, type, value);
308 static void instr_user_srcdst_variable(double time, const char *src, const char *dst, const char *variable,
309 const char *father_type, double value, InstrUserVariable what)
311 sg_netpoint_t src_elm = sg_netpoint_by_name_or_null(src);
313 xbt_die("Element '%s' not found!",src);
315 sg_netpoint_t dst_elm = sg_netpoint_by_name_or_null(dst);
317 xbt_die("Element '%s' not found!",dst);
319 std::vector<simgrid::surf::LinkImpl*> route;
320 simgrid::kernel::routing::NetZoneImpl::getGlobalRoute(src_elm, dst_elm, &route, nullptr);
321 for (auto link : route)
322 instr_user_variable(time, link->cname(), variable, father_type, value, what, nullptr, user_link_variables);
325 /** \ingroup TRACE_API
326 * \brief Creates a file with the topology of the platform file used for the simulator.
328 * The graph topology will have the following properties: all hosts, links and routers of the platform file are mapped
329 * to graph nodes; routes are mapped to edges.
330 * The platform's AS are not represented in the output.
332 * \param filename The name of the file that will hold the graph.
334 * \return 1 of successful, 0 otherwise.
336 int TRACE_platform_graph_export_graphviz (const char *filename)
338 /* returns 1 if successful, 0 otherwise */
339 if (not TRACE_is_enabled())
341 xbt_graph_t g = instr_routing_platform_graph();
344 instr_routing_platform_graph_export_graphviz (g, filename);
345 xbt_graph_free_graph(g, xbt_free_f, xbt_free_f, nullptr);
350 * Derived functions that use instr_user_variable and TRACE_user_srcdst_variable. They were previously defined as
351 * pre-processors directives, but were transformed into functions so the user can track them using gdb.
354 /* for VM variables */
355 /** \ingroup TRACE_user_variables
356 * \brief Declare a new user variable associated to VMs.
358 * Declare a user variable that will be associated to VMs. A user vm variable can be used to trace user variables
359 * such as the number of tasks in a VM, the number of clients in an application (for VMs), and so on. The color
360 * associated to this new variable will be random.
362 * \param variable The name of the new variable to be declared.
364 * \see TRACE_vm_variable_declare_with_color
366 void TRACE_vm_variable_declare (const char *variable)
368 instr_user_variable(0, nullptr, variable, "MSG_VM", 0, INSTR_US_DECLARE, nullptr, user_vm_variables);
371 /** \ingroup TRACE_user_variables
372 * \brief Declare a new user variable associated to VMs with a color.
374 * Same as #TRACE_vm_variable_declare, but associated a color to the newly created user host variable. The color needs
375 * to be a string with three numbers separated by spaces in the range [0,1].
376 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
378 * \param variable The name of the new variable to be declared.
379 * \param color The color for the new variable.
381 void TRACE_vm_variable_declare_with_color (const char *variable, const char *color)
383 instr_user_variable(0, nullptr, variable, "MSG_VM", 0, INSTR_US_DECLARE, color, user_vm_variables);
386 /** \ingroup TRACE_user_variables
387 * \brief Set the value of a variable of a host.
389 * \param vm The name of the VM to be considered.
390 * \param variable The name of the variable to be considered.
391 * \param value The new value of the variable.
393 * \see TRACE_vm_variable_declare, TRACE_vm_variable_add, TRACE_vm_variable_sub
395 void TRACE_vm_variable_set (const char *vm, const char *variable, double value)
397 TRACE_vm_variable_set_with_time (MSG_get_clock(), vm, variable, value);
400 /** \ingroup TRACE_user_variables
401 * \brief Add a value to a variable of a VM.
403 * \param vm The name of the VM to be considered.
404 * \param variable The name of the variable to be considered.
405 * \param value The value to be added to the variable.
407 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_sub
409 void TRACE_vm_variable_add (const char *vm, const char *variable, double value)
411 TRACE_vm_variable_add_with_time (MSG_get_clock(), vm, variable, value);
414 /** \ingroup TRACE_user_variables
415 * \brief Subtract a value from a variable of a VM.
417 * \param vm The name of the vm to be considered.
418 * \param variable The name of the variable to be considered.
419 * \param value The value to be subtracted from the variable.
421 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_add
423 void TRACE_vm_variable_sub (const char *vm, const char *variable, double value)
425 TRACE_vm_variable_sub_with_time (MSG_get_clock(), vm, variable, value);
428 /** \ingroup TRACE_user_variables
429 * \brief Set the value of a variable of a VM at a given timestamp.
431 * Same as #TRACE_vm_variable_set, but let user specify the time used to trace it. Users can specify a time that
432 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
433 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
436 * \param time The timestamp to be used to tag this change of value.
437 * \param vm The name of the VM to be considered.
438 * \param variable The name of the variable to be considered.
439 * \param value The new value of the variable.
441 * \see TRACE_vm_variable_declare, TRACE_vm_variable_add_with_time, TRACE_vm_variable_sub_with_time
443 void TRACE_vm_variable_set_with_time (double time, const char *vm, const char *variable, double value)
445 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_SET, nullptr, user_vm_variables);
448 /** \ingroup TRACE_user_variables
449 * \brief Add a value to a variable of a VM at a given timestamp.
451 * Same as #TRACE_vm_variable_add, but let user specify the time used to trace it. Users can specify a time that
452 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
453 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
456 * \param time The timestamp to be used to tag this change of value.
457 * \param vm The name of the VM to be considered.
458 * \param variable The name of the variable to be considered.
459 * \param value The value to be added to the variable.
461 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_sub_with_time
463 void TRACE_vm_variable_add_with_time (double time, const char *vm, const char *variable, double value)
465 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_ADD, nullptr, user_vm_variables);
468 /** \ingroup TRACE_user_variables
469 * \brief Subtract a value from a variable of a VM at a given timestamp.
471 * Same as #TRACE_vm_variable_sub, but let user specify the time used to trace it. Users can specify a time that
472 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
473 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
476 * \param time The timestamp to be used to tag this change of value.
477 * \param vm The name of the VM to be considered.
478 * \param variable The name of the variable to be considered.
479 * \param value The value to be subtracted from the variable.
481 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_add_with_time
483 void TRACE_vm_variable_sub_with_time (double time, const char *vm, const char *variable, double value)
485 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_SUB, nullptr, user_vm_variables);
488 /** \ingroup TRACE_user_variables
489 * \brief Get declared user vm variables
491 * This function should be used to get VM variables that were already declared with #TRACE_vm_variable_declare or with
492 * #TRACE_vm_variable_declare_with_color.
494 * \return A dynar with the declared host variables, must be freed with xbt_dynar_free.
496 xbt_dynar_t TRACE_get_vm_variables ()
498 return instr_dict_to_dynar (user_vm_variables);
501 /* for host variables */
502 /** \ingroup TRACE_user_variables
503 * \brief Declare a new user variable associated to hosts.
505 * Declare a user variable that will be associated to hosts.
506 * A user host variable can be used to trace user variables such as the number of tasks in a server, the number of
507 * clients in an application (for hosts), and so on. The color associated to this new variable will be random.
509 * \param variable The name of the new variable to be declared.
511 * \see TRACE_host_variable_declare_with_color
513 void TRACE_host_variable_declare (const char *variable)
515 instr_user_variable(0, nullptr, variable, "HOST", 0, INSTR_US_DECLARE, nullptr, user_host_variables);
518 /** \ingroup TRACE_user_variables
519 * \brief Declare a new user variable associated to hosts with a color.
521 * Same as #TRACE_host_variable_declare, but associated a color to the newly created user host variable. The color
522 * needs to be a string with three numbers separated by spaces in the range [0,1].
523 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
525 * \param variable The name of the new variable to be declared.
526 * \param color The color for the new variable.
528 void TRACE_host_variable_declare_with_color (const char *variable, const char *color)
530 instr_user_variable(0, nullptr, variable, "HOST", 0, INSTR_US_DECLARE, color, user_host_variables);
533 /** \ingroup TRACE_user_variables
534 * \brief Set the value of a variable of a host.
536 * \param host The name of the host to be considered.
537 * \param variable The name of the variable to be considered.
538 * \param value The new value of the variable.
540 * \see TRACE_host_variable_declare, TRACE_host_variable_add, TRACE_host_variable_sub
542 void TRACE_host_variable_set (const char *host, const char *variable, double value)
544 TRACE_host_variable_set_with_time (MSG_get_clock(), host, variable, value);
547 /** \ingroup TRACE_user_variables
548 * \brief Add a value to a variable of a host.
550 * \param host The name of the host to be considered.
551 * \param variable The name of the variable to be considered.
552 * \param value The value to be added to the variable.
554 * \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_sub
556 void TRACE_host_variable_add (const char *host, const char *variable, double value)
558 TRACE_host_variable_add_with_time (MSG_get_clock(), host, variable, value);
561 /** \ingroup TRACE_user_variables
562 * \brief Subtract a value from a variable of a host.
564 * \param host The name of the host to be considered.
565 * \param variable The name of the variable to be considered.
566 * \param value The value to be subtracted from the variable.
568 * \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_add
570 void TRACE_host_variable_sub (const char *host, const char *variable, double value)
572 TRACE_host_variable_sub_with_time (MSG_get_clock(), host, variable, value);
575 /** \ingroup TRACE_user_variables
576 * \brief Set the value of a variable of a host at a given timestamp.
578 * Same as #TRACE_host_variable_set, but let user specify the time used to trace it. Users can specify a time that
579 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
580 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
583 * \param time The timestamp to be used to tag this change of value.
584 * \param host The name of the host to be considered.
585 * \param variable The name of the variable to be considered.
586 * \param value The new value of the variable.
588 * \see TRACE_host_variable_declare, TRACE_host_variable_add_with_time, TRACE_host_variable_sub_with_time
590 void TRACE_host_variable_set_with_time (double time, const char *host, const char *variable, double value)
592 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SET, nullptr, user_host_variables);
595 /** \ingroup TRACE_user_variables
596 * \brief Add a value to a variable of a host at a given timestamp.
598 * Same as #TRACE_host_variable_add, but let user specify the time used to trace it. Users can specify a time that
599 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
600 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
603 * \param time The timestamp to be used to tag this change of value.
604 * \param host The name of the host to be considered.
605 * \param variable The name of the variable to be considered.
606 * \param value The value to be added to the variable.
608 * \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_sub_with_time
610 void TRACE_host_variable_add_with_time (double time, const char *host, const char *variable, double value)
612 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_ADD, nullptr, user_host_variables);
615 /** \ingroup TRACE_user_variables
616 * \brief Subtract a value from a variable of a host at a given timestamp.
618 * Same as #TRACE_host_variable_sub, but let user specify the time used to trace it. Users can specify a time that
619 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
620 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
623 * \param time The timestamp to be used to tag this change of value.
624 * \param host The name of the host to be considered.
625 * \param variable The name of the variable to be considered.
626 * \param value The value to be subtracted from the variable.
628 * \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_add_with_time
630 void TRACE_host_variable_sub_with_time (double time, const char *host, const char *variable, double value)
632 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SUB, nullptr, user_host_variables);
635 /** \ingroup TRACE_user_variables
636 * \brief Get declared user host variables
638 * This function should be used to get host variables that were already declared with #TRACE_host_variable_declare or
639 * with #TRACE_host_variable_declare_with_color.
641 * \return A dynar with the declared host variables, must be freed with xbt_dynar_free.
643 xbt_dynar_t TRACE_get_host_variables ()
645 return instr_dict_to_dynar (user_host_variables);
648 /* for link variables */
649 /** \ingroup TRACE_user_variables
650 * \brief Declare a new user variable associated to links.
652 * Declare a user variable that will be associated to links.
653 * A user link variable can be used, for example, to trace user variables such as the number of messages being
654 * transferred through network links. The color associated to this new variable will be random.
656 * \param variable The name of the new variable to be declared.
658 * \see TRACE_link_variable_declare_with_color
660 void TRACE_link_variable_declare (const char *variable)
662 instr_user_variable (0, nullptr, variable, "LINK", 0, INSTR_US_DECLARE, nullptr, user_link_variables);
665 /** \ingroup TRACE_user_variables
666 * \brief Declare a new user variable associated to links with a color.
668 * Same as #TRACE_link_variable_declare, but associated a color to the newly created user link variable. The color
669 * needs to be a string with three numbers separated by spaces in the range [0,1].
670 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
672 * \param variable The name of the new variable to be declared.
673 * \param color The color for the new variable.
675 void TRACE_link_variable_declare_with_color (const char *variable, const char *color)
677 instr_user_variable (0, nullptr, variable, "LINK", 0, INSTR_US_DECLARE, color, user_link_variables);
680 /** \ingroup TRACE_user_variables
681 * \brief Set the value of a variable of a link.
683 * \param link The name of the link to be considered.
684 * \param variable The name of the variable to be considered.
685 * \param value The new value of the variable.
687 * \see TRACE_link_variable_declare, TRACE_link_variable_add, TRACE_link_variable_sub
689 void TRACE_link_variable_set (const char *link, const char *variable, double value)
691 TRACE_link_variable_set_with_time (MSG_get_clock(), link, variable, value);
694 /** \ingroup TRACE_user_variables
695 * \brief Add a value to a variable of a link.
697 * \param link The name of the link to be considered.
698 * \param variable The name of the variable to be considered.
699 * \param value The value to be added to the variable.
701 * \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_sub
703 void TRACE_link_variable_add (const char *link, const char *variable, double value)
705 TRACE_link_variable_add_with_time (MSG_get_clock(), link, variable, value);
708 /** \ingroup TRACE_user_variables
709 * \brief Subtract a value from a variable of a link.
711 * \param link The name of the link to be considered.
712 * \param variable The name of the variable to be considered.
713 * \param value The value to be subtracted from the variable.
715 * \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_add
717 void TRACE_link_variable_sub (const char *link, const char *variable, double value)
719 TRACE_link_variable_sub_with_time (MSG_get_clock(), link, variable, value);
722 /** \ingroup TRACE_user_variables
723 * \brief Set the value of a variable of a link at a given timestamp.
725 * Same as #TRACE_link_variable_set, but let user specify the time used to trace it. Users can specify a time that
726 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
727 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
730 * \param time The timestamp to be used to tag this change of value.
731 * \param link The name of the link to be considered.
732 * \param variable The name of the variable to be considered.
733 * \param value The new value of the variable.
735 * \see TRACE_link_variable_declare, TRACE_link_variable_add_with_time, TRACE_link_variable_sub_with_time
737 void TRACE_link_variable_set_with_time (double time, const char *link, const char *variable, double value)
739 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SET, nullptr, user_link_variables);
742 /** \ingroup TRACE_user_variables
743 * \brief Add a value to a variable of a link at a given timestamp.
745 * Same as #TRACE_link_variable_add, but let user specify the time used to trace it. Users can specify a time that
746 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
747 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
750 * \param time The timestamp to be used to tag this change of value.
751 * \param link The name of the link to be considered.
752 * \param variable The name of the variable to be considered.
753 * \param value The value to be added to the variable.
755 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_sub_with_time
757 void TRACE_link_variable_add_with_time (double time, const char *link, const char *variable, double value)
759 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_ADD, nullptr, user_link_variables);
762 /** \ingroup TRACE_user_variables
763 * \brief Subtract a value from a variable of a link at a given timestamp.
765 * Same as #TRACE_link_variable_sub, but let user specify the time used to trace it. Users can specify a time that
766 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
767 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
770 * \param time The timestamp to be used to tag this change of value.
771 * \param link The name of the link to be considered.
772 * \param variable The name of the variable to be considered.
773 * \param value The value to be subtracted from the variable.
775 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_add_with_time
777 void TRACE_link_variable_sub_with_time (double time, const char *link, const char *variable, double value)
779 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SUB, nullptr, user_link_variables);
782 /* for link variables, but with src and dst used for get_route */
783 /** \ingroup TRACE_user_variables
784 * \brief Set the value of the variable present in the links connecting source and destination.
786 * Same as #TRACE_link_variable_set, but instead of providing the name of link to be considered, provide the source
787 * and destination hosts. All links that are part of the route between source and destination will have the variable
788 * set to the provided value.
790 * \param src The name of the source host for get route.
791 * \param dst The name of the destination host for get route.
792 * \param variable The name of the variable to be considered.
793 * \param value The new value of the variable.
795 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add, TRACE_link_srcdst_variable_sub
797 void TRACE_link_srcdst_variable_set (const char *src, const char *dst, const char *variable, double value)
799 TRACE_link_srcdst_variable_set_with_time (MSG_get_clock(), src, dst, variable, value);
802 /** \ingroup TRACE_user_variables
803 * \brief Add a value to the variable present in the links connecting source and destination.
805 * Same as #TRACE_link_variable_add, but instead of providing the name of link to be considered, provide the source
806 * and destination hosts. All links that are part of the route between source and destination will have the value
807 * passed as parameter added to the current value of the variable name to be considered.
809 * \param src The name of the source host for get route.
810 * \param dst The name of the destination host for get route.
811 * \param variable The name of the variable to be considered.
812 * \param value The value to be added to the variable.
814 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_sub
816 void TRACE_link_srcdst_variable_add (const char *src, const char *dst, const char *variable, double value)
818 TRACE_link_srcdst_variable_add_with_time (MSG_get_clock(), src, dst, variable, value);
821 /** \ingroup TRACE_user_variables
822 * \brief Subtract a value from the variable present in the links connecting source and destination.
824 * Same as #TRACE_link_variable_sub, but instead of providing the name of link to be considered, provide the source
825 * and destination hosts. All links that are part of the route between source and destination will have the value
826 * passed as parameter subtracted from the current value of the variable name to be considered.
828 * \param src The name of the source host for get route.
829 * \param dst The name of the destination host for get route.
830 * \param variable The name of the variable to be considered.
831 * \param value The value to be subtracted from the variable.
833 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_add
835 void TRACE_link_srcdst_variable_sub (const char *src, const char *dst, const char *variable, double value)
837 TRACE_link_srcdst_variable_sub_with_time (MSG_get_clock(), src, dst, variable, value);
840 /** \ingroup TRACE_user_variables
841 * \brief Set the value of the variable present in the links connecting source and destination at a given timestamp.
843 * Same as #TRACE_link_srcdst_variable_set, but let user specify the time used to trace it. Users can specify a time
844 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
845 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
848 * \param time The timestamp to be used to tag this change of value.
849 * \param src The name of the source host for get route.
850 * \param dst The name of the destination host for get route.
851 * \param variable The name of the variable to be considered.
852 * \param value The new value of the variable.
854 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add_with_time, TRACE_link_srcdst_variable_sub_with_time
856 void TRACE_link_srcdst_variable_set_with_time (double time, const char *src, const char *dst, const char *variable,
859 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SET);
862 /** \ingroup TRACE_user_variables
863 * \brief Add a value to the variable present in the links connecting source and destination at a given timestamp.
865 * Same as #TRACE_link_srcdst_variable_add, but let user specify the time used to trace it. Users can specify a time
866 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
867 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
870 * \param time The timestamp to be used to tag this change of value.
871 * \param src The name of the source host for get route.
872 * \param dst The name of the destination host for get route.
873 * \param variable The name of the variable to be considered.
874 * \param value The value to be added to the variable.
876 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_sub_with_time
878 void TRACE_link_srcdst_variable_add_with_time (double time, const char *src, const char *dst, const char *variable,
881 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_ADD);
884 /** \ingroup TRACE_user_variables
885 * \brief Subtract a value from the variable present in the links connecting source and dest. at a given timestamp.
887 * Same as #TRACE_link_srcdst_variable_sub, but let user specify the time used to trace it. Users can specify a time
888 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
889 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
892 * \param time The timestamp to be used to tag this change of value.
893 * \param src The name of the source host for get route.
894 * \param dst The name of the destination host for get route.
895 * \param variable The name of the variable to be considered.
896 * \param value The value to be subtracted from the variable.
898 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_add_with_time
900 void TRACE_link_srcdst_variable_sub_with_time (double time, const char *src, const char *dst, const char *variable,
903 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SUB);
906 /** \ingroup TRACE_user_variables
907 * \brief Get declared user link variables
909 * This function should be used to get link variables that were already declared with #TRACE_link_variable_declare or
910 * with #TRACE_link_variable_declare_with_color.
912 * \return A dynar with the declared link variables, must be freed with xbt_dynar_free.
914 xbt_dynar_t TRACE_get_link_variables ()
916 return instr_dict_to_dynar (user_link_variables);
919 /** \ingroup TRACE_user_variables
920 * \brief Declare a new user state associated to hosts.
922 * Declare a user state that will be associated to hosts.
923 * A user host state can be used to trace application states.
925 * \param state The name of the new state to be declared.
927 * \see TRACE_host_state_declare_value
929 void TRACE_host_state_declare (const char *state)
931 instr_new_user_state_type("HOST", state);
934 /** \ingroup TRACE_user_variables
935 * \brief Declare a new value for a user state associated to hosts.
937 * Declare a value for a state. The color needs to be a string with 3 numbers separated by spaces in the range [0,1].
938 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
940 * \param state The name of the new state to be declared.
941 * \param value The name of the value
942 * \param color The color of the value
944 * \see TRACE_host_state_declare
946 void TRACE_host_state_declare_value (const char *state, const char *value, const char *color)
948 instr_new_value_for_user_state_type (state, value, color);
951 /** \ingroup TRACE_user_variables
952 * \brief Set the user state to the given value.
954 * Change a user state previously declared to the given value.
956 * \param host The name of the host to be considered.
957 * \param state The name of the state previously declared.
958 * \param value The new value of the state.
960 * \see TRACE_host_state_declare, TRACE_host_push_state, TRACE_host_pop_state, TRACE_host_reset_state
962 void TRACE_host_set_state (const char *host, const char *state, const char *value)
964 container_t container = PJ_container_get(host);
965 type_t type = PJ_type_get (state, container->type);
966 val_t val = PJ_value_get_or_new (value, nullptr, type); /* if user didn't declare a value with a color, use nullptr color */
967 new SetStateEvent(MSG_get_clock(), container, type, val);
970 /** \ingroup TRACE_user_variables
971 * \brief Push a new value for a state of a given host.
973 * Change a user state previously declared by pushing the new value to the state.
975 * \param host The name of the host to be considered.
976 * \param state The name of the state previously declared.
977 * \param value The value to be pushed.
979 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_pop_state, TRACE_host_reset_state
981 void TRACE_host_push_state (const char *host, const char *state, const char *value)
983 container_t container = PJ_container_get(host);
984 type_t type = PJ_type_get (state, container->type);
985 val_t val = PJ_value_get_or_new (value, nullptr, type); /* if user didn't declare a value with a color, use nullptr color */
986 new PushStateEvent(MSG_get_clock(), container, type, val);
989 /** \ingroup TRACE_user_variables
990 * \brief Pop the last value of a state of a given host.
992 * Change a user state previously declared by removing the last value of the state.
994 * \param host The name of the host to be considered.
995 * \param state The name of the state to be popped.
997 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_reset_state
999 void TRACE_host_pop_state (const char *host, const char *state)
1001 container_t container = PJ_container_get(host);
1002 type_t type = PJ_type_get (state, container->type);
1003 new PopStateEvent(MSG_get_clock(), container, type);
1006 /** \ingroup TRACE_user_variables
1007 * \brief Reset the state of a given host.
1009 * Clear all previous values of a user state.
1011 * \param host The name of the host to be considered.
1012 * \param state The name of the state to be cleared.
1014 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_pop_state
1016 void TRACE_host_reset_state (const char *host, const char *state)
1018 container_t container = PJ_container_get(host);
1019 type_t type = PJ_type_get (state, container->type);
1020 new ResetStateEvent(MSG_get_clock(), container, type);
1023 /** \ingroup TRACE_API
1024 * \brief Get Paje container types that can be mapped to the nodes of a graph.
1026 * This function can be used to create a user made graph configuration file for Triva. Normally, it is used with the
1027 * functions defined in \ref TRACE_user_variables.
1029 * \return A dynar with the types, must be freed with xbt_dynar_free.
1031 xbt_dynar_t TRACE_get_node_types ()
1033 return instr_dict_to_dynar (trivaNodeTypes);
1036 /** \ingroup TRACE_API
1037 * \brief Get Paje container types that can be mapped to the edges of a graph.
1039 * This function can be used to create a user made graph configuration file for Triva. Normally, it is used with the
1040 * functions defined in \ref TRACE_user_variables.
1042 * \return A dynar with the types, must be freed with xbt_dynar_free.
1044 xbt_dynar_t TRACE_get_edge_types ()
1046 return instr_dict_to_dynar (trivaEdgeTypes);
1049 /** \ingroup TRACE_API
1050 * \brief Pauses all tracing activities.
1055 instr_pause_tracing();
1058 /** \ingroup TRACE_API
1059 * \brief Resumes all tracing activities.
1062 void TRACE_resume ()
1064 instr_resume_tracing();