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");
178 simgrid::instr::EventType* type =
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
233 simgrid::instr::EventType* type =
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* father_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(father_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 *father_type, double value, InstrUserVariable what)
299 simgrid::kernel::routing::NetPoint* src_elm = sg_netpoint_by_name_or_null(src);
301 xbt_die("Element '%s' not found!",src);
303 simgrid::kernel::routing::NetPoint* dst_elm = sg_netpoint_by_name_or_null(dst);
305 xbt_die("Element '%s' not found!",dst);
307 std::vector<simgrid::kernel::resource::LinkImpl*> route;
308 simgrid::kernel::routing::NetZoneImpl::get_global_route(src_elm, dst_elm, route, nullptr);
309 for (auto const& link : route)
310 instr_user_variable(time, link->get_cname(), variable, father_type, value, what, nullptr, &user_link_variables);
313 /** @ingroup TRACE_API
314 * @brief Creates a file with the topology of the platform file used for the simulator.
316 * The graph topology will have the following properties: all hosts, links and routers of the platform file are mapped
317 * to graph nodes; routes are mapped to edges.
318 * The platform's zones are not represented in the output.
320 * @param filename The name of the file that will hold the graph.
322 * @return 1 of successful, 0 otherwise.
324 int TRACE_platform_graph_export_graphviz (const char *filename)
326 simgrid::instr::platform_graph_export_graphviz(filename);
331 * Derived functions that use instr_user_variable and TRACE_user_srcdst_variable. They were previously defined as
332 * pre-processors directives, but were transformed into functions so the user can track them using gdb.
335 /* for VM variables */
336 /** @ingroup TRACE_user_variables
337 * @brief Declare a new user variable associated to VMs.
339 * Declare a user variable that will be associated to VMs. A user vm variable can be used to trace user variables
340 * such as the number of tasks in a VM, the number of clients in an application (for VMs), and so on. The color
341 * associated to this new variable will be random.
343 * @param variable The name of the new variable to be declared.
345 * @see TRACE_vm_variable_declare_with_color
347 void TRACE_vm_variable_declare (const char *variable)
349 instr_user_variable(0, nullptr, variable, "VM", 0, InstrUserVariable::DECLARE, nullptr, &user_vm_variables);
352 /** @ingroup TRACE_user_variables
353 * @brief Declare a new user variable associated to VMs with a color.
355 * Same as #TRACE_vm_variable_declare, but associated a color to the newly created user host variable. The color needs
356 * to be a string with three numbers separated by spaces in the range [0,1].
357 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
359 * @param variable The name of the new variable to be declared.
360 * @param color The color for the new variable.
362 void TRACE_vm_variable_declare_with_color (const char *variable, const char *color)
364 instr_user_variable(0, nullptr, variable, "VM", 0, InstrUserVariable::DECLARE, color, &user_vm_variables);
367 /** @ingroup TRACE_user_variables
368 * @brief Set the value of a variable of a host.
370 * @param vm The name of the VM to be considered.
371 * @param variable The name of the variable to be considered.
372 * @param value The new value of the variable.
374 * @see TRACE_vm_variable_declare, TRACE_vm_variable_add, TRACE_vm_variable_sub
376 void TRACE_vm_variable_set (const char *vm, const char *variable, double value)
378 TRACE_vm_variable_set_with_time(simgrid_get_clock(), vm, variable, value);
381 /** @ingroup TRACE_user_variables
382 * @brief Add a value to a variable of a VM.
384 * @param vm The name of the VM to be considered.
385 * @param variable The name of the variable to be considered.
386 * @param value The value to be added to the variable.
388 * @see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_sub
390 void TRACE_vm_variable_add (const char *vm, const char *variable, double value)
392 TRACE_vm_variable_add_with_time(simgrid_get_clock(), vm, variable, value);
395 /** @ingroup TRACE_user_variables
396 * @brief Subtract a value from a variable of a VM.
398 * @param vm The name of the vm to be considered.
399 * @param variable The name of the variable to be considered.
400 * @param value The value to be subtracted from the variable.
402 * @see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_add
404 void TRACE_vm_variable_sub (const char *vm, const char *variable, double value)
406 TRACE_vm_variable_sub_with_time(simgrid_get_clock(), vm, variable, value);
409 /** @ingroup TRACE_user_variables
410 * @brief Set the value of a variable of a VM at a given timestamp.
412 * Same as #TRACE_vm_variable_set, but let user specify the time used to trace it. Users can specify a time that
413 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
414 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
417 * @param time The timestamp to be used to tag this change of value.
418 * @param vm The name of the VM to be considered.
419 * @param variable The name of the variable to be considered.
420 * @param value The new value of the variable.
422 * @see TRACE_vm_variable_declare, TRACE_vm_variable_add_with_time, TRACE_vm_variable_sub_with_time
424 void TRACE_vm_variable_set_with_time (double time, const char *vm, const char *variable, double value)
426 instr_user_variable(time, vm, variable, "VM", value, InstrUserVariable::SET, nullptr, &user_vm_variables);
429 /** @ingroup TRACE_user_variables
430 * @brief Add a value to a variable of a VM at a given timestamp.
432 * Same as #TRACE_vm_variable_add, but let user specify the time used to trace it. Users can specify a time that
433 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
434 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
437 * @param time The timestamp to be used to tag this change of value.
438 * @param vm The name of the VM to be considered.
439 * @param variable The name of the variable to be considered.
440 * @param value The value to be added to the variable.
442 * @see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_sub_with_time
444 void TRACE_vm_variable_add_with_time (double time, const char *vm, const char *variable, double value)
446 instr_user_variable(time, vm, variable, "VM", value, InstrUserVariable::ADD, nullptr, &user_vm_variables);
449 /** @ingroup TRACE_user_variables
450 * @brief Subtract a value from a variable of a VM at a given timestamp.
452 * Same as #TRACE_vm_variable_sub, but let user specify the time used to trace it. Users can specify a time that
453 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
454 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
457 * @param time The timestamp to be used to tag this change of value.
458 * @param vm The name of the VM to be considered.
459 * @param variable The name of the variable to be considered.
460 * @param value The value to be subtracted from the variable.
462 * @see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_add_with_time
464 void TRACE_vm_variable_sub_with_time (double time, const char *vm, const char *variable, double value)
466 instr_user_variable(time, vm, variable, "VM", value, InstrUserVariable::SUB, nullptr, &user_vm_variables);
469 /* for host variables */
470 /** @ingroup TRACE_user_variables
471 * @brief Declare a new user variable associated to hosts.
473 * Declare a user variable that will be associated to hosts.
474 * A user host variable can be used to trace user variables such as the number of tasks in a server, the number of
475 * clients in an application (for hosts), and so on. The color associated to this new variable will be random.
477 * @param variable The name of the new variable to be declared.
479 * @see TRACE_host_variable_declare_with_color
481 void TRACE_host_variable_declare (const char *variable)
483 instr_user_variable(0, nullptr, variable, "HOST", 0, InstrUserVariable::DECLARE, nullptr, &user_host_variables);
486 /** @ingroup TRACE_user_variables
487 * @brief Declare a new user variable associated to hosts with a color.
489 * Same as #TRACE_host_variable_declare, but associated a color to the newly created user host variable. The color
490 * needs to be a string with three numbers separated by spaces in the range [0,1].
491 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
493 * @param variable The name of the new variable to be declared.
494 * @param color The color for the new variable.
496 void TRACE_host_variable_declare_with_color (const char *variable, const char *color)
498 instr_user_variable(0, nullptr, variable, "HOST", 0, InstrUserVariable::DECLARE, color, &user_host_variables);
501 /** @ingroup TRACE_user_variables
502 * @brief Set the value of a variable of a host.
504 * @param host The name of the host to be considered.
505 * @param variable The name of the variable to be considered.
506 * @param value The new value of the variable.
508 * @see TRACE_host_variable_declare, TRACE_host_variable_add, TRACE_host_variable_sub
510 void TRACE_host_variable_set (const char *host, const char *variable, double value)
512 TRACE_host_variable_set_with_time(simgrid_get_clock(), host, variable, value);
515 /** @ingroup TRACE_user_variables
516 * @brief Add a value to a variable of a host.
518 * @param host The name of the host to be considered.
519 * @param variable The name of the variable to be considered.
520 * @param value The value to be added to the variable.
522 * @see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_sub
524 void TRACE_host_variable_add (const char *host, const char *variable, double value)
526 TRACE_host_variable_add_with_time(simgrid_get_clock(), host, variable, value);
529 /** @ingroup TRACE_user_variables
530 * @brief Subtract a value from a variable of a host.
532 * @param host The name of the host to be considered.
533 * @param variable The name of the variable to be considered.
534 * @param value The value to be subtracted from the variable.
536 * @see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_add
538 void TRACE_host_variable_sub (const char *host, const char *variable, double value)
540 TRACE_host_variable_sub_with_time(simgrid_get_clock(), host, variable, value);
543 /** @ingroup TRACE_user_variables
544 * @brief Set the value of a variable of a host at a given timestamp.
546 * Same as #TRACE_host_variable_set, but let user specify the time used to trace it. Users can specify a time that
547 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
548 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
551 * @param time The timestamp to be used to tag this change of value.
552 * @param host The name of the host to be considered.
553 * @param variable The name of the variable to be considered.
554 * @param value The new value of the variable.
556 * @see TRACE_host_variable_declare, TRACE_host_variable_add_with_time, TRACE_host_variable_sub_with_time
558 void TRACE_host_variable_set_with_time (double time, const char *host, const char *variable, double value)
560 instr_user_variable(time, host, variable, "HOST", value, InstrUserVariable::SET, nullptr, &user_host_variables);
563 /** @ingroup TRACE_user_variables
564 * @brief Add a value to a variable of a host at a given timestamp.
566 * Same as #TRACE_host_variable_add, but let user specify the time used to trace it. Users can specify a time that
567 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
568 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
571 * @param time The timestamp to be used to tag this change of value.
572 * @param host The name of the host to be considered.
573 * @param variable The name of the variable to be considered.
574 * @param value The value to be added to the variable.
576 * @see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_sub_with_time
578 void TRACE_host_variable_add_with_time (double time, const char *host, const char *variable, double value)
580 instr_user_variable(time, host, variable, "HOST", value, InstrUserVariable::ADD, nullptr, &user_host_variables);
583 /** @ingroup TRACE_user_variables
584 * @brief Subtract a value from a variable of a host at a given timestamp.
586 * Same as #TRACE_host_variable_sub, but let user specify the time used to trace it. Users can specify a time that
587 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
588 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
591 * @param time The timestamp to be used to tag this change of value.
592 * @param host The name of the host to be considered.
593 * @param variable The name of the variable to be considered.
594 * @param value The value to be subtracted from the variable.
596 * @see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_add_with_time
598 void TRACE_host_variable_sub_with_time (double time, const char *host, const char *variable, double value)
600 instr_user_variable(time, host, variable, "HOST", value, InstrUserVariable::SUB, nullptr, &user_host_variables);
603 /** @ingroup TRACE_user_variables
604 * @brief Get declared user host variables
606 * This function should be used to get host variables that were already declared with #TRACE_host_variable_declare or
607 * with #TRACE_host_variable_declare_with_color.
609 * @return A dynar with the declared host variables, must be freed with xbt_dynar_free.
611 xbt_dynar_t TRACE_get_host_variables ()
613 return instr_set_to_dynar(user_host_variables);
616 /* for link variables */
617 /** @ingroup TRACE_user_variables
618 * @brief Declare a new user variable associated to links.
620 * Declare a user variable that will be associated to links.
621 * A user link variable can be used, for example, to trace user variables such as the number of messages being
622 * transferred through network links. The color associated to this new variable will be random.
624 * @param variable The name of the new variable to be declared.
626 * @see TRACE_link_variable_declare_with_color
628 void TRACE_link_variable_declare (const char *variable)
630 instr_user_variable(0, nullptr, variable, "LINK", 0, InstrUserVariable::DECLARE, nullptr, &user_link_variables);
633 /** @ingroup TRACE_user_variables
634 * @brief Declare a new user variable associated to links with a color.
636 * Same as #TRACE_link_variable_declare, but associated a color to the newly created user link variable. The color
637 * needs to be a string with three numbers separated by spaces in the range [0,1].
638 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
640 * @param variable The name of the new variable to be declared.
641 * @param color The color for the new variable.
643 void TRACE_link_variable_declare_with_color (const char *variable, const char *color)
645 instr_user_variable(0, nullptr, variable, "LINK", 0, InstrUserVariable::DECLARE, color, &user_link_variables);
648 /** @ingroup TRACE_user_variables
649 * @brief Set the value of a variable of a link.
651 * @param link The name of the link to be considered.
652 * @param variable The name of the variable to be considered.
653 * @param value The new value of the variable.
655 * @see TRACE_link_variable_declare, TRACE_link_variable_add, TRACE_link_variable_sub
657 void TRACE_link_variable_set (const char *link, const char *variable, double value)
659 TRACE_link_variable_set_with_time(simgrid_get_clock(), link, variable, value);
662 /** @ingroup TRACE_user_variables
663 * @brief Add a value to a variable of a link.
665 * @param link The name of the link to be considered.
666 * @param variable The name of the variable to be considered.
667 * @param value The value to be added to the variable.
669 * @see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_sub
671 void TRACE_link_variable_add (const char *link, const char *variable, double value)
673 TRACE_link_variable_add_with_time(simgrid_get_clock(), link, variable, value);
676 /** @ingroup TRACE_user_variables
677 * @brief Subtract a value from a variable of a link.
679 * @param link The name of the link to be considered.
680 * @param variable The name of the variable to be considered.
681 * @param value The value to be subtracted from the variable.
683 * @see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_add
685 void TRACE_link_variable_sub (const char *link, const char *variable, double value)
687 TRACE_link_variable_sub_with_time(simgrid_get_clock(), link, variable, value);
690 /** @ingroup TRACE_user_variables
691 * @brief Set the value of a variable of a link at a given timestamp.
693 * Same as #TRACE_link_variable_set, but let user specify the time used to trace it. Users can specify a time that
694 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
695 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
698 * @param time The timestamp to be used to tag this change of value.
699 * @param link The name of the link to be considered.
700 * @param variable The name of the variable to be considered.
701 * @param value The new value of the variable.
703 * @see TRACE_link_variable_declare, TRACE_link_variable_add_with_time, TRACE_link_variable_sub_with_time
705 void TRACE_link_variable_set_with_time (double time, const char *link, const char *variable, double value)
707 instr_user_variable(time, link, variable, "LINK", value, InstrUserVariable::SET, nullptr, &user_link_variables);
710 /** @ingroup TRACE_user_variables
711 * @brief Add a value to a variable of a link at a given timestamp.
713 * Same as #TRACE_link_variable_add, but let user specify the time used to trace it. Users can specify a time that
714 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
715 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
718 * @param time The timestamp to be used to tag this change of value.
719 * @param link The name of the link to be considered.
720 * @param variable The name of the variable to be considered.
721 * @param value The value to be added to the variable.
723 * @see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_sub_with_time
725 void TRACE_link_variable_add_with_time (double time, const char *link, const char *variable, double value)
727 instr_user_variable(time, link, variable, "LINK", value, InstrUserVariable::ADD, nullptr, &user_link_variables);
730 /** @ingroup TRACE_user_variables
731 * @brief Subtract a value from a variable of a link at a given timestamp.
733 * Same as #TRACE_link_variable_sub, but let user specify the time used to trace it. Users can specify a time that
734 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
735 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
738 * @param time The timestamp to be used to tag this change of value.
739 * @param link The name of the link to be considered.
740 * @param variable The name of the variable to be considered.
741 * @param value The value to be subtracted from the variable.
743 * @see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_add_with_time
745 void TRACE_link_variable_sub_with_time (double time, const char *link, const char *variable, double value)
747 instr_user_variable(time, link, variable, "LINK", value, InstrUserVariable::SUB, nullptr, &user_link_variables);
750 /* for link variables, but with src and dst used for get_route */
751 /** @ingroup TRACE_user_variables
752 * @brief Set the value of the variable present in the links connecting source and destination.
754 * Same as #TRACE_link_variable_set, but instead of providing the name of link to be considered, provide the source
755 * and destination hosts. All links that are part of the route between source and destination will have the variable
756 * set to the provided value.
758 * @param src The name of the source host for get route.
759 * @param dst The name of the destination host for get route.
760 * @param variable The name of the variable to be considered.
761 * @param value The new value of the variable.
763 * @see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add, TRACE_link_srcdst_variable_sub
765 void TRACE_link_srcdst_variable_set (const char *src, const char *dst, const char *variable, double value)
767 TRACE_link_srcdst_variable_set_with_time(simgrid_get_clock(), src, dst, variable, value);
770 /** @ingroup TRACE_user_variables
771 * @brief Add a value to the variable present in the links connecting source and destination.
773 * Same as #TRACE_link_variable_add, 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 value
775 * passed as parameter added to the current value of the variable name to be considered.
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 value to be added to the variable.
782 * @see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_sub
784 void TRACE_link_srcdst_variable_add (const char *src, const char *dst, const char *variable, double value)
786 TRACE_link_srcdst_variable_add_with_time(simgrid_get_clock(), src, dst, variable, value);
789 /** @ingroup TRACE_user_variables
790 * @brief Subtract a value from the variable present in the links connecting source and destination.
792 * Same as #TRACE_link_variable_sub, 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 subtracted from 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 subtracted from the variable.
801 * @see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_add
803 void TRACE_link_srcdst_variable_sub (const char *src, const char *dst, const char *variable, double value)
805 TRACE_link_srcdst_variable_sub_with_time(simgrid_get_clock(), src, dst, variable, value);
808 /** @ingroup TRACE_user_variables
809 * @brief Set the value of the variable present in the links connecting source and destination at a given timestamp.
811 * Same as #TRACE_link_srcdst_variable_set, but let user specify the time used to trace it. Users can specify a time
812 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
813 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
816 * @param time The timestamp to be used to tag this change of value.
817 * @param src The name of the source host for get route.
818 * @param dst The name of the destination host for get route.
819 * @param variable The name of the variable to be considered.
820 * @param value The new value of the variable.
822 * @see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add_with_time, TRACE_link_srcdst_variable_sub_with_time
824 void TRACE_link_srcdst_variable_set_with_time (double time, const char *src, const char *dst, const char *variable,
827 instr_user_srcdst_variable(time, src, dst, variable, "LINK", value, InstrUserVariable::SET);
830 /** @ingroup TRACE_user_variables
831 * @brief Add a value to the variable present in the links connecting source and destination at a given timestamp.
833 * Same as #TRACE_link_srcdst_variable_add, but let user specify the time used to trace it. Users can specify a time
834 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
835 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
838 * @param time The timestamp to be used to tag this change of value.
839 * @param src The name of the source host for get route.
840 * @param dst The name of the destination host for get route.
841 * @param variable The name of the variable to be considered.
842 * @param value The value to be added to the variable.
844 * @see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_sub_with_time
846 void TRACE_link_srcdst_variable_add_with_time (double time, const char *src, const char *dst, const char *variable,
849 instr_user_srcdst_variable(time, src, dst, variable, "LINK", value, InstrUserVariable::ADD);
852 /** @ingroup TRACE_user_variables
853 * @brief Subtract a value from the variable present in the links connecting source and dest. at a given timestamp.
855 * Same as #TRACE_link_srcdst_variable_sub, but let user specify the time used to trace it. Users can specify a time
856 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
857 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
860 * @param time The timestamp to be used to tag this change of value.
861 * @param src The name of the source host for get route.
862 * @param dst The name of the destination host for get route.
863 * @param variable The name of the variable to be considered.
864 * @param value The value to be subtracted from the variable.
866 * @see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_add_with_time
868 void TRACE_link_srcdst_variable_sub_with_time (double time, const char *src, const char *dst, const char *variable,
871 instr_user_srcdst_variable(time, src, dst, variable, "LINK", value, InstrUserVariable::SUB);
874 /** @ingroup TRACE_user_variables
875 * @brief Get declared user link variables
877 * This function should be used to get link variables that were already declared with #TRACE_link_variable_declare or
878 * with #TRACE_link_variable_declare_with_color.
880 * @return A dynar with the declared link variables, must be freed with xbt_dynar_free.
882 xbt_dynar_t TRACE_get_link_variables ()
884 return instr_set_to_dynar(user_link_variables);
887 /** @ingroup TRACE_user_variables
888 * @brief Declare a new user state associated to hosts.
890 * Declare a user state that will be associated to hosts.
891 * A user host state can be used to trace application states.
893 * @param state The name of the new state to be declared.
895 * @see TRACE_host_state_declare_value
897 void TRACE_host_state_declare (const char *state)
899 instr_new_user_state_type("HOST", state);
902 /** @ingroup TRACE_user_variables
903 * @brief Declare a new value for a user state associated to hosts.
905 * Declare a value for a state. The color needs to be a string with 3 numbers separated by spaces in the range [0,1].
906 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
908 * @param state The name of the new state to be declared.
909 * @param value The name of the value
910 * @param color The color of the value
912 * @see TRACE_host_state_declare
914 void TRACE_host_state_declare_value (const char *state, const char *value, const char *color)
916 instr_new_value_for_user_state_type (state, value, color);
919 /** @ingroup TRACE_user_variables
920 * @brief Set the user state to the given value.
922 * Change a user state previously declared to the given value.
924 * @param host The name of the host to be considered.
925 * @param state_name The name of the state previously declared.
926 * @param value_name The new value of the state.
928 * @see TRACE_host_state_declare, TRACE_host_push_state, TRACE_host_pop_state, TRACE_host_reset_state
930 void TRACE_host_set_state(const char* host, const char* state_name, const char* value_name)
932 simgrid::instr::StateType* state = simgrid::instr::Container::by_name(host)->get_state(state_name);
933 state->add_entity_value(value_name);
934 state->set_event(value_name);
937 /** @ingroup TRACE_user_variables
938 * @brief Push a new value for a state of a given host.
940 * Change a user state previously declared by pushing the new value to the state.
942 * @param host The name of the host to be considered.
943 * @param state_name The name of the state previously declared.
944 * @param value_name The value to be pushed.
946 * @see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_pop_state, TRACE_host_reset_state
948 void TRACE_host_push_state(const char* host, const char* state_name, const char* value_name)
950 simgrid::instr::Container::by_name(host)->get_state(state_name)->push_event(value_name);
953 /** @ingroup TRACE_user_variables
954 * @brief Pop the last value of a state of a given host.
956 * Change a user state previously declared by removing the last value of the state.
958 * @param host The name of the host to be considered.
959 * @param state_name The name of the state to be popped.
961 * @see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_reset_state
963 void TRACE_host_pop_state(const char* host, const char* state_name)
965 simgrid::instr::Container::by_name(host)->get_state(state_name)->pop_event();