1 /* Copyright (c) 2010-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "simgrid_config.h"
8 #include "src/instr/instr_private.h"
9 #include "src/kernel/routing/NetPoint.hpp"
10 #include "src/surf/network_interface.hpp"
11 #include "src/surf/surf_private.h"
12 #include "surf/surf.h"
22 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API");
24 std::set<std::string> created_categories;
25 std::set<std::string> declared_marks;
26 std::set<std::string> user_host_variables;
27 std::set<std::string> user_vm_variables;
28 std::set<std::string> user_link_variables;
29 extern std::set<std::string> trivaNodeTypes;
30 extern std::set<std::string> trivaEdgeTypes;
32 static xbt_dynar_t instr_set_to_dynar(std::set<std::string>* filter)
34 if (not TRACE_is_enabled() || not TRACE_needs_platform())
37 xbt_dynar_t ret = xbt_dynar_new (sizeof(char*), &xbt_free_ref);
38 for (auto const& name : *filter)
39 xbt_dynar_push_as(ret, char*, xbt_strdup(name.c_str()));
44 /** \ingroup TRACE_category
45 * \brief Declare a new category with a random color.
47 * This function should be used to define a user category. The category can be used to differentiate the tasks that
48 * are created during the simulation (for example, tasks from server1, server2, or request tasks, computation tasks,
49 * communication tasks). All resource utilization (host power and link bandwidth) will be classified according to the
50 * task category. Tasks that do not belong to a category are not traced. The color for the category that is being
51 * declared is random. This function has no effect if a category with the same name has been already declared.
53 * See \ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
55 * \param category The name of the new tracing category to be created.
57 * \see TRACE_category_with_color, MSG_task_set_category, SD_task_set_category
59 void TRACE_category(const char *category)
61 TRACE_category_with_color (category, nullptr);
64 /** \ingroup TRACE_category
65 * \brief Declare a new category with a color.
67 * Same as #TRACE_category, but let user specify a color encoded as a RGB-like string with three floats from 0 to 1.
68 * So, to specify a red color, pass "1 0 0" as color parameter. A light-gray color can be specified using "0.7 0.7 0.7"
69 * as color. This function has no effect if a category with the same name has been already declared.
71 * See \ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
73 * \param category The name of the new tracing category to be created.
74 * \param color The color of the category (see \ref outcomes_vizu to
75 * know how to correctly specify the color)
77 * \see MSG_task_set_category, SD_task_set_category
79 void TRACE_category_with_color (const char *category, const char *color)
81 /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with categories */
82 if (not TRACE_is_enabled() || not TRACE_needs_platform())
85 if (not(TRACE_categorized() && category != nullptr))
88 //check if category is already created
89 if (created_categories.find(category) != created_categories.end())
92 created_categories.insert(category);
95 char final_color[INSTR_DEFAULT_STR_SIZE];
97 //generate a random color
98 double red = drand48();
99 double green = drand48();
100 double blue = drand48();
101 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%f %f %f", red, green, blue);
103 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
106 XBT_DEBUG("CAT,declare %s, \"%s\" \"%s\"", category, color, final_color);
108 //define the type of this category on top of hosts and links
109 instr_new_variable_type (category, final_color);
112 /** \ingroup TRACE_category
113 * \brief Get declared categories
115 * This function should be used to get categories that were already declared with #TRACE_category or with
116 * #TRACE_category_with_color.
118 * See \ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
120 * \return A dynar with the declared categories, must be freed with xbt_dynar_free.
122 * \see MSG_task_set_category, SD_task_set_category
124 xbt_dynar_t TRACE_get_categories ()
126 if (not TRACE_is_enabled() || not TRACE_categorized())
128 return instr_set_to_dynar(&created_categories);
131 /** \ingroup TRACE_mark
132 * \brief Declare a new type for tracing mark.
134 * This function declares a new Paje event type in the trace file that can be used by simulators to declare
135 * application-level marks. This function is independent of which API is used in SimGrid.
137 * \param mark_type The name of the new type.
141 void TRACE_declare_mark(const char *mark_type)
143 /* safe switchs. tracing has to be activated and if platform is not traced, we can't deal with marks */
144 if (not TRACE_is_enabled() || not TRACE_needs_platform())
148 THROWF (tracing_error, 1, "mark_type is nullptr");
150 //check if mark_type is already declared
151 if (declared_marks.find(mark_type) != declared_marks.end()) {
152 THROWF (tracing_error, 1, "mark_type with name (%s) is already declared", mark_type);
155 XBT_DEBUG("MARK,declare %s", mark_type);
156 simgrid::instr::Type::eventNew(mark_type, PJ_type_get_root());
157 declared_marks.insert(mark_type);
160 /** \ingroup TRACE_mark
161 * \brief Declare a new colored value for a previously declared mark type.
163 * This function declares a new colored value for a Paje event type in the trace file that can be used by simulators to
164 * declare application-level marks. This function is independent of which API is used in SimGrid. The color needs to be
165 * a string with three numbers separated by spaces in the range [0,1].
166 * A light-gray color can be specified using "0.7 0.7 0.7" as color. If a nullptr color is provided, the color used will
167 * be white ("1 1 1").
169 * \param mark_type The name of the new type.
170 * \param mark_value The name of the new value for this type.
171 * \param mark_color The color of the new value for this type.
175 void TRACE_declare_mark_value_with_color (const char *mark_type, const char *mark_value, const char *mark_color)
177 /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
178 if (not TRACE_is_enabled() || not TRACE_needs_platform())
182 THROWF (tracing_error, 1, "mark_type is nullptr");
184 THROWF (tracing_error, 1, "mark_value is nullptr");
186 simgrid::instr::Type* type = PJ_type_get_root()->getChild(mark_type);
188 THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
191 char white[INSTR_DEFAULT_STR_SIZE] = "1.0 1.0 1.0";
195 XBT_DEBUG("MARK,declare_value %s %s %s", mark_type, mark_value, mark_color);
196 new simgrid::instr::Value(mark_value, mark_color, type);
199 /** \ingroup TRACE_mark
200 * \brief Declare a new value for a previously declared mark type.
202 * This function declares a new value for a Paje event type in the trace file that can be used by simulators to declare
203 * application-level marks. This function is independent of which API is used in SimGrid. Calling this function is the
204 * same as calling \ref TRACE_declare_mark_value_with_color with a nullptr color.
206 * \param mark_type The name of the new type.
207 * \param mark_value The name of the new value for this type.
211 void TRACE_declare_mark_value (const char *mark_type, const char *mark_value)
213 TRACE_declare_mark_value_with_color (mark_type, mark_value, nullptr);
217 * \ingroup TRACE_mark
218 * \brief Create a new instance of a tracing mark type.
220 * This function creates a mark in the trace file. The first parameter had to be previously declared using
221 * #TRACE_declare_mark, the second is the identifier for this mark instance. We recommend that the mark_value is a
222 * unique value for the whole simulation. Nevertheless, this is not a strong requirement: the trace will be valid even
223 * if there are multiple mark identifiers for the same trace.
225 * \param mark_type The name of the type for which the new instance will belong.
226 * \param mark_value The name of the new instance mark.
228 * \see TRACE_declare_mark
230 void TRACE_mark(const char *mark_type, const char *mark_value)
232 /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
233 if (not TRACE_is_enabled() || not TRACE_needs_platform())
237 THROWF (tracing_error, 1, "mark_type is nullptr");
239 THROWF (tracing_error, 1, "mark_value is nullptr");
241 //check if mark_type is already declared
242 simgrid::instr::Type* type = PJ_type_get_root()->getChild(mark_type);
244 THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
247 XBT_DEBUG("MARK %s %s", mark_type, mark_value);
248 new simgrid::instr::NewEvent(MSG_get_clock(), PJ_container_get_root(), type,
249 simgrid::instr::Value::get(mark_value, type));
252 /** \ingroup TRACE_mark
253 * \brief Get declared marks
255 * This function should be used to get marks that were already declared with #TRACE_declare_mark.
257 * \return A dynar with the declared marks, must be freed with xbt_dynar_free.
259 xbt_dynar_t TRACE_get_marks ()
261 if (not TRACE_is_enabled())
264 return instr_set_to_dynar(&declared_marks);
267 static void instr_user_variable(double time, const char* resource, const char* variable, const char* father_type,
268 double value, InstrUserVariable what, const char* color, std::set<std::string>* filter)
270 /* safe switches. tracing has to be activated and if platform is not traced, we don't allow user variables */
271 if (not TRACE_is_enabled() || not TRACE_needs_platform())
274 //check if variable is already declared
275 auto created = filter->find(variable);
276 if (what == INSTR_US_DECLARE){
277 if (created == filter->end()) { // not declared yet
278 filter->insert(variable);
279 instr_new_user_variable_type (father_type, variable, color);
282 if (created != filter->end()) { // declared, let's work
284 snprintf(valuestr, 100, "%g", value);
285 container_t container = PJ_container_get(resource);
286 simgrid::instr::Type* type = container->type_->getChild(variable);
289 new simgrid::instr::SetVariableEvent(time, container, type, value);
292 new simgrid::instr::AddVariableEvent(time, container, type, value);
295 new simgrid::instr::SubVariableEvent(time, container, type, value);
305 static void instr_user_srcdst_variable(double time, const char *src, const char *dst, const char *variable,
306 const char *father_type, double value, InstrUserVariable what)
308 sg_netpoint_t src_elm = sg_netpoint_by_name_or_null(src);
310 xbt_die("Element '%s' not found!",src);
312 sg_netpoint_t dst_elm = sg_netpoint_by_name_or_null(dst);
314 xbt_die("Element '%s' not found!",dst);
316 std::vector<simgrid::surf::LinkImpl*> route;
317 simgrid::kernel::routing::NetZoneImpl::getGlobalRoute(src_elm, dst_elm, &route, nullptr);
318 for (auto const& link : route)
319 instr_user_variable(time, link->cname(), variable, father_type, value, what, nullptr, &user_link_variables);
322 /** \ingroup TRACE_API
323 * \brief Creates a file with the topology of the platform file used for the simulator.
325 * The graph topology will have the following properties: all hosts, links and routers of the platform file are mapped
326 * to graph nodes; routes are mapped to edges.
327 * The platform's AS are not represented in the output.
329 * \param filename The name of the file that will hold the graph.
331 * \return 1 of successful, 0 otherwise.
333 int TRACE_platform_graph_export_graphviz (const char *filename)
335 /* returns 1 if successful, 0 otherwise */
336 if (not TRACE_is_enabled())
338 xbt_graph_t g = instr_routing_platform_graph();
341 instr_routing_platform_graph_export_graphviz (g, filename);
342 xbt_graph_free_graph(g, xbt_free_f, xbt_free_f, nullptr);
347 * Derived functions that use instr_user_variable and TRACE_user_srcdst_variable. They were previously defined as
348 * pre-processors directives, but were transformed into functions so the user can track them using gdb.
351 /* for VM variables */
352 /** \ingroup TRACE_user_variables
353 * \brief Declare a new user variable associated to VMs.
355 * Declare a user variable that will be associated to VMs. A user vm variable can be used to trace user variables
356 * such as the number of tasks in a VM, the number of clients in an application (for VMs), and so on. The color
357 * associated to this new variable will be random.
359 * \param variable The name of the new variable to be declared.
361 * \see TRACE_vm_variable_declare_with_color
363 void TRACE_vm_variable_declare (const char *variable)
365 instr_user_variable(0, nullptr, variable, "MSG_VM", 0, INSTR_US_DECLARE, nullptr, &user_vm_variables);
368 /** \ingroup TRACE_user_variables
369 * \brief Declare a new user variable associated to VMs with a color.
371 * Same as #TRACE_vm_variable_declare, but associated a color to the newly created user host variable. The color needs
372 * to be a string with three numbers separated by spaces in the range [0,1].
373 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
375 * \param variable The name of the new variable to be declared.
376 * \param color The color for the new variable.
378 void TRACE_vm_variable_declare_with_color (const char *variable, const char *color)
380 instr_user_variable(0, nullptr, variable, "MSG_VM", 0, INSTR_US_DECLARE, color, &user_vm_variables);
383 /** \ingroup TRACE_user_variables
384 * \brief Set the value of a variable of a host.
386 * \param vm The name of the VM to be considered.
387 * \param variable The name of the variable to be considered.
388 * \param value The new value of the variable.
390 * \see TRACE_vm_variable_declare, TRACE_vm_variable_add, TRACE_vm_variable_sub
392 void TRACE_vm_variable_set (const char *vm, const char *variable, double value)
394 TRACE_vm_variable_set_with_time (MSG_get_clock(), vm, variable, value);
397 /** \ingroup TRACE_user_variables
398 * \brief Add a value to a variable of a VM.
400 * \param vm The name of the VM to be considered.
401 * \param variable The name of the variable to be considered.
402 * \param value The value to be added to the variable.
404 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_sub
406 void TRACE_vm_variable_add (const char *vm, const char *variable, double value)
408 TRACE_vm_variable_add_with_time (MSG_get_clock(), vm, variable, value);
411 /** \ingroup TRACE_user_variables
412 * \brief Subtract a value from a variable of a VM.
414 * \param vm The name of the vm to be considered.
415 * \param variable The name of the variable to be considered.
416 * \param value The value to be subtracted from the variable.
418 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_add
420 void TRACE_vm_variable_sub (const char *vm, const char *variable, double value)
422 TRACE_vm_variable_sub_with_time (MSG_get_clock(), vm, variable, value);
425 /** \ingroup TRACE_user_variables
426 * \brief Set the value of a variable of a VM at a given timestamp.
428 * Same as #TRACE_vm_variable_set, but let user specify the time used to trace it. Users can specify a time that
429 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
430 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
433 * \param time The timestamp to be used to tag this change of value.
434 * \param vm The name of the VM to be considered.
435 * \param variable The name of the variable to be considered.
436 * \param value The new value of the variable.
438 * \see TRACE_vm_variable_declare, TRACE_vm_variable_add_with_time, TRACE_vm_variable_sub_with_time
440 void TRACE_vm_variable_set_with_time (double time, const char *vm, const char *variable, double value)
442 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_SET, nullptr, &user_vm_variables);
445 /** \ingroup TRACE_user_variables
446 * \brief Add a value to a variable of a VM at a given timestamp.
448 * Same as #TRACE_vm_variable_add, but let user specify the time used to trace it. Users can specify a time that
449 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
450 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
453 * \param time The timestamp to be used to tag this change of value.
454 * \param vm The name of the VM to be considered.
455 * \param variable The name of the variable to be considered.
456 * \param value The value to be added to the variable.
458 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_sub_with_time
460 void TRACE_vm_variable_add_with_time (double time, const char *vm, const char *variable, double value)
462 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_ADD, nullptr, &user_vm_variables);
465 /** \ingroup TRACE_user_variables
466 * \brief Subtract a value from a variable of a VM at a given timestamp.
468 * Same as #TRACE_vm_variable_sub, but let user specify the time used to trace it. Users can specify a time that
469 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
470 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
473 * \param time The timestamp to be used to tag this change of value.
474 * \param vm The name of the VM to be considered.
475 * \param variable The name of the variable to be considered.
476 * \param value The value to be subtracted from the variable.
478 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_add_with_time
480 void TRACE_vm_variable_sub_with_time (double time, const char *vm, const char *variable, double value)
482 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_SUB, nullptr, &user_vm_variables);
485 /* for host variables */
486 /** \ingroup TRACE_user_variables
487 * \brief Declare a new user variable associated to hosts.
489 * Declare a user variable that will be associated to hosts.
490 * A user host variable can be used to trace user variables such as the number of tasks in a server, the number of
491 * clients in an application (for hosts), and so on. The color associated to this new variable will be random.
493 * \param variable The name of the new variable to be declared.
495 * \see TRACE_host_variable_declare_with_color
497 void TRACE_host_variable_declare (const char *variable)
499 instr_user_variable(0, nullptr, variable, "HOST", 0, INSTR_US_DECLARE, nullptr, &user_host_variables);
502 /** \ingroup TRACE_user_variables
503 * \brief Declare a new user variable associated to hosts with a color.
505 * Same as #TRACE_host_variable_declare, but associated a color to the newly created user host variable. The color
506 * needs to be a string with three numbers separated by spaces in the range [0,1].
507 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
509 * \param variable The name of the new variable to be declared.
510 * \param color The color for the new variable.
512 void TRACE_host_variable_declare_with_color (const char *variable, const char *color)
514 instr_user_variable(0, nullptr, variable, "HOST", 0, INSTR_US_DECLARE, color, &user_host_variables);
517 /** \ingroup TRACE_user_variables
518 * \brief Set the value of a variable of a host.
520 * \param host The name of the host to be considered.
521 * \param variable The name of the variable to be considered.
522 * \param value The new value of the variable.
524 * \see TRACE_host_variable_declare, TRACE_host_variable_add, TRACE_host_variable_sub
526 void TRACE_host_variable_set (const char *host, const char *variable, double value)
528 TRACE_host_variable_set_with_time (MSG_get_clock(), host, variable, value);
531 /** \ingroup TRACE_user_variables
532 * \brief Add a value to a variable of a host.
534 * \param host The name of the host to be considered.
535 * \param variable The name of the variable to be considered.
536 * \param value The value to be added to the variable.
538 * \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_sub
540 void TRACE_host_variable_add (const char *host, const char *variable, double value)
542 TRACE_host_variable_add_with_time (MSG_get_clock(), host, variable, value);
545 /** \ingroup TRACE_user_variables
546 * \brief Subtract a value from a variable of a host.
548 * \param host The name of the host to be considered.
549 * \param variable The name of the variable to be considered.
550 * \param value The value to be subtracted from the variable.
552 * \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_add
554 void TRACE_host_variable_sub (const char *host, const char *variable, double value)
556 TRACE_host_variable_sub_with_time (MSG_get_clock(), host, variable, value);
559 /** \ingroup TRACE_user_variables
560 * \brief Set the value of a variable of a host at a given timestamp.
562 * Same as #TRACE_host_variable_set, but let user specify the time used to trace it. Users can specify a time that
563 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
564 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
567 * \param time The timestamp to be used to tag this change of value.
568 * \param host The name of the host to be considered.
569 * \param variable The name of the variable to be considered.
570 * \param value The new value of the variable.
572 * \see TRACE_host_variable_declare, TRACE_host_variable_add_with_time, TRACE_host_variable_sub_with_time
574 void TRACE_host_variable_set_with_time (double time, const char *host, const char *variable, double value)
576 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SET, nullptr, &user_host_variables);
579 /** \ingroup TRACE_user_variables
580 * \brief Add a value to a variable of a host at a given timestamp.
582 * Same as #TRACE_host_variable_add, but let user specify the time used to trace it. Users can specify a time that
583 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
584 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
587 * \param time The timestamp to be used to tag this change of value.
588 * \param host The name of the host to be considered.
589 * \param variable The name of the variable to be considered.
590 * \param value The value to be added to the variable.
592 * \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_sub_with_time
594 void TRACE_host_variable_add_with_time (double time, const char *host, const char *variable, double value)
596 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_ADD, nullptr, &user_host_variables);
599 /** \ingroup TRACE_user_variables
600 * \brief Subtract a value from a variable of a host at a given timestamp.
602 * Same as #TRACE_host_variable_sub, but let user specify the time used to trace it. Users can specify a time that
603 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
604 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
607 * \param time The timestamp to be used to tag this change of value.
608 * \param host The name of the host to be considered.
609 * \param variable The name of the variable to be considered.
610 * \param value The value to be subtracted from the variable.
612 * \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_add_with_time
614 void TRACE_host_variable_sub_with_time (double time, const char *host, const char *variable, double value)
616 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SUB, nullptr, &user_host_variables);
619 /** \ingroup TRACE_user_variables
620 * \brief Get declared user host variables
622 * This function should be used to get host variables that were already declared with #TRACE_host_variable_declare or
623 * with #TRACE_host_variable_declare_with_color.
625 * \return A dynar with the declared host variables, must be freed with xbt_dynar_free.
627 xbt_dynar_t TRACE_get_host_variables ()
629 return instr_set_to_dynar(&user_host_variables);
632 /* for link variables */
633 /** \ingroup TRACE_user_variables
634 * \brief Declare a new user variable associated to links.
636 * Declare a user variable that will be associated to links.
637 * A user link variable can be used, for example, to trace user variables such as the number of messages being
638 * transferred through network links. The color associated to this new variable will be random.
640 * \param variable The name of the new variable to be declared.
642 * \see TRACE_link_variable_declare_with_color
644 void TRACE_link_variable_declare (const char *variable)
646 instr_user_variable(0, nullptr, variable, "LINK", 0, INSTR_US_DECLARE, nullptr, &user_link_variables);
649 /** \ingroup TRACE_user_variables
650 * \brief Declare a new user variable associated to links with a color.
652 * Same as #TRACE_link_variable_declare, but associated a color to the newly created user link variable. The color
653 * needs to be a string with three numbers separated by spaces in the range [0,1].
654 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
656 * \param variable The name of the new variable to be declared.
657 * \param color The color for the new variable.
659 void TRACE_link_variable_declare_with_color (const char *variable, const char *color)
661 instr_user_variable(0, nullptr, variable, "LINK", 0, INSTR_US_DECLARE, color, &user_link_variables);
664 /** \ingroup TRACE_user_variables
665 * \brief Set the value of a variable of a link.
667 * \param link The name of the link to be considered.
668 * \param variable The name of the variable to be considered.
669 * \param value The new value of the variable.
671 * \see TRACE_link_variable_declare, TRACE_link_variable_add, TRACE_link_variable_sub
673 void TRACE_link_variable_set (const char *link, const char *variable, double value)
675 TRACE_link_variable_set_with_time (MSG_get_clock(), link, variable, value);
678 /** \ingroup TRACE_user_variables
679 * \brief Add a value to a variable of a link.
681 * \param link The name of the link to be considered.
682 * \param variable The name of the variable to be considered.
683 * \param value The value to be added to the variable.
685 * \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_sub
687 void TRACE_link_variable_add (const char *link, const char *variable, double value)
689 TRACE_link_variable_add_with_time (MSG_get_clock(), link, variable, value);
692 /** \ingroup TRACE_user_variables
693 * \brief Subtract a value from a variable of a link.
695 * \param link The name of the link to be considered.
696 * \param variable The name of the variable to be considered.
697 * \param value The value to be subtracted from the variable.
699 * \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_add
701 void TRACE_link_variable_sub (const char *link, const char *variable, double value)
703 TRACE_link_variable_sub_with_time (MSG_get_clock(), link, variable, value);
706 /** \ingroup TRACE_user_variables
707 * \brief Set the value of a variable of a link at a given timestamp.
709 * Same as #TRACE_link_variable_set, but let user specify the time used to trace it. Users can specify a time that
710 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
711 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
714 * \param time The timestamp to be used to tag this change of value.
715 * \param link The name of the link to be considered.
716 * \param variable The name of the variable to be considered.
717 * \param value The new value of the variable.
719 * \see TRACE_link_variable_declare, TRACE_link_variable_add_with_time, TRACE_link_variable_sub_with_time
721 void TRACE_link_variable_set_with_time (double time, const char *link, const char *variable, double value)
723 instr_user_variable(time, link, variable, "LINK", value, INSTR_US_SET, nullptr, &user_link_variables);
726 /** \ingroup TRACE_user_variables
727 * \brief Add a value to a variable of a link at a given timestamp.
729 * Same as #TRACE_link_variable_add, but let user specify the time used to trace it. Users can specify a time that
730 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
731 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
734 * \param time The timestamp to be used to tag this change of value.
735 * \param link The name of the link to be considered.
736 * \param variable The name of the variable to be considered.
737 * \param value The value to be added to the variable.
739 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_sub_with_time
741 void TRACE_link_variable_add_with_time (double time, const char *link, const char *variable, double value)
743 instr_user_variable(time, link, variable, "LINK", value, INSTR_US_ADD, nullptr, &user_link_variables);
746 /** \ingroup TRACE_user_variables
747 * \brief Subtract a value from a variable of a link at a given timestamp.
749 * Same as #TRACE_link_variable_sub, but let user specify the time used to trace it. Users can specify a time that
750 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
751 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
754 * \param time The timestamp to be used to tag this change of value.
755 * \param link The name of the link to be considered.
756 * \param variable The name of the variable to be considered.
757 * \param value The value to be subtracted from the variable.
759 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_add_with_time
761 void TRACE_link_variable_sub_with_time (double time, const char *link, const char *variable, double value)
763 instr_user_variable(time, link, variable, "LINK", value, INSTR_US_SUB, nullptr, &user_link_variables);
766 /* for link variables, but with src and dst used for get_route */
767 /** \ingroup TRACE_user_variables
768 * \brief Set the value of the variable present in the links connecting source and destination.
770 * Same as #TRACE_link_variable_set, but instead of providing the name of link to be considered, provide the source
771 * and destination hosts. All links that are part of the route between source and destination will have the variable
772 * set to the provided value.
774 * \param src The name of the source host for get route.
775 * \param dst The name of the destination host for get route.
776 * \param variable The name of the variable to be considered.
777 * \param value The new value of the variable.
779 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add, TRACE_link_srcdst_variable_sub
781 void TRACE_link_srcdst_variable_set (const char *src, const char *dst, const char *variable, double value)
783 TRACE_link_srcdst_variable_set_with_time (MSG_get_clock(), src, dst, variable, value);
786 /** \ingroup TRACE_user_variables
787 * \brief Add a value to the variable present in the links connecting source and destination.
789 * Same as #TRACE_link_variable_add, but instead of providing the name of link to be considered, provide the source
790 * and destination hosts. All links that are part of the route between source and destination will have the value
791 * passed as parameter added to the current value of the variable name to be considered.
793 * \param src The name of the source host for get route.
794 * \param dst The name of the destination host for get route.
795 * \param variable The name of the variable to be considered.
796 * \param value The value to be added to the variable.
798 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_sub
800 void TRACE_link_srcdst_variable_add (const char *src, const char *dst, const char *variable, double value)
802 TRACE_link_srcdst_variable_add_with_time (MSG_get_clock(), src, dst, variable, value);
805 /** \ingroup TRACE_user_variables
806 * \brief Subtract a value from the variable present in the links connecting source and destination.
808 * Same as #TRACE_link_variable_sub, but instead of providing the name of link to be considered, provide the source
809 * and destination hosts. All links that are part of the route between source and destination will have the value
810 * passed as parameter subtracted from the current value of the variable name to be considered.
812 * \param src The name of the source host for get route.
813 * \param dst The name of the destination host for get route.
814 * \param variable The name of the variable to be considered.
815 * \param value The value to be subtracted from the variable.
817 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_add
819 void TRACE_link_srcdst_variable_sub (const char *src, const char *dst, const char *variable, double value)
821 TRACE_link_srcdst_variable_sub_with_time (MSG_get_clock(), src, dst, variable, value);
824 /** \ingroup TRACE_user_variables
825 * \brief Set the value of the variable present in the links connecting source and destination at a given timestamp.
827 * Same as #TRACE_link_srcdst_variable_set, but let user specify the time used to trace it. Users can specify a time
828 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
829 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
832 * \param time The timestamp to be used to tag this change of value.
833 * \param src The name of the source host for get route.
834 * \param dst The name of the destination host for get route.
835 * \param variable The name of the variable to be considered.
836 * \param value The new value of the variable.
838 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add_with_time, TRACE_link_srcdst_variable_sub_with_time
840 void TRACE_link_srcdst_variable_set_with_time (double time, const char *src, const char *dst, const char *variable,
843 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SET);
846 /** \ingroup TRACE_user_variables
847 * \brief Add a value to the variable present in the links connecting source and destination at a given timestamp.
849 * Same as #TRACE_link_srcdst_variable_add, but let user specify the time used to trace it. Users can specify a time
850 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
851 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
854 * \param time The timestamp to be used to tag this change of value.
855 * \param src The name of the source host for get route.
856 * \param dst The name of the destination host for get route.
857 * \param variable The name of the variable to be considered.
858 * \param value The value to be added to the variable.
860 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_sub_with_time
862 void TRACE_link_srcdst_variable_add_with_time (double time, const char *src, const char *dst, const char *variable,
865 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_ADD);
868 /** \ingroup TRACE_user_variables
869 * \brief Subtract a value from the variable present in the links connecting source and dest. at a given timestamp.
871 * Same as #TRACE_link_srcdst_variable_sub, but let user specify the time used to trace it. Users can specify a time
872 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
873 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
876 * \param time The timestamp to be used to tag this change of value.
877 * \param src The name of the source host for get route.
878 * \param dst The name of the destination host for get route.
879 * \param variable The name of the variable to be considered.
880 * \param value The value to be subtracted from the variable.
882 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_add_with_time
884 void TRACE_link_srcdst_variable_sub_with_time (double time, const char *src, const char *dst, const char *variable,
887 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SUB);
890 /** \ingroup TRACE_user_variables
891 * \brief Get declared user link variables
893 * This function should be used to get link variables that were already declared with #TRACE_link_variable_declare or
894 * with #TRACE_link_variable_declare_with_color.
896 * \return A dynar with the declared link variables, must be freed with xbt_dynar_free.
898 xbt_dynar_t TRACE_get_link_variables ()
900 return instr_set_to_dynar(&user_link_variables);
903 /** \ingroup TRACE_user_variables
904 * \brief Declare a new user state associated to hosts.
906 * Declare a user state that will be associated to hosts.
907 * A user host state can be used to trace application states.
909 * \param state The name of the new state to be declared.
911 * \see TRACE_host_state_declare_value
913 void TRACE_host_state_declare (const char *state)
915 instr_new_user_state_type("HOST", state);
918 /** \ingroup TRACE_user_variables
919 * \brief Declare a new value for a user state associated to hosts.
921 * Declare a value for a state. The color needs to be a string with 3 numbers separated by spaces in the range [0,1].
922 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
924 * \param state The name of the new state to be declared.
925 * \param value The name of the value
926 * \param color The color of the value
928 * \see TRACE_host_state_declare
930 void TRACE_host_state_declare_value (const char *state, const char *value, const char *color)
932 instr_new_value_for_user_state_type (state, value, color);
935 /** \ingroup TRACE_user_variables
936 * \brief Set the user state to the given value.
938 * Change a user state previously declared to the given value.
940 * \param host The name of the host to be considered.
941 * \param state The name of the state previously declared.
942 * \param value The new value of the state.
944 * \see TRACE_host_state_declare, TRACE_host_push_state, TRACE_host_pop_state, TRACE_host_reset_state
946 void TRACE_host_set_state(const char* host, const char* state, const char* value_str)
948 container_t container = PJ_container_get(host);
949 simgrid::instr::Type* type = container->type_->getChild(state);
950 simgrid::instr::Value* val = simgrid::instr::Value::get_or_new(
951 value_str, nullptr, type); /* if user didn't declare a value with a color, use nullptr color */
952 new simgrid::instr::SetStateEvent(MSG_get_clock(), container, type, val);
955 /** \ingroup TRACE_user_variables
956 * \brief Push a new value for a state of a given host.
958 * Change a user state previously declared by pushing the new value to the state.
960 * \param host The name of the host to be considered.
961 * \param state The name of the state previously declared.
962 * \param value The value to be pushed.
964 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_pop_state, TRACE_host_reset_state
966 void TRACE_host_push_state(const char* host, const char* state, const char* value_str)
968 container_t container = PJ_container_get(host);
969 simgrid::instr::Type* type = container->type_->getChild(state);
970 simgrid::instr::Value* val = simgrid::instr::Value::get_or_new(
971 value_str, nullptr, type); /* if user didn't declare a value with a color, use nullptr color */
972 new simgrid::instr::PushStateEvent(MSG_get_clock(), container, type, val);
975 /** \ingroup TRACE_user_variables
976 * \brief Pop the last value of a state of a given host.
978 * Change a user state previously declared by removing the last value of the state.
980 * \param host The name of the host to be considered.
981 * \param state The name of the state to be popped.
983 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_reset_state
985 void TRACE_host_pop_state (const char *host, const char *state)
987 container_t container = PJ_container_get(host);
988 simgrid::instr::Type* type = container->type_->getChild(state);
989 new simgrid::instr::PopStateEvent(MSG_get_clock(), container, type);
992 /** \ingroup TRACE_API
993 * \brief Get Paje container types that can be mapped to the nodes of a graph.
995 * This function can be used to create a user made graph configuration file for Triva. Normally, it is used with the
996 * functions defined in \ref TRACE_user_variables.
998 * \return A dynar with the types, must be freed with xbt_dynar_free.
1000 xbt_dynar_t TRACE_get_node_types ()
1002 return instr_set_to_dynar(&trivaNodeTypes);
1005 /** \ingroup TRACE_API
1006 * \brief Get Paje container types that can be mapped to the edges of a graph.
1008 * This function can be used to create a user made graph configuration file for Triva. Normally, it is used with the
1009 * functions defined in \ref TRACE_user_variables.
1011 * \return A dynar with the types, must be freed with xbt_dynar_free.
1013 xbt_dynar_t TRACE_get_edge_types ()
1015 return instr_set_to_dynar(&trivaEdgeTypes);