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 (!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, 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 (!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 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 (!TRACE_is_enabled() || !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 (!TRACE_is_enabled() || !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 (!TRACE_is_enabled() || !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 (!TRACE_is_enabled() || !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_pajeNewEvent (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 (!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 (!TRACE_is_enabled() || !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 (!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
288 snprintf(valuestr, 100, "%g", value);
289 container_t container = PJ_container_get(resource);
290 type_t type = PJ_type_get (variable, container->type);
293 new_pajeSetVariable(time, container, type, value);
296 new_pajeAddVariable(time, container, type, value);
299 n.new_pajeSubVariable(time, container, type, value);
309 static void instr_user_srcdst_variable(double time, const char *src, const char *dst, const char *variable,
310 const char *father_type, double value, InstrUserVariable what)
312 sg_netpoint_t src_elm = sg_netpoint_by_name_or_null(src);
314 xbt_die("Element '%s' not found!",src);
316 sg_netpoint_t dst_elm = sg_netpoint_by_name_or_null(dst);
318 xbt_die("Element '%s' not found!",dst);
320 std::vector<simgrid::surf::LinkImpl*> route;
321 simgrid::kernel::routing::NetZoneImpl::getGlobalRoute(src_elm, dst_elm, &route, nullptr);
322 for (auto link : route)
323 instr_user_variable(time, link->cname(), variable, father_type, value, what, nullptr, user_link_variables);
326 /** \ingroup TRACE_API
327 * \brief Creates a file with the topology of the platform file used for the simulator.
329 * The graph topology will have the following properties: all hosts, links and routers of the platform file are mapped
330 * to graph nodes; routes are mapped to edges.
331 * The platform's AS are not represented in the output.
333 * \param filename The name of the file that will hold the graph.
335 * \return 1 of successful, 0 otherwise.
337 int TRACE_platform_graph_export_graphviz (const char *filename)
339 /* returns 1 if successful, 0 otherwise */
340 if (!TRACE_is_enabled())
342 xbt_graph_t g = instr_routing_platform_graph();
345 instr_routing_platform_graph_export_graphviz (g, filename);
346 xbt_graph_free_graph(g, xbt_free_f, xbt_free_f, nullptr);
351 * Derived functions that use instr_user_variable and TRACE_user_srcdst_variable. They were previously defined as
352 * pre-processors directives, but were transformed into functions so the user can track them using gdb.
355 /* for VM variables */
356 /** \ingroup TRACE_user_variables
357 * \brief Declare a new user variable associated to VMs.
359 * Declare a user variable that will be associated to VMs. A user vm variable can be used to trace user variables
360 * such as the number of tasks in a VM, the number of clients in an application (for VMs), and so on. The color
361 * associated to this new variable will be random.
363 * \param variable The name of the new variable to be declared.
365 * \see TRACE_vm_variable_declare_with_color
367 void TRACE_vm_variable_declare (const char *variable)
369 instr_user_variable(0, nullptr, variable, "MSG_VM", 0, INSTR_US_DECLARE, nullptr, user_vm_variables);
372 /** \ingroup TRACE_user_variables
373 * \brief Declare a new user variable associated to VMs with a color.
375 * Same as #TRACE_vm_variable_declare, but associated a color to the newly created user host variable. The color needs
376 * to be a string with three numbers separated by spaces in the range [0,1].
377 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
379 * \param variable The name of the new variable to be declared.
380 * \param color The color for the new variable.
382 void TRACE_vm_variable_declare_with_color (const char *variable, const char *color)
384 instr_user_variable(0, nullptr, variable, "MSG_VM", 0, INSTR_US_DECLARE, color, user_vm_variables);
387 /** \ingroup TRACE_user_variables
388 * \brief Set the value of a variable of a host.
390 * \param vm The name of the VM to be considered.
391 * \param variable The name of the variable to be considered.
392 * \param value The new value of the variable.
394 * \see TRACE_vm_variable_declare, TRACE_vm_variable_add, TRACE_vm_variable_sub
396 void TRACE_vm_variable_set (const char *vm, const char *variable, double value)
398 TRACE_vm_variable_set_with_time (MSG_get_clock(), vm, variable, value);
401 /** \ingroup TRACE_user_variables
402 * \brief Add a value to a variable of a VM.
404 * \param vm The name of the VM to be considered.
405 * \param variable The name of the variable to be considered.
406 * \param value The value to be added to the variable.
408 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_sub
410 void TRACE_vm_variable_add (const char *vm, const char *variable, double value)
412 TRACE_vm_variable_add_with_time (MSG_get_clock(), vm, variable, value);
415 /** \ingroup TRACE_user_variables
416 * \brief Subtract a value from a variable of a VM.
418 * \param vm The name of the vm to be considered.
419 * \param variable The name of the variable to be considered.
420 * \param value The value to be subtracted from the variable.
422 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_add
424 void TRACE_vm_variable_sub (const char *vm, const char *variable, double value)
426 TRACE_vm_variable_sub_with_time (MSG_get_clock(), vm, variable, value);
429 /** \ingroup TRACE_user_variables
430 * \brief Set the value of a variable of a VM at a given timestamp.
432 * Same as #TRACE_vm_variable_set, but let user specify the time used to trace it. Users can specify a time that
433 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
434 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
437 * \param time The timestamp to be used to tag this change of value.
438 * \param vm The name of the VM to be considered.
439 * \param variable The name of the variable to be considered.
440 * \param value The new value of the variable.
442 * \see TRACE_vm_variable_declare, TRACE_vm_variable_add_with_time, TRACE_vm_variable_sub_with_time
444 void TRACE_vm_variable_set_with_time (double time, const char *vm, const char *variable, double value)
446 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_SET, nullptr, user_vm_variables);
449 /** \ingroup TRACE_user_variables
450 * \brief Add a value to a variable of a VM at a given timestamp.
452 * Same as #TRACE_vm_variable_add, but let user specify the time used to trace it. Users can specify a time that
453 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
454 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
457 * \param time The timestamp to be used to tag this change of value.
458 * \param vm The name of the VM to be considered.
459 * \param variable The name of the variable to be considered.
460 * \param value The value to be added to the variable.
462 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_sub_with_time
464 void TRACE_vm_variable_add_with_time (double time, const char *vm, const char *variable, double value)
466 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_ADD, nullptr, user_vm_variables);
469 /** \ingroup TRACE_user_variables
470 * \brief Subtract a value from a variable of a VM at a given timestamp.
472 * Same as #TRACE_vm_variable_sub, but let user specify the time used to trace it. Users can specify a time that
473 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
474 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
477 * \param time The timestamp to be used to tag this change of value.
478 * \param vm The name of the VM to be considered.
479 * \param variable The name of the variable to be considered.
480 * \param value The value to be subtracted from the variable.
482 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_add_with_time
484 void TRACE_vm_variable_sub_with_time (double time, const char *vm, const char *variable, double value)
486 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_SUB, nullptr, user_vm_variables);
489 /** \ingroup TRACE_user_variables
490 * \brief Get declared user vm variables
492 * This function should be used to get VM variables that were already declared with #TRACE_vm_variable_declare or with
493 * #TRACE_vm_variable_declare_with_color.
495 * \return A dynar with the declared host variables, must be freed with xbt_dynar_free.
497 xbt_dynar_t TRACE_get_vm_variables ()
499 return instr_dict_to_dynar (user_vm_variables);
502 /* for host variables */
503 /** \ingroup TRACE_user_variables
504 * \brief Declare a new user variable associated to hosts.
506 * Declare a user variable that will be associated to hosts.
507 * A user host variable can be used to trace user variables such as the number of tasks in a server, the number of
508 * clients in an application (for hosts), and so on. The color associated to this new variable will be random.
510 * \param variable The name of the new variable to be declared.
512 * \see TRACE_host_variable_declare_with_color
514 void TRACE_host_variable_declare (const char *variable)
516 instr_user_variable(0, nullptr, variable, "HOST", 0, INSTR_US_DECLARE, nullptr, user_host_variables);
519 /** \ingroup TRACE_user_variables
520 * \brief Declare a new user variable associated to hosts with a color.
522 * Same as #TRACE_host_variable_declare, but associated a color to the newly created user host variable. The color
523 * needs to be a string with three numbers separated by spaces in the range [0,1].
524 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
526 * \param variable The name of the new variable to be declared.
527 * \param color The color for the new variable.
529 void TRACE_host_variable_declare_with_color (const char *variable, const char *color)
531 instr_user_variable(0, nullptr, variable, "HOST", 0, INSTR_US_DECLARE, color, user_host_variables);
534 /** \ingroup TRACE_user_variables
535 * \brief Set the value of a variable of a host.
537 * \param host The name of the host to be considered.
538 * \param variable The name of the variable to be considered.
539 * \param value The new value of the variable.
541 * \see TRACE_host_variable_declare, TRACE_host_variable_add, TRACE_host_variable_sub
543 void TRACE_host_variable_set (const char *host, const char *variable, double value)
545 TRACE_host_variable_set_with_time (MSG_get_clock(), host, variable, value);
548 /** \ingroup TRACE_user_variables
549 * \brief Add a value to a variable of a host.
551 * \param host The name of the host to be considered.
552 * \param variable The name of the variable to be considered.
553 * \param value The value to be added to the variable.
555 * \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_sub
557 void TRACE_host_variable_add (const char *host, const char *variable, double value)
559 TRACE_host_variable_add_with_time (MSG_get_clock(), host, variable, value);
562 /** \ingroup TRACE_user_variables
563 * \brief Subtract a value from a variable of a host.
565 * \param host The name of the host to be considered.
566 * \param variable The name of the variable to be considered.
567 * \param value The value to be subtracted from the variable.
569 * \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_add
571 void TRACE_host_variable_sub (const char *host, const char *variable, double value)
573 TRACE_host_variable_sub_with_time (MSG_get_clock(), host, variable, value);
576 /** \ingroup TRACE_user_variables
577 * \brief Set the value of a variable of a host at a given timestamp.
579 * Same as #TRACE_host_variable_set, but let user specify the time used to trace it. Users can specify a time that
580 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
581 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
584 * \param time The timestamp to be used to tag this change of value.
585 * \param host The name of the host to be considered.
586 * \param variable The name of the variable to be considered.
587 * \param value The new value of the variable.
589 * \see TRACE_host_variable_declare, TRACE_host_variable_add_with_time, TRACE_host_variable_sub_with_time
591 void TRACE_host_variable_set_with_time (double time, const char *host, const char *variable, double value)
593 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SET, nullptr, user_host_variables);
596 /** \ingroup TRACE_user_variables
597 * \brief Add a value to a variable of a host at a given timestamp.
599 * Same as #TRACE_host_variable_add, but let user specify the time used to trace it. Users can specify a time that
600 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
601 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
604 * \param time The timestamp to be used to tag this change of value.
605 * \param host The name of the host to be considered.
606 * \param variable The name of the variable to be considered.
607 * \param value The value to be added to the variable.
609 * \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_sub_with_time
611 void TRACE_host_variable_add_with_time (double time, const char *host, const char *variable, double value)
613 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_ADD, nullptr, user_host_variables);
616 /** \ingroup TRACE_user_variables
617 * \brief Subtract a value from a variable of a host at a given timestamp.
619 * Same as #TRACE_host_variable_sub, but let user specify the time used to trace it. Users can specify a time that
620 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
621 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
624 * \param time The timestamp to be used to tag this change of value.
625 * \param host The name of the host to be considered.
626 * \param variable The name of the variable to be considered.
627 * \param value The value to be subtracted from the variable.
629 * \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_add_with_time
631 void TRACE_host_variable_sub_with_time (double time, const char *host, const char *variable, double value)
633 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SUB, nullptr, user_host_variables);
636 /** \ingroup TRACE_user_variables
637 * \brief Get declared user host variables
639 * This function should be used to get host variables that were already declared with #TRACE_host_variable_declare or
640 * with #TRACE_host_variable_declare_with_color.
642 * \return A dynar with the declared host variables, must be freed with xbt_dynar_free.
644 xbt_dynar_t TRACE_get_host_variables ()
646 return instr_dict_to_dynar (user_host_variables);
649 /* for link variables */
650 /** \ingroup TRACE_user_variables
651 * \brief Declare a new user variable associated to links.
653 * Declare a user variable that will be associated to links.
654 * A user link variable can be used, for example, to trace user variables such as the number of messages being
655 * transferred through network links. The color associated to this new variable will be random.
657 * \param variable The name of the new variable to be declared.
659 * \see TRACE_link_variable_declare_with_color
661 void TRACE_link_variable_declare (const char *variable)
663 instr_user_variable (0, nullptr, variable, "LINK", 0, INSTR_US_DECLARE, nullptr, user_link_variables);
666 /** \ingroup TRACE_user_variables
667 * \brief Declare a new user variable associated to links with a color.
669 * Same as #TRACE_link_variable_declare, but associated a color to the newly created user link variable. The color
670 * needs to be a string with three numbers separated by spaces in the range [0,1].
671 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
673 * \param variable The name of the new variable to be declared.
674 * \param color The color for the new variable.
676 void TRACE_link_variable_declare_with_color (const char *variable, const char *color)
678 instr_user_variable (0, nullptr, variable, "LINK", 0, INSTR_US_DECLARE, color, user_link_variables);
681 /** \ingroup TRACE_user_variables
682 * \brief Set the value of a variable of a link.
684 * \param link The name of the link to be considered.
685 * \param variable The name of the variable to be considered.
686 * \param value The new value of the variable.
688 * \see TRACE_link_variable_declare, TRACE_link_variable_add, TRACE_link_variable_sub
690 void TRACE_link_variable_set (const char *link, const char *variable, double value)
692 TRACE_link_variable_set_with_time (MSG_get_clock(), link, variable, value);
695 /** \ingroup TRACE_user_variables
696 * \brief Add a value to a variable of a link.
698 * \param link The name of the link to be considered.
699 * \param variable The name of the variable to be considered.
700 * \param value The value to be added to the variable.
702 * \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_sub
704 void TRACE_link_variable_add (const char *link, const char *variable, double value)
706 TRACE_link_variable_add_with_time (MSG_get_clock(), link, variable, value);
709 /** \ingroup TRACE_user_variables
710 * \brief Subtract a value from a variable of a link.
712 * \param link The name of the link to be considered.
713 * \param variable The name of the variable to be considered.
714 * \param value The value to be subtracted from the variable.
716 * \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_add
718 void TRACE_link_variable_sub (const char *link, const char *variable, double value)
720 TRACE_link_variable_sub_with_time (MSG_get_clock(), link, variable, value);
723 /** \ingroup TRACE_user_variables
724 * \brief Set the value of a variable of a link at a given timestamp.
726 * Same as #TRACE_link_variable_set, but let user specify the time used to trace it. Users can specify a time that
727 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
728 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
731 * \param time The timestamp to be used to tag this change of value.
732 * \param link The name of the link to be considered.
733 * \param variable The name of the variable to be considered.
734 * \param value The new value of the variable.
736 * \see TRACE_link_variable_declare, TRACE_link_variable_add_with_time, TRACE_link_variable_sub_with_time
738 void TRACE_link_variable_set_with_time (double time, const char *link, const char *variable, double value)
740 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SET, nullptr, user_link_variables);
743 /** \ingroup TRACE_user_variables
744 * \brief Add a value to a variable of a link at a given timestamp.
746 * Same as #TRACE_link_variable_add, but let user specify the time used to trace it. Users can specify a time that
747 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
748 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
751 * \param time The timestamp to be used to tag this change of value.
752 * \param link The name of the link to be considered.
753 * \param variable The name of the variable to be considered.
754 * \param value The value to be added to the variable.
756 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_sub_with_time
758 void TRACE_link_variable_add_with_time (double time, const char *link, const char *variable, double value)
760 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_ADD, nullptr, user_link_variables);
763 /** \ingroup TRACE_user_variables
764 * \brief Subtract a value from a variable of a link at a given timestamp.
766 * Same as #TRACE_link_variable_sub, but let user specify the time used to trace it. Users can specify a time that
767 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
768 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
771 * \param time The timestamp to be used to tag this change of value.
772 * \param link The name of the link to be considered.
773 * \param variable The name of the variable to be considered.
774 * \param value The value to be subtracted from the variable.
776 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_add_with_time
778 void TRACE_link_variable_sub_with_time (double time, const char *link, const char *variable, double value)
780 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SUB, nullptr, user_link_variables);
783 /* for link variables, but with src and dst used for get_route */
784 /** \ingroup TRACE_user_variables
785 * \brief Set the value of the variable present in the links connecting source and destination.
787 * Same as #TRACE_link_variable_set, but instead of providing the name of link to be considered, provide the source
788 * and destination hosts. All links that are part of the route between source and destination will have the variable
789 * set to the provided value.
791 * \param src The name of the source host for get route.
792 * \param dst The name of the destination host for get route.
793 * \param variable The name of the variable to be considered.
794 * \param value The new value of the variable.
796 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add, TRACE_link_srcdst_variable_sub
798 void TRACE_link_srcdst_variable_set (const char *src, const char *dst, const char *variable, double value)
800 TRACE_link_srcdst_variable_set_with_time (MSG_get_clock(), src, dst, variable, value);
803 /** \ingroup TRACE_user_variables
804 * \brief Add a value to the variable present in the links connecting source and destination.
806 * Same as #TRACE_link_variable_add, but instead of providing the name of link to be considered, provide the source
807 * and destination hosts. All links that are part of the route between source and destination will have the value
808 * passed as parameter added to the current value of the variable name to be considered.
810 * \param src The name of the source host for get route.
811 * \param dst The name of the destination host for get route.
812 * \param variable The name of the variable to be considered.
813 * \param value The value to be added to the variable.
815 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_sub
817 void TRACE_link_srcdst_variable_add (const char *src, const char *dst, const char *variable, double value)
819 TRACE_link_srcdst_variable_add_with_time (MSG_get_clock(), src, dst, variable, value);
822 /** \ingroup TRACE_user_variables
823 * \brief Subtract a value from the variable present in the links connecting source and destination.
825 * Same as #TRACE_link_variable_sub, but instead of providing the name of link to be considered, provide the source
826 * and destination hosts. All links that are part of the route between source and destination will have the value
827 * passed as parameter subtracted from the current value of the variable name to be considered.
829 * \param src The name of the source host for get route.
830 * \param dst The name of the destination host for get route.
831 * \param variable The name of the variable to be considered.
832 * \param value The value to be subtracted from the variable.
834 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_add
836 void TRACE_link_srcdst_variable_sub (const char *src, const char *dst, const char *variable, double value)
838 TRACE_link_srcdst_variable_sub_with_time (MSG_get_clock(), src, dst, variable, value);
841 /** \ingroup TRACE_user_variables
842 * \brief Set the value of the variable present in the links connecting source and destination at a given timestamp.
844 * Same as #TRACE_link_srcdst_variable_set, but let user specify the time used to trace it. Users can specify a time
845 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
846 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
849 * \param time The timestamp to be used to tag this change of value.
850 * \param src The name of the source host for get route.
851 * \param dst The name of the destination host for get route.
852 * \param variable The name of the variable to be considered.
853 * \param value The new value of the variable.
855 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add_with_time, TRACE_link_srcdst_variable_sub_with_time
857 void TRACE_link_srcdst_variable_set_with_time (double time, const char *src, const char *dst, const char *variable,
860 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SET);
863 /** \ingroup TRACE_user_variables
864 * \brief Add a value to the variable present in the links connecting source and destination at a given timestamp.
866 * Same as #TRACE_link_srcdst_variable_add, but let user specify the time used to trace it. Users can specify a time
867 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
868 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
871 * \param time The timestamp to be used to tag this change of value.
872 * \param src The name of the source host for get route.
873 * \param dst The name of the destination host for get route.
874 * \param variable The name of the variable to be considered.
875 * \param value The value to be added to the variable.
877 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_sub_with_time
879 void TRACE_link_srcdst_variable_add_with_time (double time, const char *src, const char *dst, const char *variable,
882 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_ADD);
885 /** \ingroup TRACE_user_variables
886 * \brief Subtract a value from the variable present in the links connecting source and dest. at a given timestamp.
888 * Same as #TRACE_link_srcdst_variable_sub, but let user specify the time used to trace it. Users can specify a time
889 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
890 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
893 * \param time The timestamp to be used to tag this change of value.
894 * \param src The name of the source host for get route.
895 * \param dst The name of the destination host for get route.
896 * \param variable The name of the variable to be considered.
897 * \param value The value to be subtracted from the variable.
899 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_add_with_time
901 void TRACE_link_srcdst_variable_sub_with_time (double time, const char *src, const char *dst, const char *variable,
904 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SUB);
907 /** \ingroup TRACE_user_variables
908 * \brief Get declared user link variables
910 * This function should be used to get link variables that were already declared with #TRACE_link_variable_declare or
911 * with #TRACE_link_variable_declare_with_color.
913 * \return A dynar with the declared link variables, must be freed with xbt_dynar_free.
915 xbt_dynar_t TRACE_get_link_variables ()
917 return instr_dict_to_dynar (user_link_variables);
920 /** \ingroup TRACE_user_variables
921 * \brief Declare a new user state associated to hosts.
923 * Declare a user state that will be associated to hosts.
924 * A user host state can be used to trace application states.
926 * \param state The name of the new state to be declared.
928 * \see TRACE_host_state_declare_value
930 void TRACE_host_state_declare (const char *state)
932 instr_new_user_state_type("HOST", state);
935 /** \ingroup TRACE_user_variables
936 * \brief Declare a new value for a user state associated to hosts.
938 * Declare a value for a state. The color needs to be a string with 3 numbers separated by spaces in the range [0,1].
939 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
941 * \param state The name of the new state to be declared.
942 * \param value The name of the value
943 * \param color The color of the value
945 * \see TRACE_host_state_declare
947 void TRACE_host_state_declare_value (const char *state, const char *value, const char *color)
949 instr_new_value_for_user_state_type (state, value, color);
952 /** \ingroup TRACE_user_variables
953 * \brief Set the user state to the given value.
955 * Change a user state previously declared to the given value.
957 * \param host The name of the host to be considered.
958 * \param state The name of the state previously declared.
959 * \param value The new value of the state.
961 * \see TRACE_host_state_declare, TRACE_host_push_state, TRACE_host_pop_state, TRACE_host_reset_state
963 void TRACE_host_set_state (const char *host, const char *state, const char *value)
965 container_t container = PJ_container_get(host);
966 type_t type = PJ_type_get (state, container->type);
967 val_t val = PJ_value_get_or_new (value, nullptr, type); /* if user didn't declare a value with a color, use nullptr color */
968 new_pajeSetState(MSG_get_clock(), container, type, val);
971 /** \ingroup TRACE_user_variables
972 * \brief Push a new value for a state of a given host.
974 * Change a user state previously declared by pushing the new value to the state.
976 * \param host The name of the host to be considered.
977 * \param state The name of the state previously declared.
978 * \param value The value to be pushed.
980 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_pop_state, TRACE_host_reset_state
982 void TRACE_host_push_state (const char *host, const char *state, const char *value)
984 container_t container = PJ_container_get(host);
985 type_t type = PJ_type_get (state, container->type);
986 val_t val = PJ_value_get_or_new (value, nullptr, type); /* if user didn't declare a value with a color, use nullptr color */
987 new_pajePushState(MSG_get_clock(), container, type, val);
990 /** \ingroup TRACE_user_variables
991 * \brief Pop the last value of a state of a given host.
993 * Change a user state previously declared by removing the last value of the state.
995 * \param host The name of the host to be considered.
996 * \param state The name of the state to be popped.
998 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_reset_state
1000 void TRACE_host_pop_state (const char *host, const char *state)
1002 container_t container = PJ_container_get(host);
1003 type_t type = PJ_type_get (state, container->type);
1004 new_pajePopState(MSG_get_clock(), container, type);
1007 /** \ingroup TRACE_user_variables
1008 * \brief Reset the state of a given host.
1010 * Clear all previous values of a user state.
1012 * \param host The name of the host to be considered.
1013 * \param state The name of the state to be cleared.
1015 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_pop_state
1017 void TRACE_host_reset_state (const char *host, const char *state)
1019 container_t container = PJ_container_get(host);
1020 type_t type = PJ_type_get (state, container->type);
1021 new_pajeResetState(MSG_get_clock(), container, type);
1024 /** \ingroup TRACE_API
1025 * \brief Get Paje container types that can be mapped to the nodes of a graph.
1027 * This function can be used to create a user made graph configuration file for Triva. Normally, it is used with the
1028 * functions defined in \ref TRACE_user_variables.
1030 * \return A dynar with the types, must be freed with xbt_dynar_free.
1032 xbt_dynar_t TRACE_get_node_types ()
1034 return instr_dict_to_dynar (trivaNodeTypes);
1037 /** \ingroup TRACE_API
1038 * \brief Get Paje container types that can be mapped to the edges of a graph.
1040 * This function can be used to create a user made graph configuration file for Triva. Normally, it is used with the
1041 * functions defined in \ref TRACE_user_variables.
1043 * \return A dynar with the types, must be freed with xbt_dynar_free.
1045 xbt_dynar_t TRACE_get_edge_types ()
1047 return instr_dict_to_dynar (trivaEdgeTypes);
1050 /** \ingroup TRACE_API
1051 * \brief Pauses all tracing activities.
1056 instr_pause_tracing();
1059 /** \ingroup TRACE_API
1060 * \brief Resumes all tracing activities.
1063 void TRACE_resume ()
1065 instr_resume_tracing();