1 /* Copyright (c) 2010-2018. 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"
13 enum class InstrUserVariable { DECLARE, SET, ADD, SUB };
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API");
17 std::set<std::string> created_categories;
18 std::set<std::string> declared_marks;
19 std::set<std::string> user_host_variables;
20 std::set<std::string> user_vm_variables;
21 std::set<std::string> user_link_variables;
22 extern std::set<std::string> trivaNodeTypes;
23 extern std::set<std::string> trivaEdgeTypes;
25 static xbt_dynar_t instr_set_to_dynar(std::set<std::string>* filter)
27 if (not TRACE_is_enabled() || not TRACE_needs_platform())
30 xbt_dynar_t ret = xbt_dynar_new (sizeof(char*), &xbt_free_ref);
31 for (auto const& name : *filter)
32 xbt_dynar_push_as(ret, char*, xbt_strdup(name.c_str()));
37 /** @ingroup TRACE_category
38 * @brief Declare a new category with a random color.
40 * This function should be used to define a user category. The category can be used to differentiate the tasks that
41 * are created during the simulation (for example, tasks from server1, server2, or request tasks, computation tasks,
42 * communication tasks). All resource utilization (host power and link bandwidth) will be classified according to the
43 * task category. Tasks that do not belong to a category are not traced. The color for the category that is being
44 * declared is random. This function has no effect if a category with the same name has been already declared.
46 * See @ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
48 * @param category The name of the new tracing category to be created.
50 * @see TRACE_category_with_color, MSG_task_set_category, SD_task_set_category
52 void TRACE_category(const char *category)
54 TRACE_category_with_color (category, nullptr);
57 /** @ingroup TRACE_category
58 * @brief Declare a new category with a color.
60 * Same as #TRACE_category, but let user specify a color encoded as a RGB-like string with three floats from 0 to 1.
61 * 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"
62 * as color. This function has no effect if a category with the same name has been already declared.
64 * See @ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
66 * @param category The name of the new tracing category to be created.
67 * @param color The color of the category (see @ref outcomes_vizu to
68 * know how to correctly specify the color)
70 * @see MSG_task_set_category, SD_task_set_category
72 void TRACE_category_with_color (const char *category, const char *color)
74 /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with categories */
75 if (not TRACE_is_enabled() || not TRACE_needs_platform())
78 if (not(TRACE_categorized() && category != nullptr))
81 //check if category is already created
82 if (created_categories.find(category) != created_categories.end())
85 created_categories.insert(category);
88 std::string final_color;
90 //generate a random color
91 double red = drand48();
92 double green = drand48();
93 double blue = drand48();
94 final_color = std::to_string(red) + " " + std::to_string(green) + " " + std::to_string(blue);
96 final_color = std::string(color);
99 XBT_DEBUG("CAT,declare %s, \"%s\" \"%s\"", category, color, final_color.c_str());
101 //define the type of this category on top of hosts and links
102 instr_new_variable_type (category, final_color);
105 /** @ingroup TRACE_category
106 * @brief Get declared categories
108 * This function should be used to get categories that were already declared with #TRACE_category or with
109 * #TRACE_category_with_color.
111 * See @ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
113 * @return A dynar with the declared categories, must be freed with xbt_dynar_free.
115 * @see MSG_task_set_category, SD_task_set_category
117 xbt_dynar_t TRACE_get_categories ()
119 if (not TRACE_is_enabled() || not TRACE_categorized())
121 return instr_set_to_dynar(&created_categories);
124 /** @ingroup TRACE_mark
125 * @brief Declare a new type for tracing mark.
127 * This function declares a new Paje event type in the trace file that can be used by simulators to declare
128 * application-level marks. This function is independent of which API is used in SimGrid.
130 * @param mark_type The name of the new type.
134 void TRACE_declare_mark(const char *mark_type)
136 /* safe switchs. tracing has to be activated and if platform is not traced, we can't deal with marks */
137 if (not TRACE_is_enabled() || not TRACE_needs_platform())
140 xbt_assert(mark_type, "mark_type is nullptr");
142 //check if mark_type is already declared
143 if (declared_marks.find(mark_type) != declared_marks.end()) {
144 THROWF (tracing_error, 1, "mark_type with name (%s) is already declared", mark_type);
147 XBT_DEBUG("MARK,declare %s", mark_type);
148 simgrid::instr::Container::get_root()->type_->by_name_or_create<simgrid::instr::EventType>(mark_type);
149 declared_marks.insert(mark_type);
152 /** @ingroup TRACE_mark
153 * @brief Declare a new colored value for a previously declared mark type.
155 * This function declares a new colored value for a Paje event type in the trace file that can be used by simulators to
156 * declare application-level marks. This function is independent of which API is used in SimGrid. The color needs to be
157 * a string with three numbers separated by spaces in the range [0,1].
158 * 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
159 * be white ("1 1 1").
161 * @param mark_type The name of the new type.
162 * @param mark_value The name of the new value for this type.
163 * @param mark_color The color of the new value for this type.
167 void TRACE_declare_mark_value_with_color (const char *mark_type, const char *mark_value, const char *mark_color)
169 /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
170 if (not TRACE_is_enabled() || not TRACE_needs_platform())
173 xbt_assert(mark_type, "mark_type is nullptr");
174 xbt_assert(mark_value, "mark_value is nullptr");
176 simgrid::instr::EventType* type =
177 static_cast<simgrid::instr::EventType*>(simgrid::instr::Container::get_root()->type_->by_name(mark_type));
179 THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
182 mark_color = "1.0 1.0 1.0" /*white*/;
184 XBT_DEBUG("MARK,declare_value %s %s %s", mark_type, mark_value, mark_color);
185 type->add_entity_value(mark_value, mark_color);
189 /** @ingroup TRACE_mark
190 * @brief Declare a new value for a previously declared mark type.
192 * This function declares a new value for a Paje event type in the trace file that can be used by simulators to declare
193 * application-level marks. This function is independent of which API is used in SimGrid. Calling this function is the
194 * same as calling @ref TRACE_declare_mark_value_with_color with a nullptr color.
196 * @param mark_type The name of the new type.
197 * @param mark_value The name of the new value for this type.
201 void TRACE_declare_mark_value (const char *mark_type, const char *mark_value)
203 TRACE_declare_mark_value_with_color (mark_type, mark_value, nullptr);
207 * @ingroup TRACE_mark
208 * @brief Create a new instance of a tracing mark type.
210 * This function creates a mark in the trace file. The first parameter had to be previously declared using
211 * #TRACE_declare_mark, the second is the identifier for this mark instance. We recommend that the mark_value is a
212 * unique value for the whole simulation. Nevertheless, this is not a strong requirement: the trace will be valid even
213 * if there are multiple mark identifiers for the same trace.
215 * @param mark_type The name of the type for which the new instance will belong.
216 * @param mark_value The name of the new instance mark.
218 * @see TRACE_declare_mark
220 void TRACE_mark(const char *mark_type, const char *mark_value)
222 /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
223 if (not TRACE_is_enabled() || not TRACE_needs_platform())
226 xbt_assert(mark_type, "mark_type is nullptr");
227 xbt_assert(mark_value, "mark_value is nullptr");
229 //check if mark_type is already declared
230 simgrid::instr::EventType* type =
231 static_cast<simgrid::instr::EventType*>(simgrid::instr::Container::get_root()->type_->by_name(mark_type));
233 THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
235 XBT_DEBUG("MARK %s %s", mark_type, mark_value);
236 new simgrid::instr::NewEvent(MSG_get_clock(), simgrid::instr::Container::get_root(), type,
237 type->get_entity_value(mark_value));
241 /** @ingroup TRACE_mark
242 * @brief Get declared marks
244 * This function should be used to get marks that were already declared with #TRACE_declare_mark.
246 * @return A dynar with the declared marks, must be freed with xbt_dynar_free.
248 xbt_dynar_t TRACE_get_marks ()
250 if (not TRACE_is_enabled())
253 return instr_set_to_dynar(&declared_marks);
256 static void instr_user_variable(double time, const char* resource, const char* variable_name, const char* father_type,
257 double value, InstrUserVariable what, const char* color, std::set<std::string>* filter)
259 /* safe switches. tracing has to be activated and if platform is not traced, we don't allow user variables */
260 if (not TRACE_is_enabled() || not TRACE_needs_platform())
263 //check if variable is already declared
264 auto created = filter->find(variable_name);
265 if (what == InstrUserVariable::DECLARE) {
266 if (created == filter->end()) { // not declared yet
267 filter->insert(variable_name);
268 instr_new_user_variable_type(father_type, variable_name, color == nullptr ? "" : color);
271 if (created != filter->end()) { // declared, let's work
272 simgrid::instr::VariableType* variable =
273 simgrid::instr::Container::by_name(resource)->get_variable(variable_name);
275 case InstrUserVariable::SET:
276 variable->set_event(time, value);
278 case InstrUserVariable::ADD:
279 variable->add_event(time, value);
281 case InstrUserVariable::SUB:
282 variable->sub_event(time, value);
292 static void instr_user_srcdst_variable(double time, const char *src, const char *dst, const char *variable,
293 const char *father_type, double value, InstrUserVariable what)
295 simgrid::kernel::routing::NetPoint* src_elm = sg_netpoint_by_name_or_null(src);
297 xbt_die("Element '%s' not found!",src);
299 simgrid::kernel::routing::NetPoint* dst_elm = sg_netpoint_by_name_or_null(dst);
301 xbt_die("Element '%s' not found!",dst);
303 std::vector<simgrid::kernel::resource::LinkImpl*> route;
304 simgrid::kernel::routing::NetZoneImpl::get_global_route(src_elm, dst_elm, route, nullptr);
305 for (auto const& link : route)
306 instr_user_variable(time, link->get_cname(), variable, father_type, value, what, nullptr, &user_link_variables);
309 /** @ingroup TRACE_API
310 * @brief Creates a file with the topology of the platform file used for the simulator.
312 * The graph topology will have the following properties: all hosts, links and routers of the platform file are mapped
313 * to graph nodes; routes are mapped to edges.
314 * The platform's AS are not represented in the output.
316 * @param filename The name of the file that will hold the graph.
318 * @return 1 of successful, 0 otherwise.
320 int TRACE_platform_graph_export_graphviz (const char *filename)
322 /* returns 1 if successful, 0 otherwise */
323 if (not TRACE_is_enabled())
325 xbt_graph_t g = instr_routing_platform_graph();
328 instr_routing_platform_graph_export_graphviz (g, filename);
329 xbt_graph_free_graph(g, xbt_free_f, xbt_free_f, nullptr);
334 * Derived functions that use instr_user_variable and TRACE_user_srcdst_variable. They were previously defined as
335 * pre-processors directives, but were transformed into functions so the user can track them using gdb.
338 /* for VM variables */
339 /** @ingroup TRACE_user_variables
340 * @brief Declare a new user variable associated to VMs.
342 * Declare a user variable that will be associated to VMs. A user vm variable can be used to trace user variables
343 * such as the number of tasks in a VM, the number of clients in an application (for VMs), and so on. The color
344 * associated to this new variable will be random.
346 * @param variable The name of the new variable to be declared.
348 * @see TRACE_vm_variable_declare_with_color
350 void TRACE_vm_variable_declare (const char *variable)
352 instr_user_variable(0, nullptr, variable, "VM", 0, InstrUserVariable::DECLARE, nullptr, &user_vm_variables);
355 /** @ingroup TRACE_user_variables
356 * @brief Declare a new user variable associated to VMs with a color.
358 * Same as #TRACE_vm_variable_declare, but associated a color to the newly created user host variable. The color needs
359 * to be a string with three numbers separated by spaces in the range [0,1].
360 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
362 * @param variable The name of the new variable to be declared.
363 * @param color The color for the new variable.
365 void TRACE_vm_variable_declare_with_color (const char *variable, const char *color)
367 instr_user_variable(0, nullptr, variable, "VM", 0, InstrUserVariable::DECLARE, color, &user_vm_variables);
370 /** @ingroup TRACE_user_variables
371 * @brief Set the value of a variable of a host.
373 * @param vm The name of the VM to be considered.
374 * @param variable The name of the variable to be considered.
375 * @param value The new value of the variable.
377 * @see TRACE_vm_variable_declare, TRACE_vm_variable_add, TRACE_vm_variable_sub
379 void TRACE_vm_variable_set (const char *vm, const char *variable, double value)
381 TRACE_vm_variable_set_with_time (MSG_get_clock(), vm, variable, value);
384 /** @ingroup TRACE_user_variables
385 * @brief Add a value to a variable of a VM.
387 * @param vm The name of the VM to be considered.
388 * @param variable The name of the variable to be considered.
389 * @param value The value to be added to the variable.
391 * @see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_sub
393 void TRACE_vm_variable_add (const char *vm, const char *variable, double value)
395 TRACE_vm_variable_add_with_time (MSG_get_clock(), vm, variable, value);
398 /** @ingroup TRACE_user_variables
399 * @brief Subtract a value from a variable of a VM.
401 * @param vm The name of the vm to be considered.
402 * @param variable The name of the variable to be considered.
403 * @param value The value to be subtracted from the variable.
405 * @see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_add
407 void TRACE_vm_variable_sub (const char *vm, const char *variable, double value)
409 TRACE_vm_variable_sub_with_time (MSG_get_clock(), vm, variable, value);
412 /** @ingroup TRACE_user_variables
413 * @brief Set the value of a variable of a VM at a given timestamp.
415 * Same as #TRACE_vm_variable_set, but let user specify the time used to trace it. Users can specify a time that
416 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
417 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
420 * @param time The timestamp to be used to tag this change of value.
421 * @param vm The name of the VM to be considered.
422 * @param variable The name of the variable to be considered.
423 * @param value The new value of the variable.
425 * @see TRACE_vm_variable_declare, TRACE_vm_variable_add_with_time, TRACE_vm_variable_sub_with_time
427 void TRACE_vm_variable_set_with_time (double time, const char *vm, const char *variable, double value)
429 instr_user_variable(time, vm, variable, "VM", value, InstrUserVariable::SET, nullptr, &user_vm_variables);
432 /** @ingroup TRACE_user_variables
433 * @brief Add a value to a variable of a VM at a given timestamp.
435 * Same as #TRACE_vm_variable_add, but let user specify the time used to trace it. Users can specify a time that
436 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
437 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
440 * @param time The timestamp to be used to tag this change of value.
441 * @param vm The name of the VM to be considered.
442 * @param variable The name of the variable to be considered.
443 * @param value The value to be added to the variable.
445 * @see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_sub_with_time
447 void TRACE_vm_variable_add_with_time (double time, const char *vm, const char *variable, double value)
449 instr_user_variable(time, vm, variable, "VM", value, InstrUserVariable::ADD, nullptr, &user_vm_variables);
452 /** @ingroup TRACE_user_variables
453 * @brief Subtract a value from a variable of a VM at a given timestamp.
455 * Same as #TRACE_vm_variable_sub, but let user specify the time used to trace it. Users can specify a time that
456 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
457 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
460 * @param time The timestamp to be used to tag this change of value.
461 * @param vm The name of the VM to be considered.
462 * @param variable The name of the variable to be considered.
463 * @param value The value to be subtracted from the variable.
465 * @see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_add_with_time
467 void TRACE_vm_variable_sub_with_time (double time, const char *vm, const char *variable, double value)
469 instr_user_variable(time, vm, variable, "VM", value, InstrUserVariable::SUB, nullptr, &user_vm_variables);
472 /* for host variables */
473 /** @ingroup TRACE_user_variables
474 * @brief Declare a new user variable associated to hosts.
476 * Declare a user variable that will be associated to hosts.
477 * A user host variable can be used to trace user variables such as the number of tasks in a server, the number of
478 * clients in an application (for hosts), and so on. The color associated to this new variable will be random.
480 * @param variable The name of the new variable to be declared.
482 * @see TRACE_host_variable_declare_with_color
484 void TRACE_host_variable_declare (const char *variable)
486 instr_user_variable(0, nullptr, variable, "HOST", 0, InstrUserVariable::DECLARE, nullptr, &user_host_variables);
489 /** @ingroup TRACE_user_variables
490 * @brief Declare a new user variable associated to hosts with a color.
492 * Same as #TRACE_host_variable_declare, but associated a color to the newly created user host variable. The color
493 * needs to be a string with three numbers separated by spaces in the range [0,1].
494 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
496 * @param variable The name of the new variable to be declared.
497 * @param color The color for the new variable.
499 void TRACE_host_variable_declare_with_color (const char *variable, const char *color)
501 instr_user_variable(0, nullptr, variable, "HOST", 0, InstrUserVariable::DECLARE, color, &user_host_variables);
504 /** @ingroup TRACE_user_variables
505 * @brief Set the value of a variable of a host.
507 * @param host The name of the host to be considered.
508 * @param variable The name of the variable to be considered.
509 * @param value The new value of the variable.
511 * @see TRACE_host_variable_declare, TRACE_host_variable_add, TRACE_host_variable_sub
513 void TRACE_host_variable_set (const char *host, const char *variable, double value)
515 TRACE_host_variable_set_with_time (MSG_get_clock(), host, variable, value);
518 /** @ingroup TRACE_user_variables
519 * @brief Add a value to a variable of a host.
521 * @param host The name of the host to be considered.
522 * @param variable The name of the variable to be considered.
523 * @param value The value to be added to the variable.
525 * @see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_sub
527 void TRACE_host_variable_add (const char *host, const char *variable, double value)
529 TRACE_host_variable_add_with_time (MSG_get_clock(), host, variable, value);
532 /** @ingroup TRACE_user_variables
533 * @brief Subtract a value from a variable of a host.
535 * @param host The name of the host to be considered.
536 * @param variable The name of the variable to be considered.
537 * @param value The value to be subtracted from the variable.
539 * @see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_add
541 void TRACE_host_variable_sub (const char *host, const char *variable, double value)
543 TRACE_host_variable_sub_with_time (MSG_get_clock(), host, variable, value);
546 /** @ingroup TRACE_user_variables
547 * @brief Set the value of a variable of a host at a given timestamp.
549 * Same as #TRACE_host_variable_set, but let user specify the time used to trace it. Users can specify a time that
550 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
551 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
554 * @param time The timestamp to be used to tag this change of value.
555 * @param host The name of the host to be considered.
556 * @param variable The name of the variable to be considered.
557 * @param value The new value of the variable.
559 * @see TRACE_host_variable_declare, TRACE_host_variable_add_with_time, TRACE_host_variable_sub_with_time
561 void TRACE_host_variable_set_with_time (double time, const char *host, const char *variable, double value)
563 instr_user_variable(time, host, variable, "HOST", value, InstrUserVariable::SET, nullptr, &user_host_variables);
566 /** @ingroup TRACE_user_variables
567 * @brief Add a value to a variable of a host at a given timestamp.
569 * Same as #TRACE_host_variable_add, but let user specify the time used to trace it. Users can specify a time that
570 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
571 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
574 * @param time The timestamp to be used to tag this change of value.
575 * @param host The name of the host to be considered.
576 * @param variable The name of the variable to be considered.
577 * @param value The value to be added to the variable.
579 * @see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_sub_with_time
581 void TRACE_host_variable_add_with_time (double time, const char *host, const char *variable, double value)
583 instr_user_variable(time, host, variable, "HOST", value, InstrUserVariable::ADD, nullptr, &user_host_variables);
586 /** @ingroup TRACE_user_variables
587 * @brief Subtract a value from a variable of a host at a given timestamp.
589 * Same as #TRACE_host_variable_sub, but let user specify the time used to trace it. Users can specify a time that
590 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
591 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
594 * @param time The timestamp to be used to tag this change of value.
595 * @param host The name of the host to be considered.
596 * @param variable The name of the variable to be considered.
597 * @param value The value to be subtracted from the variable.
599 * @see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_add_with_time
601 void TRACE_host_variable_sub_with_time (double time, const char *host, const char *variable, double value)
603 instr_user_variable(time, host, variable, "HOST", value, InstrUserVariable::SUB, nullptr, &user_host_variables);
606 /** @ingroup TRACE_user_variables
607 * @brief Get declared user host variables
609 * This function should be used to get host variables that were already declared with #TRACE_host_variable_declare or
610 * with #TRACE_host_variable_declare_with_color.
612 * @return A dynar with the declared host variables, must be freed with xbt_dynar_free.
614 xbt_dynar_t TRACE_get_host_variables ()
616 return instr_set_to_dynar(&user_host_variables);
619 /* for link variables */
620 /** @ingroup TRACE_user_variables
621 * @brief Declare a new user variable associated to links.
623 * Declare a user variable that will be associated to links.
624 * A user link variable can be used, for example, to trace user variables such as the number of messages being
625 * transferred through network links. The color associated to this new variable will be random.
627 * @param variable The name of the new variable to be declared.
629 * @see TRACE_link_variable_declare_with_color
631 void TRACE_link_variable_declare (const char *variable)
633 instr_user_variable(0, nullptr, variable, "LINK", 0, InstrUserVariable::DECLARE, nullptr, &user_link_variables);
636 /** @ingroup TRACE_user_variables
637 * @brief Declare a new user variable associated to links with a color.
639 * Same as #TRACE_link_variable_declare, but associated a color to the newly created user link variable. The color
640 * needs to be a string with three numbers separated by spaces in the range [0,1].
641 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
643 * @param variable The name of the new variable to be declared.
644 * @param color The color for the new variable.
646 void TRACE_link_variable_declare_with_color (const char *variable, const char *color)
648 instr_user_variable(0, nullptr, variable, "LINK", 0, InstrUserVariable::DECLARE, color, &user_link_variables);
651 /** @ingroup TRACE_user_variables
652 * @brief Set the value of a variable of a link.
654 * @param link The name of the link to be considered.
655 * @param variable The name of the variable to be considered.
656 * @param value The new value of the variable.
658 * @see TRACE_link_variable_declare, TRACE_link_variable_add, TRACE_link_variable_sub
660 void TRACE_link_variable_set (const char *link, const char *variable, double value)
662 TRACE_link_variable_set_with_time (MSG_get_clock(), link, variable, value);
665 /** @ingroup TRACE_user_variables
666 * @brief Add a value to a variable of a link.
668 * @param link The name of the link to be considered.
669 * @param variable The name of the variable to be considered.
670 * @param value The value to be added to the variable.
672 * @see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_sub
674 void TRACE_link_variable_add (const char *link, const char *variable, double value)
676 TRACE_link_variable_add_with_time (MSG_get_clock(), link, variable, value);
679 /** @ingroup TRACE_user_variables
680 * @brief Subtract a value from a variable of a link.
682 * @param link The name of the link to be considered.
683 * @param variable The name of the variable to be considered.
684 * @param value The value to be subtracted from the variable.
686 * @see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_add
688 void TRACE_link_variable_sub (const char *link, const char *variable, double value)
690 TRACE_link_variable_sub_with_time (MSG_get_clock(), link, variable, value);
693 /** @ingroup TRACE_user_variables
694 * @brief Set the value of a variable of a link at a given timestamp.
696 * Same as #TRACE_link_variable_set, but let user specify the time used to trace it. Users can specify a time that
697 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
698 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
701 * @param time The timestamp to be used to tag this change of value.
702 * @param link The name of the link to be considered.
703 * @param variable The name of the variable to be considered.
704 * @param value The new value of the variable.
706 * @see TRACE_link_variable_declare, TRACE_link_variable_add_with_time, TRACE_link_variable_sub_with_time
708 void TRACE_link_variable_set_with_time (double time, const char *link, const char *variable, double value)
710 instr_user_variable(time, link, variable, "LINK", value, InstrUserVariable::SET, nullptr, &user_link_variables);
713 /** @ingroup TRACE_user_variables
714 * @brief Add a value to a variable of a link at a given timestamp.
716 * Same as #TRACE_link_variable_add, but let user specify the time used to trace it. Users can specify a time that
717 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
718 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
721 * @param time The timestamp to be used to tag this change of value.
722 * @param link The name of the link to be considered.
723 * @param variable The name of the variable to be considered.
724 * @param value The value to be added to the variable.
726 * @see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_sub_with_time
728 void TRACE_link_variable_add_with_time (double time, const char *link, const char *variable, double value)
730 instr_user_variable(time, link, variable, "LINK", value, InstrUserVariable::ADD, nullptr, &user_link_variables);
733 /** @ingroup TRACE_user_variables
734 * @brief Subtract a value from a variable of a link at a given timestamp.
736 * Same as #TRACE_link_variable_sub, but let user specify the time used to trace it. Users can specify a time that
737 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
738 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
741 * @param time The timestamp to be used to tag this change of value.
742 * @param link The name of the link to be considered.
743 * @param variable The name of the variable to be considered.
744 * @param value The value to be subtracted from the variable.
746 * @see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_add_with_time
748 void TRACE_link_variable_sub_with_time (double time, const char *link, const char *variable, double value)
750 instr_user_variable(time, link, variable, "LINK", value, InstrUserVariable::SUB, nullptr, &user_link_variables);
753 /* for link variables, but with src and dst used for get_route */
754 /** @ingroup TRACE_user_variables
755 * @brief Set the value of the variable present in the links connecting source and destination.
757 * Same as #TRACE_link_variable_set, but instead of providing the name of link to be considered, provide the source
758 * and destination hosts. All links that are part of the route between source and destination will have the variable
759 * set to the provided value.
761 * @param src The name of the source host for get route.
762 * @param dst The name of the destination host for get route.
763 * @param variable The name of the variable to be considered.
764 * @param value The new value of the variable.
766 * @see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add, TRACE_link_srcdst_variable_sub
768 void TRACE_link_srcdst_variable_set (const char *src, const char *dst, const char *variable, double value)
770 TRACE_link_srcdst_variable_set_with_time (MSG_get_clock(), src, dst, variable, value);
773 /** @ingroup TRACE_user_variables
774 * @brief Add a value to the variable present in the links connecting source and destination.
776 * Same as #TRACE_link_variable_add, but instead of providing the name of link to be considered, provide the source
777 * and destination hosts. All links that are part of the route between source and destination will have the value
778 * passed as parameter added to the current value of the variable name to be considered.
780 * @param src The name of the source host for get route.
781 * @param dst The name of the destination host for get route.
782 * @param variable The name of the variable to be considered.
783 * @param value The value to be added to the variable.
785 * @see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_sub
787 void TRACE_link_srcdst_variable_add (const char *src, const char *dst, const char *variable, double value)
789 TRACE_link_srcdst_variable_add_with_time (MSG_get_clock(), src, dst, variable, value);
792 /** @ingroup TRACE_user_variables
793 * @brief Subtract a value from the variable present in the links connecting source and destination.
795 * Same as #TRACE_link_variable_sub, but instead of providing the name of link to be considered, provide the source
796 * and destination hosts. All links that are part of the route between source and destination will have the value
797 * passed as parameter subtracted from the current value of the variable name to be considered.
799 * @param src The name of the source host for get route.
800 * @param dst The name of the destination host for get route.
801 * @param variable The name of the variable to be considered.
802 * @param value The value to be subtracted from the variable.
804 * @see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_add
806 void TRACE_link_srcdst_variable_sub (const char *src, const char *dst, const char *variable, double value)
808 TRACE_link_srcdst_variable_sub_with_time (MSG_get_clock(), src, dst, variable, value);
811 /** @ingroup TRACE_user_variables
812 * @brief Set the value of the variable present in the links connecting source and destination at a given timestamp.
814 * Same as #TRACE_link_srcdst_variable_set, but let user specify the time used to trace it. Users can specify a time
815 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
816 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
819 * @param time The timestamp to be used to tag this change of value.
820 * @param src The name of the source host for get route.
821 * @param dst The name of the destination host for get route.
822 * @param variable The name of the variable to be considered.
823 * @param value The new value of the variable.
825 * @see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add_with_time, TRACE_link_srcdst_variable_sub_with_time
827 void TRACE_link_srcdst_variable_set_with_time (double time, const char *src, const char *dst, const char *variable,
830 instr_user_srcdst_variable(time, src, dst, variable, "LINK", value, InstrUserVariable::SET);
833 /** @ingroup TRACE_user_variables
834 * @brief Add a value to the variable present in the links connecting source and destination at a given timestamp.
836 * Same as #TRACE_link_srcdst_variable_add, but let user specify the time used to trace it. Users can specify a time
837 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
838 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
841 * @param time The timestamp to be used to tag this change of value.
842 * @param src The name of the source host for get route.
843 * @param dst The name of the destination host for get route.
844 * @param variable The name of the variable to be considered.
845 * @param value The value to be added to the variable.
847 * @see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_sub_with_time
849 void TRACE_link_srcdst_variable_add_with_time (double time, const char *src, const char *dst, const char *variable,
852 instr_user_srcdst_variable(time, src, dst, variable, "LINK", value, InstrUserVariable::ADD);
855 /** @ingroup TRACE_user_variables
856 * @brief Subtract a value from the variable present in the links connecting source and dest. at a given timestamp.
858 * Same as #TRACE_link_srcdst_variable_sub, but let user specify the time used to trace it. Users can specify a time
859 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
860 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
863 * @param time The timestamp to be used to tag this change of value.
864 * @param src The name of the source host for get route.
865 * @param dst The name of the destination host for get route.
866 * @param variable The name of the variable to be considered.
867 * @param value The value to be subtracted from the variable.
869 * @see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_add_with_time
871 void TRACE_link_srcdst_variable_sub_with_time (double time, const char *src, const char *dst, const char *variable,
874 instr_user_srcdst_variable(time, src, dst, variable, "LINK", value, InstrUserVariable::SUB);
877 /** @ingroup TRACE_user_variables
878 * @brief Get declared user link variables
880 * This function should be used to get link variables that were already declared with #TRACE_link_variable_declare or
881 * with #TRACE_link_variable_declare_with_color.
883 * @return A dynar with the declared link variables, must be freed with xbt_dynar_free.
885 xbt_dynar_t TRACE_get_link_variables ()
887 return instr_set_to_dynar(&user_link_variables);
890 /** @ingroup TRACE_user_variables
891 * @brief Declare a new user state associated to hosts.
893 * Declare a user state that will be associated to hosts.
894 * A user host state can be used to trace application states.
896 * @param state The name of the new state to be declared.
898 * @see TRACE_host_state_declare_value
900 void TRACE_host_state_declare (const char *state)
902 instr_new_user_state_type("HOST", state);
905 /** @ingroup TRACE_user_variables
906 * @brief Declare a new value for a user state associated to hosts.
908 * Declare a value for a state. The color needs to be a string with 3 numbers separated by spaces in the range [0,1].
909 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
911 * @param state The name of the new state to be declared.
912 * @param value The name of the value
913 * @param color The color of the value
915 * @see TRACE_host_state_declare
917 void TRACE_host_state_declare_value (const char *state, const char *value, const char *color)
919 instr_new_value_for_user_state_type (state, value, color);
922 /** @ingroup TRACE_user_variables
923 * @brief Set the user state to the given value.
925 * Change a user state previously declared to the given value.
927 * @param host The name of the host to be considered.
928 * @param state_name The name of the state previously declared.
929 * @param value_name The new value of the state.
931 * @see TRACE_host_state_declare, TRACE_host_push_state, TRACE_host_pop_state, TRACE_host_reset_state
933 void TRACE_host_set_state(const char* host, const char* state_name, const char* value_name)
935 simgrid::instr::StateType* state = simgrid::instr::Container::by_name(host)->get_state(state_name);
936 state->add_entity_value(value_name);
937 state->set_event(value_name);
940 /** @ingroup TRACE_user_variables
941 * @brief Push a new value for a state of a given host.
943 * Change a user state previously declared by pushing the new value to the state.
945 * @param host The name of the host to be considered.
946 * @param state_name The name of the state previously declared.
947 * @param value_name The value to be pushed.
949 * @see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_pop_state, TRACE_host_reset_state
951 void TRACE_host_push_state(const char* host, const char* state_name, const char* value_name)
953 simgrid::instr::Container::by_name(host)->get_state(state_name)->push_event(value_name);
956 /** @ingroup TRACE_user_variables
957 * @brief Pop the last value of a state of a given host.
959 * Change a user state previously declared by removing the last value of the state.
961 * @param host The name of the host to be considered.
962 * @param state_name The name of the state to be popped.
964 * @see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_reset_state
966 void TRACE_host_pop_state(const char* host, const char* state_name)
968 simgrid::instr::Container::by_name(host)->get_state(state_name)->pop_event();
971 /** @ingroup TRACE_API
972 * @brief Get Paje container types that can be mapped to the nodes of a graph.
974 * This function can be used to create a user made graph configuration file for Triva. Normally, it is used with the
975 * functions defined in @ref TRACE_user_variables.
977 * @return A dynar with the types, must be freed with xbt_dynar_free.
979 xbt_dynar_t TRACE_get_node_types ()
981 return instr_set_to_dynar(&trivaNodeTypes);
984 /** @ingroup TRACE_API
985 * @brief Get Paje container types that can be mapped to the edges of a graph.
987 * This function can be used to create a user made graph configuration file for Triva. Normally, it is used with the
988 * functions defined in @ref TRACE_user_variables.
990 * @return A dynar with the types, must be freed with xbt_dynar_free.
992 xbt_dynar_t TRACE_get_edge_types ()
994 return instr_set_to_dynar(&trivaEdgeTypes);