1 /* Copyright (c) 2010-2021. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "simgrid/Exception.hpp"
7 #include "simgrid/kernel/routing/NetPoint.hpp"
8 #include "src/instr/instr_private.hpp"
9 #include "src/surf/network_interface.hpp"
10 #include "src/surf/surf_private.hpp"
11 #include "surf/surf.hpp"
12 #include "xbt/random.hpp"
16 enum class InstrUserVariable { DECLARE, SET, ADD, SUB };
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API");
20 std::set<std::string, std::less<>> created_categories;
21 std::set<std::string, std::less<>> declared_marks;
22 std::set<std::string, std::less<>> user_host_variables;
23 std::set<std::string, std::less<>> user_vm_variables;
24 std::set<std::string, std::less<>> user_link_variables;
26 static xbt_dynar_t instr_set_to_dynar(const std::set<std::string, std::less<>>& filter)
28 if (not TRACE_is_enabled() || not TRACE_needs_platform())
31 xbt_dynar_t ret = xbt_dynar_new (sizeof(char*), &xbt_free_ref);
32 for (auto const& name : filter)
33 xbt_dynar_push_as(ret, char*, xbt_strdup(name.c_str()));
38 /** @ingroup TRACE_category
39 * @brief Declare a new category with a random color.
41 * This function should be used to define a user category. The category can be used to differentiate the tasks that
42 * are created during the simulation (for example, tasks from server1, server2, or request tasks, computation tasks,
43 * communication tasks). All resource utilization (host power and link bandwidth) will be classified according to the
44 * task category. Tasks that do not belong to a category are not traced. The color for the category that is being
45 * declared is random. This function has no effect if a category with the same name has been already declared.
47 * See @ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
49 * @param category The name of the new tracing category to be created.
51 * @see TRACE_category_with_color, MSG_task_set_category, SD_task_set_category
53 void TRACE_category(const char *category)
55 TRACE_category_with_color (category, nullptr);
58 /** @ingroup TRACE_category
59 * @brief Declare a new category with a color.
61 * Same as #TRACE_category, but let user specify a color encoded as an RGB-like string with three floats from 0 to 1.
62 * 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"
63 * as color. This function has no effect if a category with the same name has been already declared.
65 * See @ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
67 * @param category The name of the new tracing category to be created.
68 * @param color The color of the category (see @ref outcomes_vizu to
69 * know how to correctly specify the color)
71 * @see MSG_task_set_category, SD_task_set_category
73 void TRACE_category_with_color (const char *category, const char *color)
75 /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with categories */
76 if (not TRACE_is_enabled() || not TRACE_needs_platform())
79 if (not(TRACE_categorized() && category != nullptr))
82 //check if category is already created
83 if (created_categories.find(category) != created_categories.end())
86 created_categories.emplace(category);
89 std::string final_color;
91 //generate a random color
92 double red = simgrid::xbt::random::uniform_real(0.0, std::nextafter(1.0, 2.0));
93 double green = simgrid::xbt::random::uniform_real(0.0, std::nextafter(1.0, 2.0));
94 double blue = simgrid::xbt::random::uniform_real(0.0, std::nextafter(1.0, 2.0));
95 final_color = std::to_string(red) + " " + std::to_string(green) + " " + std::to_string(blue);
97 final_color = std::string(color);
100 XBT_DEBUG("CAT,declare %s, \"%s\" \"%s\"", category, color, final_color.c_str());
102 //define the type of this category on top of hosts and links
103 instr_new_variable_type (category, final_color);
106 /** @ingroup TRACE_category
107 * @brief Get declared categories
109 * This function should be used to get categories that were already declared with #TRACE_category or with
110 * #TRACE_category_with_color.
112 * See @ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
114 * @return A dynar with the declared categories, must be freed with xbt_dynar_free.
116 * @see MSG_task_set_category, SD_task_set_category
118 xbt_dynar_t TRACE_get_categories ()
120 if (not TRACE_is_enabled() || not TRACE_categorized())
122 return instr_set_to_dynar(created_categories);
125 /** @ingroup TRACE_mark
126 * @brief Declare a new type for tracing mark.
128 * This function declares a new Paje event type in the trace file that can be used by simulators to declare
129 * application-level marks. This function is independent of which API is used in SimGrid.
131 * @param mark_type The name of the new type.
135 void TRACE_declare_mark(const char *mark_type)
137 /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
138 if (not TRACE_is_enabled() || not TRACE_needs_platform())
141 xbt_assert(mark_type, "mark_type is nullptr");
143 //check if mark_type is already declared
144 if (declared_marks.find(mark_type) != declared_marks.end()) {
145 throw simgrid::TracingError(XBT_THROW_POINT,
146 simgrid::xbt::string_printf("mark_type with name (%s) is already declared", mark_type));
149 XBT_DEBUG("MARK,declare %s", mark_type);
150 simgrid::instr::Container::get_root()->type_->by_name_or_create<simgrid::instr::EventType>(mark_type);
151 declared_marks.emplace(mark_type);
154 /** @ingroup TRACE_mark
155 * @brief Declare a new colored value for a previously declared mark type.
157 * This function declares a new colored value for a Paje event type in the trace file that can be used by simulators to
158 * declare application-level marks. This function is independent of which API is used in SimGrid. The color needs to be
159 * a string with three numbers separated by spaces in the range [0,1].
160 * 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
161 * be white ("1 1 1").
163 * @param mark_type The name of the new type.
164 * @param mark_value The name of the new value for this type.
165 * @param mark_color The color of the new value for this type.
169 void TRACE_declare_mark_value_with_color (const char *mark_type, const char *mark_value, const char *mark_color)
171 /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
172 if (not TRACE_is_enabled() || not TRACE_needs_platform())
175 xbt_assert(mark_type, "mark_type is nullptr");
176 xbt_assert(mark_value, "mark_value is nullptr");
179 static_cast<simgrid::instr::EventType*>(simgrid::instr::Container::get_root()->type_->by_name(mark_type));
181 throw simgrid::TracingError(XBT_THROW_POINT,
182 simgrid::xbt::string_printf("mark_type with name (%s) is not declared", mark_type));
185 mark_color = "1.0 1.0 1.0" /*white*/;
187 XBT_DEBUG("MARK,declare_value %s %s %s", mark_type, mark_value, mark_color);
188 type->add_entity_value(mark_value, mark_color);
192 /** @ingroup TRACE_mark
193 * @brief Declare a new value for a previously declared mark type.
195 * This function declares a new value for a Paje event type in the trace file that can be used by simulators to declare
196 * application-level marks. This function is independent of which API is used in SimGrid. Calling this function is the
197 * same as calling @ref TRACE_declare_mark_value_with_color with a nullptr color.
199 * @param mark_type The name of the new type.
200 * @param mark_value The name of the new value for this type.
204 void TRACE_declare_mark_value (const char *mark_type, const char *mark_value)
206 TRACE_declare_mark_value_with_color (mark_type, mark_value, nullptr);
210 * @ingroup TRACE_mark
211 * @brief Create a new instance of a tracing mark type.
213 * This function creates a mark in the trace file. The first parameter had to be previously declared using
214 * #TRACE_declare_mark, the second is the identifier for this mark instance. We recommend that the mark_value is a
215 * unique value for the whole simulation. Nevertheless, this is not a strong requirement: the trace will be valid even
216 * if there are multiple mark identifiers for the same trace.
218 * @param mark_type The name of the type for which the new instance will belong.
219 * @param mark_value The name of the new instance mark.
221 * @see TRACE_declare_mark
223 void TRACE_mark(const char *mark_type, const char *mark_value)
225 /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
226 if (not TRACE_is_enabled() || not TRACE_needs_platform())
229 xbt_assert(mark_type, "mark_type is nullptr");
230 xbt_assert(mark_value, "mark_value is nullptr");
232 //check if mark_type is already declared
234 static_cast<simgrid::instr::EventType*>(simgrid::instr::Container::get_root()->type_->by_name(mark_type));
236 throw simgrid::TracingError(XBT_THROW_POINT,
237 simgrid::xbt::string_printf("mark_type with name (%s) is not declared", mark_type));
239 XBT_DEBUG("MARK %s %s", mark_type, mark_value);
240 new simgrid::instr::NewEvent(simgrid_get_clock(), simgrid::instr::Container::get_root(), type,
241 type->get_entity_value(mark_value));
245 /** @ingroup TRACE_mark
246 * @brief Get declared marks
248 * This function should be used to get marks that were already declared with #TRACE_declare_mark.
250 * @return A dynar with the declared marks, must be freed with xbt_dynar_free.
252 xbt_dynar_t TRACE_get_marks ()
254 if (not TRACE_is_enabled())
257 return instr_set_to_dynar(declared_marks);
260 static void instr_user_variable(double time, const char* resource, const char* variable_name, const char* parent_type,
261 double value, InstrUserVariable what, const char* color,
262 std::set<std::string, std::less<>>* filter)
264 /* safe switches. tracing has to be activated and if platform is not traced, we don't allow user variables */
265 if (not TRACE_is_enabled() || not TRACE_needs_platform())
268 //check if variable is already declared
269 auto created = filter->find(variable_name);
270 if (what == InstrUserVariable::DECLARE) {
271 if (created == filter->end()) { // not declared yet
272 filter->insert(variable_name);
273 instr_new_user_variable_type(parent_type, variable_name, color == nullptr ? "" : color);
276 if (created != filter->end()) { // declared, let's work
277 simgrid::instr::VariableType* variable =
278 simgrid::instr::Container::by_name(resource)->get_variable(variable_name);
280 case InstrUserVariable::SET:
281 variable->set_event(time, value);
283 case InstrUserVariable::ADD:
284 variable->add_event(time, value);
286 case InstrUserVariable::SUB:
287 variable->sub_event(time, value);
296 static void instr_user_srcdst_variable(double time, const char* src, const char* dst, const char* variable,
297 const char* parent_type, double value, InstrUserVariable what)
299 const simgrid::kernel::routing::NetPoint* src_elm = sg_netpoint_by_name_or_null(src);
300 xbt_assert(src_elm, "Element '%s' not found!", src);
302 const simgrid::kernel::routing::NetPoint* dst_elm = sg_netpoint_by_name_or_null(dst);
303 xbt_assert(dst_elm, "Element '%s' not found!", dst);
305 std::vector<simgrid::kernel::resource::LinkImpl*> route;
306 simgrid::kernel::routing::NetZoneImpl::get_global_route(src_elm, dst_elm, route, nullptr);
307 for (auto const& link : route)
308 instr_user_variable(time, link->get_cname(), variable, parent_type, value, what, nullptr, &user_link_variables);
311 /** @ingroup TRACE_API
312 * @brief Creates a file with the topology of the platform file used for the simulator.
314 * The graph topology will have the following properties: all hosts, links and routers of the platform file are mapped
315 * to graph nodes; routes are mapped to edges.
316 * The platform's zones are not represented in the output.
318 * @param filename The name of the file that will hold the graph.
320 * @return 1 of successful, 0 otherwise.
322 int TRACE_platform_graph_export_graphviz (const char *filename)
324 simgrid::instr::platform_graph_export_graphviz(filename);
329 * Derived functions that use instr_user_variable and TRACE_user_srcdst_variable. They were previously defined as
330 * pre-processors directives, but were transformed into functions so the user can track them using gdb.
333 /* for VM variables */
334 /** @ingroup TRACE_user_variables
335 * @brief Declare a new user variable associated to VMs.
337 * Declare a user variable that will be associated to VMs. A user vm variable can be used to trace user variables
338 * such as the number of tasks in a VM, the number of clients in an application (for VMs), and so on. The color
339 * associated to this new variable will be random.
341 * @param variable The name of the new variable to be declared.
343 * @see TRACE_vm_variable_declare_with_color
345 void TRACE_vm_variable_declare (const char *variable)
347 instr_user_variable(0, nullptr, variable, "VM", 0, InstrUserVariable::DECLARE, nullptr, &user_vm_variables);
350 /** @ingroup TRACE_user_variables
351 * @brief Declare a new user variable associated to VMs with a color.
353 * Same as #TRACE_vm_variable_declare, but associated a color to the newly created user host variable. The color needs
354 * to be a string with three numbers separated by spaces in the range [0,1].
355 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
357 * @param variable The name of the new variable to be declared.
358 * @param color The color for the new variable.
360 void TRACE_vm_variable_declare_with_color (const char *variable, const char *color)
362 instr_user_variable(0, nullptr, variable, "VM", 0, InstrUserVariable::DECLARE, color, &user_vm_variables);
365 /** @ingroup TRACE_user_variables
366 * @brief Set the value of a variable of a host.
368 * @param vm The name of the VM to be considered.
369 * @param variable The name of the variable to be considered.
370 * @param value The new value of the variable.
372 * @see TRACE_vm_variable_declare, TRACE_vm_variable_add, TRACE_vm_variable_sub
374 void TRACE_vm_variable_set (const char *vm, const char *variable, double value)
376 TRACE_vm_variable_set_with_time(simgrid_get_clock(), vm, variable, value);
379 /** @ingroup TRACE_user_variables
380 * @brief Add a value to a variable of a VM.
382 * @param vm The name of the VM to be considered.
383 * @param variable The name of the variable to be considered.
384 * @param value The value to be added to the variable.
386 * @see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_sub
388 void TRACE_vm_variable_add (const char *vm, const char *variable, double value)
390 TRACE_vm_variable_add_with_time(simgrid_get_clock(), vm, variable, value);
393 /** @ingroup TRACE_user_variables
394 * @brief Subtract a value from a variable of a VM.
396 * @param vm The name of the vm to be considered.
397 * @param variable The name of the variable to be considered.
398 * @param value The value to be subtracted from the variable.
400 * @see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_add
402 void TRACE_vm_variable_sub (const char *vm, const char *variable, double value)
404 TRACE_vm_variable_sub_with_time(simgrid_get_clock(), vm, variable, value);
407 /** @ingroup TRACE_user_variables
408 * @brief Set the value of a variable of a VM at a given timestamp.
410 * Same as #TRACE_vm_variable_set, but let user specify the time used to trace it. Users can specify a time that
411 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
412 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
415 * @param time The timestamp to be used to tag this change of value.
416 * @param vm The name of the VM to be considered.
417 * @param variable The name of the variable to be considered.
418 * @param value The new value of the variable.
420 * @see TRACE_vm_variable_declare, TRACE_vm_variable_add_with_time, TRACE_vm_variable_sub_with_time
422 void TRACE_vm_variable_set_with_time (double time, const char *vm, const char *variable, double value)
424 instr_user_variable(time, vm, variable, "VM", value, InstrUserVariable::SET, nullptr, &user_vm_variables);
427 /** @ingroup TRACE_user_variables
428 * @brief Add a value to a variable of a VM at a given timestamp.
430 * Same as #TRACE_vm_variable_add, but let user specify the time used to trace it. Users can specify a time that
431 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
432 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
435 * @param time The timestamp to be used to tag this change of value.
436 * @param vm The name of the VM to be considered.
437 * @param variable The name of the variable to be considered.
438 * @param value The value to be added to the variable.
440 * @see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_sub_with_time
442 void TRACE_vm_variable_add_with_time (double time, const char *vm, const char *variable, double value)
444 instr_user_variable(time, vm, variable, "VM", value, InstrUserVariable::ADD, nullptr, &user_vm_variables);
447 /** @ingroup TRACE_user_variables
448 * @brief Subtract a value from a variable of a VM at a given timestamp.
450 * Same as #TRACE_vm_variable_sub, but let user specify the time used to trace it. Users can specify a time that
451 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
452 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
455 * @param time The timestamp to be used to tag this change of value.
456 * @param vm The name of the VM to be considered.
457 * @param variable The name of the variable to be considered.
458 * @param value The value to be subtracted from the variable.
460 * @see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_add_with_time
462 void TRACE_vm_variable_sub_with_time (double time, const char *vm, const char *variable, double value)
464 instr_user_variable(time, vm, variable, "VM", value, InstrUserVariable::SUB, nullptr, &user_vm_variables);
467 /* for host variables */
468 /** @ingroup TRACE_user_variables
469 * @brief Declare a new user variable associated to hosts.
471 * Declare a user variable that will be associated to hosts.
472 * A user host variable can be used to trace user variables such as the number of tasks in a server, the number of
473 * clients in an application (for hosts), and so on. The color associated to this new variable will be random.
475 * @param variable The name of the new variable to be declared.
477 * @see TRACE_host_variable_declare_with_color
479 void TRACE_host_variable_declare (const char *variable)
481 instr_user_variable(0, nullptr, variable, "HOST", 0, InstrUserVariable::DECLARE, nullptr, &user_host_variables);
484 /** @ingroup TRACE_user_variables
485 * @brief Declare a new user variable associated to hosts with a color.
487 * Same as #TRACE_host_variable_declare, but associated a color to the newly created user host variable. The color
488 * needs to be a string with three numbers separated by spaces in the range [0,1].
489 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
491 * @param variable The name of the new variable to be declared.
492 * @param color The color for the new variable.
494 void TRACE_host_variable_declare_with_color (const char *variable, const char *color)
496 instr_user_variable(0, nullptr, variable, "HOST", 0, InstrUserVariable::DECLARE, color, &user_host_variables);
499 /** @ingroup TRACE_user_variables
500 * @brief Set the value of a variable of a host.
502 * @param host The name of the host to be considered.
503 * @param variable The name of the variable to be considered.
504 * @param value The new value of the variable.
506 * @see TRACE_host_variable_declare, TRACE_host_variable_add, TRACE_host_variable_sub
508 void TRACE_host_variable_set (const char *host, const char *variable, double value)
510 TRACE_host_variable_set_with_time(simgrid_get_clock(), host, variable, value);
513 /** @ingroup TRACE_user_variables
514 * @brief Add a value to a variable of a host.
516 * @param host The name of the host to be considered.
517 * @param variable The name of the variable to be considered.
518 * @param value The value to be added to the variable.
520 * @see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_sub
522 void TRACE_host_variable_add (const char *host, const char *variable, double value)
524 TRACE_host_variable_add_with_time(simgrid_get_clock(), host, variable, value);
527 /** @ingroup TRACE_user_variables
528 * @brief Subtract a value from a variable of a host.
530 * @param host The name of the host to be considered.
531 * @param variable The name of the variable to be considered.
532 * @param value The value to be subtracted from the variable.
534 * @see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_add
536 void TRACE_host_variable_sub (const char *host, const char *variable, double value)
538 TRACE_host_variable_sub_with_time(simgrid_get_clock(), host, variable, value);
541 /** @ingroup TRACE_user_variables
542 * @brief Set the value of a variable of a host at a given timestamp.
544 * Same as #TRACE_host_variable_set, but let user specify the time used to trace it. Users can specify a time that
545 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
546 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
549 * @param time The timestamp to be used to tag this change of value.
550 * @param host The name of the host to be considered.
551 * @param variable The name of the variable to be considered.
552 * @param value The new value of the variable.
554 * @see TRACE_host_variable_declare, TRACE_host_variable_add_with_time, TRACE_host_variable_sub_with_time
556 void TRACE_host_variable_set_with_time (double time, const char *host, const char *variable, double value)
558 instr_user_variable(time, host, variable, "HOST", value, InstrUserVariable::SET, nullptr, &user_host_variables);
561 /** @ingroup TRACE_user_variables
562 * @brief Add a value to a variable of a host at a given timestamp.
564 * Same as #TRACE_host_variable_add, but let user specify the time used to trace it. Users can specify a time that
565 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
566 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
569 * @param time The timestamp to be used to tag this change of value.
570 * @param host The name of the host to be considered.
571 * @param variable The name of the variable to be considered.
572 * @param value The value to be added to the variable.
574 * @see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_sub_with_time
576 void TRACE_host_variable_add_with_time (double time, const char *host, const char *variable, double value)
578 instr_user_variable(time, host, variable, "HOST", value, InstrUserVariable::ADD, nullptr, &user_host_variables);
581 /** @ingroup TRACE_user_variables
582 * @brief Subtract a value from a variable of a host at a given timestamp.
584 * Same as #TRACE_host_variable_sub, but let user specify the time used to trace it. Users can specify a time that
585 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
586 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
589 * @param time The timestamp to be used to tag this change of value.
590 * @param host The name of the host to be considered.
591 * @param variable The name of the variable to be considered.
592 * @param value The value to be subtracted from the variable.
594 * @see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_add_with_time
596 void TRACE_host_variable_sub_with_time (double time, const char *host, const char *variable, double value)
598 instr_user_variable(time, host, variable, "HOST", value, InstrUserVariable::SUB, nullptr, &user_host_variables);
601 /** @ingroup TRACE_user_variables
602 * @brief Get declared user host variables
604 * This function should be used to get host variables that were already declared with #TRACE_host_variable_declare or
605 * with #TRACE_host_variable_declare_with_color.
607 * @return A dynar with the declared host variables, must be freed with xbt_dynar_free.
609 xbt_dynar_t TRACE_get_host_variables ()
611 return instr_set_to_dynar(user_host_variables);
614 /* for link variables */
615 /** @ingroup TRACE_user_variables
616 * @brief Declare a new user variable associated to links.
618 * Declare a user variable that will be associated to links.
619 * A user link variable can be used, for example, to trace user variables such as the number of messages being
620 * transferred through network links. The color associated to this new variable will be random.
622 * @param variable The name of the new variable to be declared.
624 * @see TRACE_link_variable_declare_with_color
626 void TRACE_link_variable_declare (const char *variable)
628 instr_user_variable(0, nullptr, variable, "LINK", 0, InstrUserVariable::DECLARE, nullptr, &user_link_variables);
631 /** @ingroup TRACE_user_variables
632 * @brief Declare a new user variable associated to links with a color.
634 * Same as #TRACE_link_variable_declare, but associated a color to the newly created user link variable. The color
635 * needs to be a string with three numbers separated by spaces in the range [0,1].
636 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
638 * @param variable The name of the new variable to be declared.
639 * @param color The color for the new variable.
641 void TRACE_link_variable_declare_with_color (const char *variable, const char *color)
643 instr_user_variable(0, nullptr, variable, "LINK", 0, InstrUserVariable::DECLARE, color, &user_link_variables);
646 /** @ingroup TRACE_user_variables
647 * @brief Set the value of a variable of a link.
649 * @param link The name of the link to be considered.
650 * @param variable The name of the variable to be considered.
651 * @param value The new value of the variable.
653 * @see TRACE_link_variable_declare, TRACE_link_variable_add, TRACE_link_variable_sub
655 void TRACE_link_variable_set (const char *link, const char *variable, double value)
657 TRACE_link_variable_set_with_time(simgrid_get_clock(), link, variable, value);
660 /** @ingroup TRACE_user_variables
661 * @brief Add a value to a variable of a link.
663 * @param link The name of the link to be considered.
664 * @param variable The name of the variable to be considered.
665 * @param value The value to be added to the variable.
667 * @see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_sub
669 void TRACE_link_variable_add (const char *link, const char *variable, double value)
671 TRACE_link_variable_add_with_time(simgrid_get_clock(), link, variable, value);
674 /** @ingroup TRACE_user_variables
675 * @brief Subtract a value from a variable of a link.
677 * @param link The name of the link to be considered.
678 * @param variable The name of the variable to be considered.
679 * @param value The value to be subtracted from the variable.
681 * @see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_add
683 void TRACE_link_variable_sub (const char *link, const char *variable, double value)
685 TRACE_link_variable_sub_with_time(simgrid_get_clock(), link, variable, value);
688 /** @ingroup TRACE_user_variables
689 * @brief Set the value of a variable of a link at a given timestamp.
691 * Same as #TRACE_link_variable_set, but let user specify the time used to trace it. Users can specify a time that
692 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
693 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
696 * @param time The timestamp to be used to tag this change of value.
697 * @param link The name of the link to be considered.
698 * @param variable The name of the variable to be considered.
699 * @param value The new value of the variable.
701 * @see TRACE_link_variable_declare, TRACE_link_variable_add_with_time, TRACE_link_variable_sub_with_time
703 void TRACE_link_variable_set_with_time (double time, const char *link, const char *variable, double value)
705 instr_user_variable(time, link, variable, "LINK", value, InstrUserVariable::SET, nullptr, &user_link_variables);
708 /** @ingroup TRACE_user_variables
709 * @brief Add a value to a variable of a link at a given timestamp.
711 * Same as #TRACE_link_variable_add, but let user specify the time used to trace it. Users can specify a time that
712 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
713 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
716 * @param time The timestamp to be used to tag this change of value.
717 * @param link The name of the link to be considered.
718 * @param variable The name of the variable to be considered.
719 * @param value The value to be added to the variable.
721 * @see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_sub_with_time
723 void TRACE_link_variable_add_with_time (double time, const char *link, const char *variable, double value)
725 instr_user_variable(time, link, variable, "LINK", value, InstrUserVariable::ADD, nullptr, &user_link_variables);
728 /** @ingroup TRACE_user_variables
729 * @brief Subtract a value from a variable of a link at a given timestamp.
731 * Same as #TRACE_link_variable_sub, but let user specify the time used to trace it. Users can specify a time that
732 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
733 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
736 * @param time The timestamp to be used to tag this change of value.
737 * @param link The name of the link to be considered.
738 * @param variable The name of the variable to be considered.
739 * @param value The value to be subtracted from the variable.
741 * @see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_add_with_time
743 void TRACE_link_variable_sub_with_time (double time, const char *link, const char *variable, double value)
745 instr_user_variable(time, link, variable, "LINK", value, InstrUserVariable::SUB, nullptr, &user_link_variables);
748 /* for link variables, but with src and dst used for get_route */
749 /** @ingroup TRACE_user_variables
750 * @brief Set the value of the variable present in the links connecting source and destination.
752 * Same as #TRACE_link_variable_set, but instead of providing the name of link to be considered, provide the source
753 * and destination hosts. All links that are part of the route between source and destination will have the variable
754 * set to the provided value.
756 * @param src The name of the source host for get route.
757 * @param dst The name of the destination host for get route.
758 * @param variable The name of the variable to be considered.
759 * @param value The new value of the variable.
761 * @see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add, TRACE_link_srcdst_variable_sub
763 void TRACE_link_srcdst_variable_set (const char *src, const char *dst, const char *variable, double value)
765 TRACE_link_srcdst_variable_set_with_time(simgrid_get_clock(), src, dst, variable, value);
768 /** @ingroup TRACE_user_variables
769 * @brief Add a value to the variable present in the links connecting source and destination.
771 * Same as #TRACE_link_variable_add, but instead of providing the name of link to be considered, provide the source
772 * and destination hosts. All links that are part of the route between source and destination will have the value
773 * passed as parameter added to the current value of the variable name to be considered.
775 * @param src The name of the source host for get route.
776 * @param dst The name of the destination host for get route.
777 * @param variable The name of the variable to be considered.
778 * @param value The value to be added to the variable.
780 * @see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_sub
782 void TRACE_link_srcdst_variable_add (const char *src, const char *dst, const char *variable, double value)
784 TRACE_link_srcdst_variable_add_with_time(simgrid_get_clock(), src, dst, variable, value);
787 /** @ingroup TRACE_user_variables
788 * @brief Subtract a value from the variable present in the links connecting source and destination.
790 * Same as #TRACE_link_variable_sub, but instead of providing the name of link to be considered, provide the source
791 * and destination hosts. All links that are part of the route between source and destination will have the value
792 * passed as parameter subtracted from the current value of the variable name to be considered.
794 * @param src The name of the source host for get route.
795 * @param dst The name of the destination host for get route.
796 * @param variable The name of the variable to be considered.
797 * @param value The value to be subtracted from the variable.
799 * @see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_add
801 void TRACE_link_srcdst_variable_sub (const char *src, const char *dst, const char *variable, double value)
803 TRACE_link_srcdst_variable_sub_with_time(simgrid_get_clock(), src, dst, variable, value);
806 /** @ingroup TRACE_user_variables
807 * @brief Set the value of the variable present in the links connecting source and destination at a given timestamp.
809 * Same as #TRACE_link_srcdst_variable_set, but let user specify the time used to trace it. Users can specify a time
810 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
811 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
814 * @param time The timestamp to be used to tag this change of value.
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 new value of the variable.
820 * @see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add_with_time, TRACE_link_srcdst_variable_sub_with_time
822 void TRACE_link_srcdst_variable_set_with_time (double time, const char *src, const char *dst, const char *variable,
825 instr_user_srcdst_variable(time, src, dst, variable, "LINK", value, InstrUserVariable::SET);
828 /** @ingroup TRACE_user_variables
829 * @brief Add a value to the variable present in the links connecting source and destination at a given timestamp.
831 * Same as #TRACE_link_srcdst_variable_add, but let user specify the time used to trace it. Users can specify a time
832 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
833 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
836 * @param time The timestamp to be used to tag this change of value.
837 * @param src The name of the source host for get route.
838 * @param dst The name of the destination host for get route.
839 * @param variable The name of the variable to be considered.
840 * @param value The value to be added to the variable.
842 * @see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_sub_with_time
844 void TRACE_link_srcdst_variable_add_with_time (double time, const char *src, const char *dst, const char *variable,
847 instr_user_srcdst_variable(time, src, dst, variable, "LINK", value, InstrUserVariable::ADD);
850 /** @ingroup TRACE_user_variables
851 * @brief Subtract a value from the variable present in the links connecting source and dest. at a given timestamp.
853 * Same as #TRACE_link_srcdst_variable_sub, but let user specify the time used to trace it. Users can specify a time
854 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
855 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
858 * @param time The timestamp to be used to tag this change of value.
859 * @param src The name of the source host for get route.
860 * @param dst The name of the destination host for get route.
861 * @param variable The name of the variable to be considered.
862 * @param value The value to be subtracted from the variable.
864 * @see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_add_with_time
866 void TRACE_link_srcdst_variable_sub_with_time (double time, const char *src, const char *dst, const char *variable,
869 instr_user_srcdst_variable(time, src, dst, variable, "LINK", value, InstrUserVariable::SUB);
872 /** @ingroup TRACE_user_variables
873 * @brief Get declared user link variables
875 * This function should be used to get link variables that were already declared with #TRACE_link_variable_declare or
876 * with #TRACE_link_variable_declare_with_color.
878 * @return A dynar with the declared link variables, must be freed with xbt_dynar_free.
880 xbt_dynar_t TRACE_get_link_variables ()
882 return instr_set_to_dynar(user_link_variables);
885 /** @ingroup TRACE_user_variables
886 * @brief Declare a new user state associated to hosts.
888 * Declare a user state that will be associated to hosts.
889 * A user host state can be used to trace application states.
891 * @param state The name of the new state to be declared.
893 * @see TRACE_host_state_declare_value
895 void TRACE_host_state_declare (const char *state)
897 instr_new_user_state_type("HOST", state);
900 /** @ingroup TRACE_user_variables
901 * @brief Declare a new value for a user state associated to hosts.
903 * Declare a value for a state. The color needs to be a string with 3 numbers separated by spaces in the range [0,1].
904 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
906 * @param state The name of the new state to be declared.
907 * @param value The name of the value
908 * @param color The color of the value
910 * @see TRACE_host_state_declare
912 void TRACE_host_state_declare_value (const char *state, const char *value, const char *color)
914 instr_new_value_for_user_state_type (state, value, color);
917 /** @ingroup TRACE_user_variables
918 * @brief Set the user state to the given value.
920 * Change a user state previously declared to the given value.
922 * @param host The name of the host to be considered.
923 * @param state_name The name of the state previously declared.
924 * @param value_name The new value of the state.
926 * @see TRACE_host_state_declare, TRACE_host_push_state, TRACE_host_pop_state, TRACE_host_reset_state
928 void TRACE_host_set_state(const char* host, const char* state_name, const char* value_name)
930 simgrid::instr::StateType* state = simgrid::instr::Container::by_name(host)->get_state(state_name);
931 state->add_entity_value(value_name);
932 state->set_event(value_name);
935 /** @ingroup TRACE_user_variables
936 * @brief Push a new value for a state of a given host.
938 * Change a user state previously declared by pushing the new value to the state.
940 * @param host The name of the host to be considered.
941 * @param state_name The name of the state previously declared.
942 * @param value_name The value to be pushed.
944 * @see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_pop_state, TRACE_host_reset_state
946 void TRACE_host_push_state(const char* host, const char* state_name, const char* value_name)
948 simgrid::instr::Container::by_name(host)->get_state(state_name)->push_event(value_name);
951 /** @ingroup TRACE_user_variables
952 * @brief Pop the last value of a state of a given host.
954 * Change a user state previously declared by removing the last value of the state.
956 * @param host The name of the host to be considered.
957 * @param state_name The name of the state to be popped.
959 * @see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_reset_state
961 void TRACE_host_pop_state(const char* host, const char* state_name)
963 simgrid::instr::Container::by_name(host)->get_state(state_name)->pop_event();