1 /* Copyright (c) 2010-2019. 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/kernel/routing/NetPoint.hpp"
7 #include "src/instr/instr_private.hpp"
8 #include "src/surf/network_interface.hpp"
9 #include "src/surf/surf_private.hpp"
10 #include "surf/surf.hpp"
15 enum class InstrUserVariable { DECLARE, SET, ADD, SUB };
17 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API");
19 std::set<std::string> created_categories;
20 std::set<std::string> declared_marks;
21 std::set<std::string> user_host_variables;
22 std::set<std::string> user_vm_variables;
23 std::set<std::string> user_link_variables;
24 extern std::set<std::string> trivaNodeTypes;
25 extern std::set<std::string> trivaEdgeTypes;
27 static xbt_dynar_t instr_set_to_dynar(std::set<std::string>* filter)
29 if (not TRACE_is_enabled() || not TRACE_needs_platform())
32 xbt_dynar_t ret = xbt_dynar_new (sizeof(char*), &xbt_free_ref);
33 for (auto const& name : *filter)
34 xbt_dynar_push_as(ret, char*, xbt_strdup(name.c_str()));
39 /** @ingroup TRACE_category
40 * @brief Declare a new category with a random color.
42 * This function should be used to define a user category. The category can be used to differentiate the tasks that
43 * are created during the simulation (for example, tasks from server1, server2, or request tasks, computation tasks,
44 * communication tasks). All resource utilization (host power and link bandwidth) will be classified according to the
45 * task category. Tasks that do not belong to a category are not traced. The color for the category that is being
46 * declared is random. This function has no effect if a category with the same name has been already declared.
48 * See @ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
50 * @param category The name of the new tracing category to be created.
52 * @see TRACE_category_with_color, MSG_task_set_category, SD_task_set_category
54 void TRACE_category(const char *category)
56 TRACE_category_with_color (category, nullptr);
59 /** @ingroup TRACE_category
60 * @brief Declare a new category with a color.
62 * Same as #TRACE_category, but let user specify a color encoded as a RGB-like string with three floats from 0 to 1.
63 * 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"
64 * as color. This function has no effect if a category with the same name has been already declared.
66 * See @ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
68 * @param category The name of the new tracing category to be created.
69 * @param color The color of the category (see @ref outcomes_vizu to
70 * know how to correctly specify the color)
72 * @see MSG_task_set_category, SD_task_set_category
74 void TRACE_category_with_color (const char *category, const char *color)
76 /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with categories */
77 if (not TRACE_is_enabled() || not TRACE_needs_platform())
80 if (not(TRACE_categorized() && category != nullptr))
83 //check if category is already created
84 if (created_categories.find(category) != created_categories.end())
87 created_categories.insert(category);
90 std::string final_color;
92 //generate a random color
93 static std::default_random_engine rnd_engine;
94 std::uniform_real_distribution<double> prng(0.0, std::nextafter(1.0, 2.0));
95 double red = prng(rnd_engine);
96 double green = prng(rnd_engine);
97 double blue = prng(rnd_engine);
98 final_color = std::to_string(red) + " " + std::to_string(green) + " " + std::to_string(blue);
100 final_color = std::string(color);
103 XBT_DEBUG("CAT,declare %s, \"%s\" \"%s\"", category, color, final_color.c_str());
105 //define the type of this category on top of hosts and links
106 instr_new_variable_type (category, final_color);
109 /** @ingroup TRACE_category
110 * @brief Get declared categories
112 * This function should be used to get categories that were already declared with #TRACE_category or with
113 * #TRACE_category_with_color.
115 * See @ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
117 * @return A dynar with the declared categories, must be freed with xbt_dynar_free.
119 * @see MSG_task_set_category, SD_task_set_category
121 xbt_dynar_t TRACE_get_categories ()
123 if (not TRACE_is_enabled() || not TRACE_categorized())
125 return instr_set_to_dynar(&created_categories);
128 /** @ingroup TRACE_mark
129 * @brief Declare a new type for tracing mark.
131 * This function declares a new Paje event type in the trace file that can be used by simulators to declare
132 * application-level marks. This function is independent of which API is used in SimGrid.
134 * @param mark_type The name of the new type.
138 void TRACE_declare_mark(const char *mark_type)
140 /* safe switchs. tracing has to be activated and if platform is not traced, we can't deal with marks */
141 if (not TRACE_is_enabled() || not TRACE_needs_platform())
144 xbt_assert(mark_type, "mark_type is nullptr");
146 //check if mark_type is already declared
147 if (declared_marks.find(mark_type) != declared_marks.end()) {
148 THROWF (tracing_error, 1, "mark_type with name (%s) is already declared", mark_type);
151 XBT_DEBUG("MARK,declare %s", mark_type);
152 simgrid::instr::Container::get_root()->type_->by_name_or_create<simgrid::instr::EventType>(mark_type);
153 declared_marks.insert(mark_type);
156 /** @ingroup TRACE_mark
157 * @brief Declare a new colored value for a previously declared mark type.
159 * This function declares a new colored value for a Paje event type in the trace file that can be used by simulators to
160 * declare application-level marks. This function is independent of which API is used in SimGrid. The color needs to be
161 * a string with three numbers separated by spaces in the range [0,1].
162 * 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
163 * be white ("1 1 1").
165 * @param mark_type The name of the new type.
166 * @param mark_value The name of the new value for this type.
167 * @param mark_color The color of the new value for this type.
171 void TRACE_declare_mark_value_with_color (const char *mark_type, const char *mark_value, const char *mark_color)
173 /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
174 if (not TRACE_is_enabled() || not TRACE_needs_platform())
177 xbt_assert(mark_type, "mark_type is nullptr");
178 xbt_assert(mark_value, "mark_value is nullptr");
180 simgrid::instr::EventType* type =
181 static_cast<simgrid::instr::EventType*>(simgrid::instr::Container::get_root()->type_->by_name(mark_type));
183 THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
186 mark_color = "1.0 1.0 1.0" /*white*/;
188 XBT_DEBUG("MARK,declare_value %s %s %s", mark_type, mark_value, mark_color);
189 type->add_entity_value(mark_value, mark_color);
193 /** @ingroup TRACE_mark
194 * @brief Declare a new value for a previously declared mark type.
196 * This function declares a new value for a Paje event type in the trace file that can be used by simulators to declare
197 * application-level marks. This function is independent of which API is used in SimGrid. Calling this function is the
198 * same as calling @ref TRACE_declare_mark_value_with_color with a nullptr color.
200 * @param mark_type The name of the new type.
201 * @param mark_value The name of the new value for this type.
205 void TRACE_declare_mark_value (const char *mark_type, const char *mark_value)
207 TRACE_declare_mark_value_with_color (mark_type, mark_value, nullptr);
211 * @ingroup TRACE_mark
212 * @brief Create a new instance of a tracing mark type.
214 * This function creates a mark in the trace file. The first parameter had to be previously declared using
215 * #TRACE_declare_mark, the second is the identifier for this mark instance. We recommend that the mark_value is a
216 * unique value for the whole simulation. Nevertheless, this is not a strong requirement: the trace will be valid even
217 * if there are multiple mark identifiers for the same trace.
219 * @param mark_type The name of the type for which the new instance will belong.
220 * @param mark_value The name of the new instance mark.
222 * @see TRACE_declare_mark
224 void TRACE_mark(const char *mark_type, const char *mark_value)
226 /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
227 if (not TRACE_is_enabled() || not TRACE_needs_platform())
230 xbt_assert(mark_type, "mark_type is nullptr");
231 xbt_assert(mark_value, "mark_value is nullptr");
233 //check if mark_type is already declared
234 simgrid::instr::EventType* type =
235 static_cast<simgrid::instr::EventType*>(simgrid::instr::Container::get_root()->type_->by_name(mark_type));
237 THROWF (tracing_error, 1, "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(MSG_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, std::set<std::string>* filter)
263 /* safe switches. tracing has to be activated and if platform is not traced, we don't allow user variables */
264 if (not TRACE_is_enabled() || not TRACE_needs_platform())
267 //check if variable is already declared
268 auto created = filter->find(variable_name);
269 if (what == InstrUserVariable::DECLARE) {
270 if (created == filter->end()) { // not declared yet
271 filter->insert(variable_name);
272 instr_new_user_variable_type(father_type, variable_name, color == nullptr ? "" : color);
275 if (created != filter->end()) { // declared, let's work
276 simgrid::instr::VariableType* variable =
277 simgrid::instr::Container::by_name(resource)->get_variable(variable_name);
279 case InstrUserVariable::SET:
280 variable->set_event(time, value);
282 case InstrUserVariable::ADD:
283 variable->add_event(time, value);
285 case InstrUserVariable::SUB:
286 variable->sub_event(time, value);
295 static void instr_user_srcdst_variable(double time, const char *src, const char *dst, const char *variable,
296 const char *father_type, double value, InstrUserVariable what)
298 simgrid::kernel::routing::NetPoint* src_elm = sg_netpoint_by_name_or_null(src);
300 xbt_die("Element '%s' not found!",src);
302 simgrid::kernel::routing::NetPoint* dst_elm = sg_netpoint_by_name_or_null(dst);
304 xbt_die("Element '%s' not found!",dst);
306 std::vector<simgrid::kernel::resource::LinkImpl*> route;
307 simgrid::kernel::routing::NetZoneImpl::get_global_route(src_elm, dst_elm, route, nullptr);
308 for (auto const& link : route)
309 instr_user_variable(time, link->get_cname(), variable, father_type, value, what, nullptr, &user_link_variables);
312 /** @ingroup TRACE_API
313 * @brief Creates a file with the topology of the platform file used for the simulator.
315 * The graph topology will have the following properties: all hosts, links and routers of the platform file are mapped
316 * to graph nodes; routes are mapped to edges.
317 * The platform's AS are not represented in the output.
319 * @param filename The name of the file that will hold the graph.
321 * @return 1 of successful, 0 otherwise.
323 int TRACE_platform_graph_export_graphviz (const char *filename)
325 /* returns 1 if successful, 0 otherwise */
326 if (not TRACE_is_enabled())
328 xbt_graph_t g = instr_routing_platform_graph();
331 instr_routing_platform_graph_export_graphviz (g, filename);
332 xbt_graph_free_graph(g, xbt_free_f, xbt_free_f, nullptr);
337 * Derived functions that use instr_user_variable and TRACE_user_srcdst_variable. They were previously defined as
338 * pre-processors directives, but were transformed into functions so the user can track them using gdb.
341 /* for VM variables */
342 /** @ingroup TRACE_user_variables
343 * @brief Declare a new user variable associated to VMs.
345 * Declare a user variable that will be associated to VMs. A user vm variable can be used to trace user variables
346 * such as the number of tasks in a VM, the number of clients in an application (for VMs), and so on. The color
347 * associated to this new variable will be random.
349 * @param variable The name of the new variable to be declared.
351 * @see TRACE_vm_variable_declare_with_color
353 void TRACE_vm_variable_declare (const char *variable)
355 instr_user_variable(0, nullptr, variable, "VM", 0, InstrUserVariable::DECLARE, nullptr, &user_vm_variables);
358 /** @ingroup TRACE_user_variables
359 * @brief Declare a new user variable associated to VMs with a color.
361 * Same as #TRACE_vm_variable_declare, but associated a color to the newly created user host variable. The color needs
362 * to be a string with three numbers separated by spaces in the range [0,1].
363 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
365 * @param variable The name of the new variable to be declared.
366 * @param color The color for the new variable.
368 void TRACE_vm_variable_declare_with_color (const char *variable, const char *color)
370 instr_user_variable(0, nullptr, variable, "VM", 0, InstrUserVariable::DECLARE, color, &user_vm_variables);
373 /** @ingroup TRACE_user_variables
374 * @brief Set the value of a variable of a host.
376 * @param vm The name of the VM to be considered.
377 * @param variable The name of the variable to be considered.
378 * @param value The new value of the variable.
380 * @see TRACE_vm_variable_declare, TRACE_vm_variable_add, TRACE_vm_variable_sub
382 void TRACE_vm_variable_set (const char *vm, const char *variable, double value)
384 TRACE_vm_variable_set_with_time (MSG_get_clock(), vm, variable, value);
387 /** @ingroup TRACE_user_variables
388 * @brief Add a value to a variable of a VM.
390 * @param vm The name of the VM to be considered.
391 * @param variable The name of the variable to be considered.
392 * @param value The value to be added to the variable.
394 * @see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_sub
396 void TRACE_vm_variable_add (const char *vm, const char *variable, double value)
398 TRACE_vm_variable_add_with_time (MSG_get_clock(), vm, variable, value);
401 /** @ingroup TRACE_user_variables
402 * @brief Subtract a value from a variable of a VM.
404 * @param vm The name of the vm to be considered.
405 * @param variable The name of the variable to be considered.
406 * @param value The value to be subtracted from the variable.
408 * @see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_add
410 void TRACE_vm_variable_sub (const char *vm, const char *variable, double value)
412 TRACE_vm_variable_sub_with_time (MSG_get_clock(), vm, variable, value);
415 /** @ingroup TRACE_user_variables
416 * @brief Set the value of a variable of a VM at a given timestamp.
418 * Same as #TRACE_vm_variable_set, but let user specify the time used to trace it. Users can specify a time that
419 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
420 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
423 * @param time The timestamp to be used to tag this change of value.
424 * @param vm The name of the VM to be considered.
425 * @param variable The name of the variable to be considered.
426 * @param value The new value of the variable.
428 * @see TRACE_vm_variable_declare, TRACE_vm_variable_add_with_time, TRACE_vm_variable_sub_with_time
430 void TRACE_vm_variable_set_with_time (double time, const char *vm, const char *variable, double value)
432 instr_user_variable(time, vm, variable, "VM", value, InstrUserVariable::SET, nullptr, &user_vm_variables);
435 /** @ingroup TRACE_user_variables
436 * @brief Add a value to a variable of a VM at a given timestamp.
438 * Same as #TRACE_vm_variable_add, but let user specify the time used to trace it. Users can specify a time that
439 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
440 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
443 * @param time The timestamp to be used to tag this change of value.
444 * @param vm The name of the VM to be considered.
445 * @param variable The name of the variable to be considered.
446 * @param value The value to be added to the variable.
448 * @see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_sub_with_time
450 void TRACE_vm_variable_add_with_time (double time, const char *vm, const char *variable, double value)
452 instr_user_variable(time, vm, variable, "VM", value, InstrUserVariable::ADD, nullptr, &user_vm_variables);
455 /** @ingroup TRACE_user_variables
456 * @brief Subtract a value from a variable of a VM at a given timestamp.
458 * Same as #TRACE_vm_variable_sub, but let user specify the time used to trace it. Users can specify a time that
459 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
460 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
463 * @param time The timestamp to be used to tag this change of value.
464 * @param vm The name of the VM to be considered.
465 * @param variable The name of the variable to be considered.
466 * @param value The value to be subtracted from the variable.
468 * @see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_add_with_time
470 void TRACE_vm_variable_sub_with_time (double time, const char *vm, const char *variable, double value)
472 instr_user_variable(time, vm, variable, "VM", value, InstrUserVariable::SUB, nullptr, &user_vm_variables);
475 /* for host variables */
476 /** @ingroup TRACE_user_variables
477 * @brief Declare a new user variable associated to hosts.
479 * Declare a user variable that will be associated to hosts.
480 * A user host variable can be used to trace user variables such as the number of tasks in a server, the number of
481 * clients in an application (for hosts), and so on. The color associated to this new variable will be random.
483 * @param variable The name of the new variable to be declared.
485 * @see TRACE_host_variable_declare_with_color
487 void TRACE_host_variable_declare (const char *variable)
489 instr_user_variable(0, nullptr, variable, "HOST", 0, InstrUserVariable::DECLARE, nullptr, &user_host_variables);
492 /** @ingroup TRACE_user_variables
493 * @brief Declare a new user variable associated to hosts with a color.
495 * Same as #TRACE_host_variable_declare, but associated a color to the newly created user host variable. The color
496 * needs to be a string with three numbers separated by spaces in the range [0,1].
497 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
499 * @param variable The name of the new variable to be declared.
500 * @param color The color for the new variable.
502 void TRACE_host_variable_declare_with_color (const char *variable, const char *color)
504 instr_user_variable(0, nullptr, variable, "HOST", 0, InstrUserVariable::DECLARE, color, &user_host_variables);
507 /** @ingroup TRACE_user_variables
508 * @brief Set the value of a variable of a host.
510 * @param host The name of the host to be considered.
511 * @param variable The name of the variable to be considered.
512 * @param value The new value of the variable.
514 * @see TRACE_host_variable_declare, TRACE_host_variable_add, TRACE_host_variable_sub
516 void TRACE_host_variable_set (const char *host, const char *variable, double value)
518 TRACE_host_variable_set_with_time (MSG_get_clock(), host, variable, value);
521 /** @ingroup TRACE_user_variables
522 * @brief Add a value to a variable of a host.
524 * @param host The name of the host to be considered.
525 * @param variable The name of the variable to be considered.
526 * @param value The value to be added to the variable.
528 * @see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_sub
530 void TRACE_host_variable_add (const char *host, const char *variable, double value)
532 TRACE_host_variable_add_with_time (MSG_get_clock(), host, variable, value);
535 /** @ingroup TRACE_user_variables
536 * @brief Subtract a value from a variable of a host.
538 * @param host The name of the host to be considered.
539 * @param variable The name of the variable to be considered.
540 * @param value The value to be subtracted from the variable.
542 * @see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_add
544 void TRACE_host_variable_sub (const char *host, const char *variable, double value)
546 TRACE_host_variable_sub_with_time (MSG_get_clock(), host, variable, value);
549 /** @ingroup TRACE_user_variables
550 * @brief Set the value of a variable of a host at a given timestamp.
552 * Same as #TRACE_host_variable_set, but let user specify the time used to trace it. Users can specify a time that
553 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
554 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
557 * @param time The timestamp to be used to tag this change of value.
558 * @param host The name of the host to be considered.
559 * @param variable The name of the variable to be considered.
560 * @param value The new value of the variable.
562 * @see TRACE_host_variable_declare, TRACE_host_variable_add_with_time, TRACE_host_variable_sub_with_time
564 void TRACE_host_variable_set_with_time (double time, const char *host, const char *variable, double value)
566 instr_user_variable(time, host, variable, "HOST", value, InstrUserVariable::SET, nullptr, &user_host_variables);
569 /** @ingroup TRACE_user_variables
570 * @brief Add a value to a variable of a host at a given timestamp.
572 * Same as #TRACE_host_variable_add, but let user specify the time used to trace it. Users can specify a time that
573 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
574 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
577 * @param time The timestamp to be used to tag this change of value.
578 * @param host The name of the host to be considered.
579 * @param variable The name of the variable to be considered.
580 * @param value The value to be added to the variable.
582 * @see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_sub_with_time
584 void TRACE_host_variable_add_with_time (double time, const char *host, const char *variable, double value)
586 instr_user_variable(time, host, variable, "HOST", value, InstrUserVariable::ADD, nullptr, &user_host_variables);
589 /** @ingroup TRACE_user_variables
590 * @brief Subtract a value from a variable of a host at a given timestamp.
592 * Same as #TRACE_host_variable_sub, but let user specify the time used to trace it. Users can specify a time that
593 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
594 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
597 * @param time The timestamp to be used to tag this change of value.
598 * @param host The name of the host to be considered.
599 * @param variable The name of the variable to be considered.
600 * @param value The value to be subtracted from the variable.
602 * @see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_add_with_time
604 void TRACE_host_variable_sub_with_time (double time, const char *host, const char *variable, double value)
606 instr_user_variable(time, host, variable, "HOST", value, InstrUserVariable::SUB, nullptr, &user_host_variables);
609 /** @ingroup TRACE_user_variables
610 * @brief Get declared user host variables
612 * This function should be used to get host variables that were already declared with #TRACE_host_variable_declare or
613 * with #TRACE_host_variable_declare_with_color.
615 * @return A dynar with the declared host variables, must be freed with xbt_dynar_free.
617 xbt_dynar_t TRACE_get_host_variables ()
619 return instr_set_to_dynar(&user_host_variables);
622 /* for link variables */
623 /** @ingroup TRACE_user_variables
624 * @brief Declare a new user variable associated to links.
626 * Declare a user variable that will be associated to links.
627 * A user link variable can be used, for example, to trace user variables such as the number of messages being
628 * transferred through network links. The color associated to this new variable will be random.
630 * @param variable The name of the new variable to be declared.
632 * @see TRACE_link_variable_declare_with_color
634 void TRACE_link_variable_declare (const char *variable)
636 instr_user_variable(0, nullptr, variable, "LINK", 0, InstrUserVariable::DECLARE, nullptr, &user_link_variables);
639 /** @ingroup TRACE_user_variables
640 * @brief Declare a new user variable associated to links with a color.
642 * Same as #TRACE_link_variable_declare, but associated a color to the newly created user link variable. The color
643 * needs to be a string with three numbers separated by spaces in the range [0,1].
644 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
646 * @param variable The name of the new variable to be declared.
647 * @param color The color for the new variable.
649 void TRACE_link_variable_declare_with_color (const char *variable, const char *color)
651 instr_user_variable(0, nullptr, variable, "LINK", 0, InstrUserVariable::DECLARE, color, &user_link_variables);
654 /** @ingroup TRACE_user_variables
655 * @brief Set the value of a variable of a link.
657 * @param link The name of the link to be considered.
658 * @param variable The name of the variable to be considered.
659 * @param value The new value of the variable.
661 * @see TRACE_link_variable_declare, TRACE_link_variable_add, TRACE_link_variable_sub
663 void TRACE_link_variable_set (const char *link, const char *variable, double value)
665 TRACE_link_variable_set_with_time (MSG_get_clock(), link, variable, value);
668 /** @ingroup TRACE_user_variables
669 * @brief Add a value to a variable of a link.
671 * @param link The name of the link to be considered.
672 * @param variable The name of the variable to be considered.
673 * @param value The value to be added to the variable.
675 * @see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_sub
677 void TRACE_link_variable_add (const char *link, const char *variable, double value)
679 TRACE_link_variable_add_with_time (MSG_get_clock(), link, variable, value);
682 /** @ingroup TRACE_user_variables
683 * @brief Subtract a value from a variable of a link.
685 * @param link The name of the link to be considered.
686 * @param variable The name of the variable to be considered.
687 * @param value The value to be subtracted from the variable.
689 * @see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_add
691 void TRACE_link_variable_sub (const char *link, const char *variable, double value)
693 TRACE_link_variable_sub_with_time (MSG_get_clock(), link, variable, value);
696 /** @ingroup TRACE_user_variables
697 * @brief Set the value of a variable of a link at a given timestamp.
699 * Same as #TRACE_link_variable_set, but let user specify the time used to trace it. Users can specify a time that
700 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
701 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
704 * @param time The timestamp to be used to tag this change of value.
705 * @param link The name of the link to be considered.
706 * @param variable The name of the variable to be considered.
707 * @param value The new value of the variable.
709 * @see TRACE_link_variable_declare, TRACE_link_variable_add_with_time, TRACE_link_variable_sub_with_time
711 void TRACE_link_variable_set_with_time (double time, const char *link, const char *variable, double value)
713 instr_user_variable(time, link, variable, "LINK", value, InstrUserVariable::SET, nullptr, &user_link_variables);
716 /** @ingroup TRACE_user_variables
717 * @brief Add a value to a variable of a link at a given timestamp.
719 * Same as #TRACE_link_variable_add, but let user specify the time used to trace it. Users can specify a time that
720 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
721 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
724 * @param time The timestamp to be used to tag this change of value.
725 * @param link The name of the link to be considered.
726 * @param variable The name of the variable to be considered.
727 * @param value The value to be added to the variable.
729 * @see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_sub_with_time
731 void TRACE_link_variable_add_with_time (double time, const char *link, const char *variable, double value)
733 instr_user_variable(time, link, variable, "LINK", value, InstrUserVariable::ADD, nullptr, &user_link_variables);
736 /** @ingroup TRACE_user_variables
737 * @brief Subtract a value from a variable of a link at a given timestamp.
739 * Same as #TRACE_link_variable_sub, but let user specify the time used to trace it. Users can specify a time that
740 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
741 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
744 * @param time The timestamp to be used to tag this change of value.
745 * @param link The name of the link to be considered.
746 * @param variable The name of the variable to be considered.
747 * @param value The value to be subtracted from the variable.
749 * @see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_add_with_time
751 void TRACE_link_variable_sub_with_time (double time, const char *link, const char *variable, double value)
753 instr_user_variable(time, link, variable, "LINK", value, InstrUserVariable::SUB, nullptr, &user_link_variables);
756 /* for link variables, but with src and dst used for get_route */
757 /** @ingroup TRACE_user_variables
758 * @brief Set the value of the variable present in the links connecting source and destination.
760 * Same as #TRACE_link_variable_set, but instead of providing the name of link to be considered, provide the source
761 * and destination hosts. All links that are part of the route between source and destination will have the variable
762 * set to the provided value.
764 * @param src The name of the source host for get route.
765 * @param dst The name of the destination host for get route.
766 * @param variable The name of the variable to be considered.
767 * @param value The new value of the variable.
769 * @see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add, TRACE_link_srcdst_variable_sub
771 void TRACE_link_srcdst_variable_set (const char *src, const char *dst, const char *variable, double value)
773 TRACE_link_srcdst_variable_set_with_time (MSG_get_clock(), src, dst, variable, value);
776 /** @ingroup TRACE_user_variables
777 * @brief Add a value to the variable present in the links connecting source and destination.
779 * Same as #TRACE_link_variable_add, but instead of providing the name of link to be considered, provide the source
780 * and destination hosts. All links that are part of the route between source and destination will have the value
781 * passed as parameter added to the current value of the variable name to be considered.
783 * @param src The name of the source host for get route.
784 * @param dst The name of the destination host for get route.
785 * @param variable The name of the variable to be considered.
786 * @param value The value to be added to the variable.
788 * @see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_sub
790 void TRACE_link_srcdst_variable_add (const char *src, const char *dst, const char *variable, double value)
792 TRACE_link_srcdst_variable_add_with_time (MSG_get_clock(), src, dst, variable, value);
795 /** @ingroup TRACE_user_variables
796 * @brief Subtract a value from the variable present in the links connecting source and destination.
798 * Same as #TRACE_link_variable_sub, but instead of providing the name of link to be considered, provide the source
799 * and destination hosts. All links that are part of the route between source and destination will have the value
800 * passed as parameter subtracted from the current value of the variable name to be considered.
802 * @param src The name of the source host for get route.
803 * @param dst The name of the destination host for get route.
804 * @param variable The name of the variable to be considered.
805 * @param value The value to be subtracted from the variable.
807 * @see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_add
809 void TRACE_link_srcdst_variable_sub (const char *src, const char *dst, const char *variable, double value)
811 TRACE_link_srcdst_variable_sub_with_time (MSG_get_clock(), src, dst, variable, value);
814 /** @ingroup TRACE_user_variables
815 * @brief Set the value of the variable present in the links connecting source and destination at a given timestamp.
817 * Same as #TRACE_link_srcdst_variable_set, but let user specify the time used to trace it. Users can specify a time
818 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
819 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
822 * @param time The timestamp to be used to tag this change of value.
823 * @param src The name of the source host for get route.
824 * @param dst The name of the destination host for get route.
825 * @param variable The name of the variable to be considered.
826 * @param value The new value of the variable.
828 * @see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add_with_time, TRACE_link_srcdst_variable_sub_with_time
830 void TRACE_link_srcdst_variable_set_with_time (double time, const char *src, const char *dst, const char *variable,
833 instr_user_srcdst_variable(time, src, dst, variable, "LINK", value, InstrUserVariable::SET);
836 /** @ingroup TRACE_user_variables
837 * @brief Add a value to the variable present in the links connecting source and destination at a given timestamp.
839 * Same as #TRACE_link_srcdst_variable_add, but let user specify the time used to trace it. Users can specify a time
840 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
841 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
844 * @param time The timestamp to be used to tag this change of value.
845 * @param src The name of the source host for get route.
846 * @param dst The name of the destination host for get route.
847 * @param variable The name of the variable to be considered.
848 * @param value The value to be added to the variable.
850 * @see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_sub_with_time
852 void TRACE_link_srcdst_variable_add_with_time (double time, const char *src, const char *dst, const char *variable,
855 instr_user_srcdst_variable(time, src, dst, variable, "LINK", value, InstrUserVariable::ADD);
858 /** @ingroup TRACE_user_variables
859 * @brief Subtract a value from the variable present in the links connecting source and dest. at a given timestamp.
861 * Same as #TRACE_link_srcdst_variable_sub, but let user specify the time used to trace it. Users can specify a time
862 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
863 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
866 * @param time The timestamp to be used to tag this change of value.
867 * @param src The name of the source host for get route.
868 * @param dst The name of the destination host for get route.
869 * @param variable The name of the variable to be considered.
870 * @param value The value to be subtracted from the variable.
872 * @see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_add_with_time
874 void TRACE_link_srcdst_variable_sub_with_time (double time, const char *src, const char *dst, const char *variable,
877 instr_user_srcdst_variable(time, src, dst, variable, "LINK", value, InstrUserVariable::SUB);
880 /** @ingroup TRACE_user_variables
881 * @brief Get declared user link variables
883 * This function should be used to get link variables that were already declared with #TRACE_link_variable_declare or
884 * with #TRACE_link_variable_declare_with_color.
886 * @return A dynar with the declared link variables, must be freed with xbt_dynar_free.
888 xbt_dynar_t TRACE_get_link_variables ()
890 return instr_set_to_dynar(&user_link_variables);
893 /** @ingroup TRACE_user_variables
894 * @brief Declare a new user state associated to hosts.
896 * Declare a user state that will be associated to hosts.
897 * A user host state can be used to trace application states.
899 * @param state The name of the new state to be declared.
901 * @see TRACE_host_state_declare_value
903 void TRACE_host_state_declare (const char *state)
905 instr_new_user_state_type("HOST", state);
908 /** @ingroup TRACE_user_variables
909 * @brief Declare a new value for a user state associated to hosts.
911 * Declare a value for a state. The color needs to be a string with 3 numbers separated by spaces in the range [0,1].
912 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
914 * @param state The name of the new state to be declared.
915 * @param value The name of the value
916 * @param color The color of the value
918 * @see TRACE_host_state_declare
920 void TRACE_host_state_declare_value (const char *state, const char *value, const char *color)
922 instr_new_value_for_user_state_type (state, value, color);
925 /** @ingroup TRACE_user_variables
926 * @brief Set the user state to the given value.
928 * Change a user state previously declared to the given value.
930 * @param host The name of the host to be considered.
931 * @param state_name The name of the state previously declared.
932 * @param value_name The new value of the state.
934 * @see TRACE_host_state_declare, TRACE_host_push_state, TRACE_host_pop_state, TRACE_host_reset_state
936 void TRACE_host_set_state(const char* host, const char* state_name, const char* value_name)
938 simgrid::instr::StateType* state = simgrid::instr::Container::by_name(host)->get_state(state_name);
939 state->add_entity_value(value_name);
940 state->set_event(value_name);
943 /** @ingroup TRACE_user_variables
944 * @brief Push a new value for a state of a given host.
946 * Change a user state previously declared by pushing the new value to the state.
948 * @param host The name of the host to be considered.
949 * @param state_name The name of the state previously declared.
950 * @param value_name The value to be pushed.
952 * @see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_pop_state, TRACE_host_reset_state
954 void TRACE_host_push_state(const char* host, const char* state_name, const char* value_name)
956 simgrid::instr::Container::by_name(host)->get_state(state_name)->push_event(value_name);
959 /** @ingroup TRACE_user_variables
960 * @brief Pop the last value of a state of a given host.
962 * Change a user state previously declared by removing the last value of the state.
964 * @param host The name of the host to be considered.
965 * @param state_name The name of the state to be popped.
967 * @see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_reset_state
969 void TRACE_host_pop_state(const char* host, const char* state_name)
971 simgrid::instr::Container::by_name(host)->get_state(state_name)->pop_event();
974 /** @ingroup TRACE_API
975 * @brief Get Paje container types that can be mapped to the nodes of a graph.
977 * This function can be used to create a user made graph configuration file for Triva. Normally, it is used with the
978 * functions defined in @ref TRACE_user_variables.
980 * @return A dynar with the types, must be freed with xbt_dynar_free.
982 xbt_dynar_t TRACE_get_node_types ()
984 return instr_set_to_dynar(&trivaNodeTypes);
987 /** @ingroup TRACE_API
988 * @brief Get Paje container types that can be mapped to the edges of a graph.
990 * This function can be used to create a user made graph configuration file for Triva. Normally, it is used with the
991 * functions defined in @ref TRACE_user_variables.
993 * @return A dynar with the types, must be freed with xbt_dynar_free.
995 xbt_dynar_t TRACE_get_edge_types ()
997 return instr_set_to_dynar(&trivaEdgeTypes);