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 /* for host variables */
489 /** \ingroup TRACE_user_variables
490 * \brief Declare a new user variable associated to hosts.
492 * Declare a user variable that will be associated to hosts.
493 * A user host variable can be used to trace user variables such as the number of tasks in a server, the number of
494 * clients in an application (for hosts), and so on. The color associated to this new variable will be random.
496 * \param variable The name of the new variable to be declared.
498 * \see TRACE_host_variable_declare_with_color
500 void TRACE_host_variable_declare (const char *variable)
502 instr_user_variable(0, nullptr, variable, "HOST", 0, INSTR_US_DECLARE, nullptr, user_host_variables);
505 /** \ingroup TRACE_user_variables
506 * \brief Declare a new user variable associated to hosts with a color.
508 * Same as #TRACE_host_variable_declare, but associated a color to the newly created user host variable. The color
509 * needs to be a string with three numbers separated by spaces in the range [0,1].
510 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
512 * \param variable The name of the new variable to be declared.
513 * \param color The color for the new variable.
515 void TRACE_host_variable_declare_with_color (const char *variable, const char *color)
517 instr_user_variable(0, nullptr, variable, "HOST", 0, INSTR_US_DECLARE, color, user_host_variables);
520 /** \ingroup TRACE_user_variables
521 * \brief Set the value of a variable of a host.
523 * \param host The name of the host to be considered.
524 * \param variable The name of the variable to be considered.
525 * \param value The new value of the variable.
527 * \see TRACE_host_variable_declare, TRACE_host_variable_add, TRACE_host_variable_sub
529 void TRACE_host_variable_set (const char *host, const char *variable, double value)
531 TRACE_host_variable_set_with_time (MSG_get_clock(), host, variable, value);
534 /** \ingroup TRACE_user_variables
535 * \brief Add a value to 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 value to be added to the variable.
541 * \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_sub
543 void TRACE_host_variable_add (const char *host, const char *variable, double value)
545 TRACE_host_variable_add_with_time (MSG_get_clock(), host, variable, value);
548 /** \ingroup TRACE_user_variables
549 * \brief Subtract a value from 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 subtracted from the variable.
555 * \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_add
557 void TRACE_host_variable_sub (const char *host, const char *variable, double value)
559 TRACE_host_variable_sub_with_time (MSG_get_clock(), host, variable, value);
562 /** \ingroup TRACE_user_variables
563 * \brief Set the value of a variable of a host at a given timestamp.
565 * Same as #TRACE_host_variable_set, but let user specify the time used to trace it. Users can specify a time that
566 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
567 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
570 * \param time The timestamp to be used to tag this change of value.
571 * \param host The name of the host to be considered.
572 * \param variable The name of the variable to be considered.
573 * \param value The new value of the variable.
575 * \see TRACE_host_variable_declare, TRACE_host_variable_add_with_time, TRACE_host_variable_sub_with_time
577 void TRACE_host_variable_set_with_time (double time, const char *host, const char *variable, double value)
579 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SET, nullptr, user_host_variables);
582 /** \ingroup TRACE_user_variables
583 * \brief Add a value to a variable of a host at a given timestamp.
585 * Same as #TRACE_host_variable_add, but let user specify the time used to trace it. Users can specify a time that
586 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
587 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
590 * \param time The timestamp to be used to tag this change of value.
591 * \param host The name of the host to be considered.
592 * \param variable The name of the variable to be considered.
593 * \param value The value to be added to the variable.
595 * \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_sub_with_time
597 void TRACE_host_variable_add_with_time (double time, const char *host, const char *variable, double value)
599 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_ADD, nullptr, user_host_variables);
602 /** \ingroup TRACE_user_variables
603 * \brief Subtract a value from a variable of a host at a given timestamp.
605 * Same as #TRACE_host_variable_sub, but let user specify the time used to trace it. Users can specify a time that
606 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
607 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
610 * \param time The timestamp to be used to tag this change of value.
611 * \param host The name of the host to be considered.
612 * \param variable The name of the variable to be considered.
613 * \param value The value to be subtracted from the variable.
615 * \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_add_with_time
617 void TRACE_host_variable_sub_with_time (double time, const char *host, const char *variable, double value)
619 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SUB, nullptr, user_host_variables);
622 /** \ingroup TRACE_user_variables
623 * \brief Get declared user host variables
625 * This function should be used to get host variables that were already declared with #TRACE_host_variable_declare or
626 * with #TRACE_host_variable_declare_with_color.
628 * \return A dynar with the declared host variables, must be freed with xbt_dynar_free.
630 xbt_dynar_t TRACE_get_host_variables ()
632 return instr_dict_to_dynar (user_host_variables);
635 /* for link variables */
636 /** \ingroup TRACE_user_variables
637 * \brief Declare a new user variable associated to links.
639 * Declare a user variable that will be associated to links.
640 * A user link variable can be used, for example, to trace user variables such as the number of messages being
641 * transferred through network links. The color associated to this new variable will be random.
643 * \param variable The name of the new variable to be declared.
645 * \see TRACE_link_variable_declare_with_color
647 void TRACE_link_variable_declare (const char *variable)
649 instr_user_variable (0, nullptr, variable, "LINK", 0, INSTR_US_DECLARE, nullptr, user_link_variables);
652 /** \ingroup TRACE_user_variables
653 * \brief Declare a new user variable associated to links with a color.
655 * Same as #TRACE_link_variable_declare, but associated a color to the newly created user link variable. The color
656 * needs to be a string with three numbers separated by spaces in the range [0,1].
657 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
659 * \param variable The name of the new variable to be declared.
660 * \param color The color for the new variable.
662 void TRACE_link_variable_declare_with_color (const char *variable, const char *color)
664 instr_user_variable (0, nullptr, variable, "LINK", 0, INSTR_US_DECLARE, color, user_link_variables);
667 /** \ingroup TRACE_user_variables
668 * \brief Set the value of a variable of a link.
670 * \param link The name of the link to be considered.
671 * \param variable The name of the variable to be considered.
672 * \param value The new value of the variable.
674 * \see TRACE_link_variable_declare, TRACE_link_variable_add, TRACE_link_variable_sub
676 void TRACE_link_variable_set (const char *link, const char *variable, double value)
678 TRACE_link_variable_set_with_time (MSG_get_clock(), link, variable, value);
681 /** \ingroup TRACE_user_variables
682 * \brief Add a value to 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 value to be added to the variable.
688 * \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_sub
690 void TRACE_link_variable_add (const char *link, const char *variable, double value)
692 TRACE_link_variable_add_with_time (MSG_get_clock(), link, variable, value);
695 /** \ingroup TRACE_user_variables
696 * \brief Subtract a value from 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 subtracted from the variable.
702 * \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_add
704 void TRACE_link_variable_sub (const char *link, const char *variable, double value)
706 TRACE_link_variable_sub_with_time (MSG_get_clock(), link, variable, value);
709 /** \ingroup TRACE_user_variables
710 * \brief Set the value of a variable of a link at a given timestamp.
712 * Same as #TRACE_link_variable_set, but let user specify the time used to trace it. Users can specify a time that
713 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
714 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
717 * \param time The timestamp to be used to tag this change of value.
718 * \param link The name of the link to be considered.
719 * \param variable The name of the variable to be considered.
720 * \param value The new value of the variable.
722 * \see TRACE_link_variable_declare, TRACE_link_variable_add_with_time, TRACE_link_variable_sub_with_time
724 void TRACE_link_variable_set_with_time (double time, const char *link, const char *variable, double value)
726 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SET, nullptr, user_link_variables);
729 /** \ingroup TRACE_user_variables
730 * \brief Add a value to a variable of a link at a given timestamp.
732 * Same as #TRACE_link_variable_add, but let user specify the time used to trace it. Users can specify a time that
733 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
734 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
737 * \param time The timestamp to be used to tag this change of value.
738 * \param link The name of the link to be considered.
739 * \param variable The name of the variable to be considered.
740 * \param value The value to be added to the variable.
742 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_sub_with_time
744 void TRACE_link_variable_add_with_time (double time, const char *link, const char *variable, double value)
746 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_ADD, nullptr, user_link_variables);
749 /** \ingroup TRACE_user_variables
750 * \brief Subtract a value from a variable of a link at a given timestamp.
752 * Same as #TRACE_link_variable_sub, but let user specify the time used to trace it. Users can specify a time that
753 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
754 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
757 * \param time The timestamp to be used to tag this change of value.
758 * \param link The name of the link to be considered.
759 * \param variable The name of the variable to be considered.
760 * \param value The value to be subtracted from the variable.
762 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_add_with_time
764 void TRACE_link_variable_sub_with_time (double time, const char *link, const char *variable, double value)
766 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SUB, nullptr, user_link_variables);
769 /* for link variables, but with src and dst used for get_route */
770 /** \ingroup TRACE_user_variables
771 * \brief Set the value of the variable present in the links connecting source and destination.
773 * Same as #TRACE_link_variable_set, but instead of providing the name of link to be considered, provide the source
774 * and destination hosts. All links that are part of the route between source and destination will have the variable
775 * set to the provided value.
777 * \param src The name of the source host for get route.
778 * \param dst The name of the destination host for get route.
779 * \param variable The name of the variable to be considered.
780 * \param value The new value of the variable.
782 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add, TRACE_link_srcdst_variable_sub
784 void TRACE_link_srcdst_variable_set (const char *src, const char *dst, const char *variable, double value)
786 TRACE_link_srcdst_variable_set_with_time (MSG_get_clock(), src, dst, variable, value);
789 /** \ingroup TRACE_user_variables
790 * \brief Add a value to the variable present in the links connecting source and destination.
792 * Same as #TRACE_link_variable_add, but instead of providing the name of link to be considered, provide the source
793 * and destination hosts. All links that are part of the route between source and destination will have the value
794 * passed as parameter added to the current value of the variable name to be considered.
796 * \param src The name of the source host for get route.
797 * \param dst The name of the destination host for get route.
798 * \param variable The name of the variable to be considered.
799 * \param value The value to be added to the variable.
801 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_sub
803 void TRACE_link_srcdst_variable_add (const char *src, const char *dst, const char *variable, double value)
805 TRACE_link_srcdst_variable_add_with_time (MSG_get_clock(), src, dst, variable, value);
808 /** \ingroup TRACE_user_variables
809 * \brief Subtract a value from the variable present in the links connecting source and destination.
811 * Same as #TRACE_link_variable_sub, but instead of providing the name of link to be considered, provide the source
812 * and destination hosts. All links that are part of the route between source and destination will have the value
813 * passed as parameter subtracted from the current value of the variable name to be considered.
815 * \param src The name of the source host for get route.
816 * \param dst The name of the destination host for get route.
817 * \param variable The name of the variable to be considered.
818 * \param value The value to be subtracted from the variable.
820 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_add
822 void TRACE_link_srcdst_variable_sub (const char *src, const char *dst, const char *variable, double value)
824 TRACE_link_srcdst_variable_sub_with_time (MSG_get_clock(), src, dst, variable, value);
827 /** \ingroup TRACE_user_variables
828 * \brief Set the value of the variable present in the links connecting source and destination at a given timestamp.
830 * Same as #TRACE_link_srcdst_variable_set, but let user specify the time used to trace it. Users can specify a time
831 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
832 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
835 * \param time The timestamp to be used to tag this change of value.
836 * \param src The name of the source host for get route.
837 * \param dst The name of the destination host for get route.
838 * \param variable The name of the variable to be considered.
839 * \param value The new value of the variable.
841 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add_with_time, TRACE_link_srcdst_variable_sub_with_time
843 void TRACE_link_srcdst_variable_set_with_time (double time, const char *src, const char *dst, const char *variable,
846 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SET);
849 /** \ingroup TRACE_user_variables
850 * \brief Add a value to the variable present in the links connecting source and destination at a given timestamp.
852 * Same as #TRACE_link_srcdst_variable_add, but let user specify the time used to trace it. Users can specify a time
853 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
854 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
857 * \param time The timestamp to be used to tag this change of value.
858 * \param src The name of the source host for get route.
859 * \param dst The name of the destination host for get route.
860 * \param variable The name of the variable to be considered.
861 * \param value The value to be added to the variable.
863 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_sub_with_time
865 void TRACE_link_srcdst_variable_add_with_time (double time, const char *src, const char *dst, const char *variable,
868 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_ADD);
871 /** \ingroup TRACE_user_variables
872 * \brief Subtract a value from the variable present in the links connecting source and dest. at a given timestamp.
874 * Same as #TRACE_link_srcdst_variable_sub, but let user specify the time used to trace it. Users can specify a time
875 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
876 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
879 * \param time The timestamp to be used to tag this change of value.
880 * \param src The name of the source host for get route.
881 * \param dst The name of the destination host for get route.
882 * \param variable The name of the variable to be considered.
883 * \param value The value to be subtracted from the variable.
885 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_add_with_time
887 void TRACE_link_srcdst_variable_sub_with_time (double time, const char *src, const char *dst, const char *variable,
890 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SUB);
893 /** \ingroup TRACE_user_variables
894 * \brief Get declared user link variables
896 * This function should be used to get link variables that were already declared with #TRACE_link_variable_declare or
897 * with #TRACE_link_variable_declare_with_color.
899 * \return A dynar with the declared link variables, must be freed with xbt_dynar_free.
901 xbt_dynar_t TRACE_get_link_variables ()
903 return instr_dict_to_dynar (user_link_variables);
906 /** \ingroup TRACE_user_variables
907 * \brief Declare a new user state associated to hosts.
909 * Declare a user state that will be associated to hosts.
910 * A user host state can be used to trace application states.
912 * \param state The name of the new state to be declared.
914 * \see TRACE_host_state_declare_value
916 void TRACE_host_state_declare (const char *state)
918 instr_new_user_state_type("HOST", state);
921 /** \ingroup TRACE_user_variables
922 * \brief Declare a new value for a user state associated to hosts.
924 * Declare a value for a state. The color needs to be a string with 3 numbers separated by spaces in the range [0,1].
925 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
927 * \param state The name of the new state to be declared.
928 * \param value The name of the value
929 * \param color The color of the value
931 * \see TRACE_host_state_declare
933 void TRACE_host_state_declare_value (const char *state, const char *value, const char *color)
935 instr_new_value_for_user_state_type (state, value, color);
938 /** \ingroup TRACE_user_variables
939 * \brief Set the user state to the given value.
941 * Change a user state previously declared to the given value.
943 * \param host The name of the host to be considered.
944 * \param state The name of the state previously declared.
945 * \param value The new value of the state.
947 * \see TRACE_host_state_declare, TRACE_host_push_state, TRACE_host_pop_state, TRACE_host_reset_state
949 void TRACE_host_set_state (const char *host, const char *state, const char *value)
951 container_t container = PJ_container_get(host);
952 type_t type = PJ_type_get (state, container->type);
953 val_t val = PJ_value_get_or_new (value, nullptr, type); /* if user didn't declare a value with a color, use nullptr color */
954 new SetStateEvent(MSG_get_clock(), container, type, val);
957 /** \ingroup TRACE_user_variables
958 * \brief Push a new value for a state of a given host.
960 * Change a user state previously declared by pushing the new value to the state.
962 * \param host The name of the host to be considered.
963 * \param state The name of the state previously declared.
964 * \param value The value to be pushed.
966 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_pop_state, TRACE_host_reset_state
968 void TRACE_host_push_state (const char *host, const char *state, const char *value)
970 container_t container = PJ_container_get(host);
971 type_t type = PJ_type_get (state, container->type);
972 val_t val = PJ_value_get_or_new (value, nullptr, type); /* if user didn't declare a value with a color, use nullptr color */
973 new PushStateEvent(MSG_get_clock(), container, type, val);
976 /** \ingroup TRACE_user_variables
977 * \brief Pop the last value of a state of a given host.
979 * Change a user state previously declared by removing the last value of the state.
981 * \param host The name of the host to be considered.
982 * \param state The name of the state to be popped.
984 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_reset_state
986 void TRACE_host_pop_state (const char *host, const char *state)
988 container_t container = PJ_container_get(host);
989 type_t type = PJ_type_get (state, container->type);
990 new PopStateEvent(MSG_get_clock(), container, type);
993 /** \ingroup TRACE_user_variables
994 * \brief Reset the state of a given host.
996 * Clear all previous values of a user state.
998 * \param host The name of the host to be considered.
999 * \param state The name of the state to be cleared.
1001 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_pop_state
1003 void TRACE_host_reset_state (const char *host, const char *state)
1005 container_t container = PJ_container_get(host);
1006 type_t type = PJ_type_get (state, container->type);
1007 new ResetStateEvent(MSG_get_clock(), container, type);
1010 /** \ingroup TRACE_API
1011 * \brief Get Paje container types that can be mapped to the nodes of a graph.
1013 * This function can be used to create a user made graph configuration file for Triva. Normally, it is used with the
1014 * functions defined in \ref TRACE_user_variables.
1016 * \return A dynar with the types, must be freed with xbt_dynar_free.
1018 xbt_dynar_t TRACE_get_node_types ()
1020 return instr_dict_to_dynar (trivaNodeTypes);
1023 /** \ingroup TRACE_API
1024 * \brief Get Paje container types that can be mapped to the edges 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_edge_types ()
1033 return instr_dict_to_dynar (trivaEdgeTypes);
1036 /** \ingroup TRACE_API
1037 * \brief Pauses all tracing activities.
1042 instr_pause_tracing();
1045 /** \ingroup TRACE_API
1046 * \brief Resumes all tracing activities.
1049 void TRACE_resume ()
1051 instr_resume_tracing();