1 /* Copyright (c) 2010-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "simgrid_config.h"
8 #include "src/instr/instr_private.h"
9 #include "src/kernel/routing/NetPoint.hpp"
10 #include "src/surf/network_interface.hpp"
11 #include "src/surf/surf_private.h"
12 #include "surf/surf.h"
22 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API");
24 std::set<std::string> simgrid::instr::created_categories;
25 std::set<std::string> simgrid::instr::declared_marks;
26 std::set<std::string> simgrid::instr::user_host_variables;
27 std::set<std::string> simgrid::instr::user_vm_variables;
28 std::set<std::string> simgrid::instr::user_link_variables;
29 extern std::set<std::string> trivaNodeTypes;
30 extern std::set<std::string> trivaEdgeTypes;
32 static xbt_dynar_t instr_set_to_dynar(std::set<std::string>* filter)
34 if (not TRACE_is_enabled() || not TRACE_needs_platform())
37 xbt_dynar_t ret = xbt_dynar_new (sizeof(char*), &xbt_free_ref);
38 for (auto const& name : *filter)
39 xbt_dynar_push_as(ret, char*, xbt_strdup(name.c_str()));
44 /** \ingroup TRACE_category
45 * \brief Declare a new category with a random color.
47 * This function should be used to define a user category. The category can be used to differentiate the tasks that
48 * are created during the simulation (for example, tasks from server1, server2, or request tasks, computation tasks,
49 * communication tasks). All resource utilization (host power and link bandwidth) will be classified according to the
50 * task category. Tasks that do not belong to a category are not traced. The color for the category that is being
51 * declared is random. This function has no effect if a category with the same name has been already declared.
53 * See \ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
55 * \param category The name of the new tracing category to be created.
57 * \see TRACE_category_with_color, MSG_task_set_category, SD_task_set_category
59 void TRACE_category(const char *category)
61 TRACE_category_with_color (category, nullptr);
64 /** \ingroup TRACE_category
65 * \brief Declare a new category with a color.
67 * Same as #TRACE_category, but let user specify a color encoded as a RGB-like string with three floats from 0 to 1.
68 * So, to specify a red color, pass "1 0 0" as color parameter. A light-gray color can be specified using "0.7 0.7 0.7"
69 * as color. This function has no effect if a category with the same name has been already declared.
71 * See \ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
73 * \param category The name of the new tracing category to be created.
74 * \param color The color of the category (see \ref outcomes_vizu to
75 * know how to correctly specify the color)
77 * \see MSG_task_set_category, SD_task_set_category
79 void TRACE_category_with_color (const char *category, const char *color)
81 /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with categories */
82 if (not TRACE_is_enabled() || not TRACE_needs_platform())
85 if (not(TRACE_categorized() && category != nullptr))
88 //check if category is already created
89 if (simgrid::instr::created_categories.find(category) != simgrid::instr::created_categories.end())
92 simgrid::instr::created_categories.insert(category);
95 char final_color[INSTR_DEFAULT_STR_SIZE];
97 //generate a random color
98 double red = drand48();
99 double green = drand48();
100 double blue = drand48();
101 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%f %f %f", red, green, blue);
103 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
106 XBT_DEBUG("CAT,declare %s, \"%s\" \"%s\"", category, color, final_color);
108 //define the type of this category on top of hosts and links
109 instr_new_variable_type (category, final_color);
112 /** \ingroup TRACE_category
113 * \brief Get declared categories
115 * This function should be used to get categories that were already declared with #TRACE_category or with
116 * #TRACE_category_with_color.
118 * See \ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
120 * \return A dynar with the declared categories, must be freed with xbt_dynar_free.
122 * \see MSG_task_set_category, SD_task_set_category
124 xbt_dynar_t TRACE_get_categories ()
126 if (not TRACE_is_enabled() || not TRACE_categorized())
128 return instr_set_to_dynar(&simgrid::instr::created_categories);
131 /** \ingroup TRACE_mark
132 * \brief Declare a new type for tracing mark.
134 * This function declares a new Paje event type in the trace file that can be used by simulators to declare
135 * application-level marks. This function is independent of which API is used in SimGrid.
137 * \param mark_type The name of the new type.
141 void TRACE_declare_mark(const char *mark_type)
143 /* safe switchs. tracing has to be activated and if platform is not traced, we can't deal with marks */
144 if (not TRACE_is_enabled() || not TRACE_needs_platform())
148 THROWF (tracing_error, 1, "mark_type is nullptr");
150 //check if mark_type is already declared
151 if (simgrid::instr::declared_marks.find(mark_type) != simgrid::instr::declared_marks.end()) {
152 THROWF (tracing_error, 1, "mark_type with name (%s) is already declared", mark_type);
155 XBT_DEBUG("MARK,declare %s", mark_type);
156 simgrid::instr::Type::eventNew(mark_type, PJ_type_get_root());
157 simgrid::instr::declared_marks.insert(mark_type);
160 /** \ingroup TRACE_mark
161 * \brief Declare a new colored value for a previously declared mark type.
163 * This function declares a new colored value for a Paje event type in the trace file that can be used by simulators to
164 * declare application-level marks. This function is independent of which API is used in SimGrid. The color needs to be
165 * a string with three numbers separated by spaces in the range [0,1].
166 * A light-gray color can be specified using "0.7 0.7 0.7" as color. If a nullptr color is provided, the color used will
167 * be white ("1 1 1").
169 * \param mark_type The name of the new type.
170 * \param mark_value The name of the new value for this type.
171 * \param mark_color The color of the new value for this type.
175 void TRACE_declare_mark_value_with_color (const char *mark_type, const char *mark_value, const char *mark_color)
177 /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
178 if (not TRACE_is_enabled() || not TRACE_needs_platform())
182 THROWF (tracing_error, 1, "mark_type is nullptr");
184 THROWF (tracing_error, 1, "mark_value is nullptr");
186 simgrid::instr::Type* type = PJ_type_get(mark_type, PJ_type_get_root());
188 THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
191 char white[INSTR_DEFAULT_STR_SIZE] = "1.0 1.0 1.0";
195 XBT_DEBUG("MARK,declare_value %s %s %s", mark_type, mark_value, mark_color);
196 simgrid::instr::Value rett(mark_value, mark_color, type);
199 /** \ingroup TRACE_mark
200 * \brief Declare a new value for a previously declared mark type.
202 * This function declares a new value for a Paje event type in the trace file that can be used by simulators to declare
203 * application-level marks. This function is independent of which API is used in SimGrid. Calling this function is the
204 * same as calling \ref TRACE_declare_mark_value_with_color with a nullptr color.
206 * \param mark_type The name of the new type.
207 * \param mark_value The name of the new value for this type.
211 void TRACE_declare_mark_value (const char *mark_type, const char *mark_value)
213 TRACE_declare_mark_value_with_color (mark_type, mark_value, nullptr);
217 * \ingroup TRACE_mark
218 * \brief Create a new instance of a tracing mark type.
220 * This function creates a mark in the trace file. The first parameter had to be previously declared using
221 * #TRACE_declare_mark, the second is the identifier for this mark instance. We recommend that the mark_value is a
222 * unique value for the whole simulation. Nevertheless, this is not a strong requirement: the trace will be valid even
223 * if there are multiple mark identifiers for the same trace.
225 * \param mark_type The name of the type for which the new instance will belong.
226 * \param mark_value The name of the new instance mark.
228 * \see TRACE_declare_mark
230 void TRACE_mark(const char *mark_type, const char *mark_value)
232 /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
233 if (not TRACE_is_enabled() || not TRACE_needs_platform())
237 THROWF (tracing_error, 1, "mark_type is nullptr");
239 THROWF (tracing_error, 1, "mark_value is nullptr");
241 //check if mark_type is already declared
242 simgrid::instr::Type* type = PJ_type_get(mark_type, PJ_type_get_root());
244 THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
247 XBT_DEBUG("MARK %s %s", mark_type, mark_value);
248 new simgrid::instr::NewEvent(MSG_get_clock(), PJ_container_get_root(), type,
249 simgrid::instr::Value::get(mark_value, type));
252 /** \ingroup TRACE_mark
253 * \brief Get declared marks
255 * This function should be used to get marks that were already declared with #TRACE_declare_mark.
257 * \return A dynar with the declared marks, must be freed with xbt_dynar_free.
259 xbt_dynar_t TRACE_get_marks ()
261 if (not TRACE_is_enabled())
264 return instr_set_to_dynar(&simgrid::instr::declared_marks);
267 static void instr_user_variable(double time, const char* resource, const char* variable, const char* father_type,
268 double value, InstrUserVariable what, const char* color, std::set<std::string>* filter)
270 /* safe switches. tracing has to be activated and if platform is not traced, we don't allow user variables */
271 if (not TRACE_is_enabled() || not TRACE_needs_platform())
274 //check if variable is already declared
275 auto created = filter->find(variable);
276 if (what == INSTR_US_DECLARE){
277 if (created == filter->end()) { // not declared yet
278 filter->insert(variable);
279 instr_new_user_variable_type (father_type, variable, color);
282 if (created != filter->end()) { // declared, let's work
284 snprintf(valuestr, 100, "%g", value);
285 container_t container = PJ_container_get(resource);
286 simgrid::instr::Type* type = PJ_type_get(variable, container->type);
289 new simgrid::instr::SetVariableEvent(time, container, type, value);
292 new simgrid::instr::AddVariableEvent(time, container, type, value);
295 new simgrid::instr::SubVariableEvent(time, container, type, value);
305 static void instr_user_srcdst_variable(double time, const char *src, const char *dst, const char *variable,
306 const char *father_type, double value, InstrUserVariable what)
308 sg_netpoint_t src_elm = sg_netpoint_by_name_or_null(src);
310 xbt_die("Element '%s' not found!",src);
312 sg_netpoint_t dst_elm = sg_netpoint_by_name_or_null(dst);
314 xbt_die("Element '%s' not found!",dst);
316 std::vector<simgrid::surf::LinkImpl*> route;
317 simgrid::kernel::routing::NetZoneImpl::getGlobalRoute(src_elm, dst_elm, &route, nullptr);
318 for (auto const& link : route)
319 instr_user_variable(time, link->cname(), variable, father_type, value, what, nullptr,
320 &simgrid::instr::user_link_variables);
323 /** \ingroup TRACE_API
324 * \brief Creates a file with the topology of the platform file used for the simulator.
326 * The graph topology will have the following properties: all hosts, links and routers of the platform file are mapped
327 * to graph nodes; routes are mapped to edges.
328 * The platform's AS are not represented in the output.
330 * \param filename The name of the file that will hold the graph.
332 * \return 1 of successful, 0 otherwise.
334 int TRACE_platform_graph_export_graphviz (const char *filename)
336 /* returns 1 if successful, 0 otherwise */
337 if (not TRACE_is_enabled())
339 xbt_graph_t g = instr_routing_platform_graph();
342 instr_routing_platform_graph_export_graphviz (g, filename);
343 xbt_graph_free_graph(g, xbt_free_f, xbt_free_f, nullptr);
348 * Derived functions that use instr_user_variable and TRACE_user_srcdst_variable. They were previously defined as
349 * pre-processors directives, but were transformed into functions so the user can track them using gdb.
352 /* for VM variables */
353 /** \ingroup TRACE_user_variables
354 * \brief Declare a new user variable associated to VMs.
356 * Declare a user variable that will be associated to VMs. A user vm variable can be used to trace user variables
357 * such as the number of tasks in a VM, the number of clients in an application (for VMs), and so on. The color
358 * associated to this new variable will be random.
360 * \param variable The name of the new variable to be declared.
362 * \see TRACE_vm_variable_declare_with_color
364 void TRACE_vm_variable_declare (const char *variable)
366 instr_user_variable(0, nullptr, variable, "MSG_VM", 0, INSTR_US_DECLARE, nullptr, &simgrid::instr::user_vm_variables);
369 /** \ingroup TRACE_user_variables
370 * \brief Declare a new user variable associated to VMs with a color.
372 * Same as #TRACE_vm_variable_declare, but associated a color to the newly created user host variable. The color needs
373 * to be a string with three numbers separated by spaces in the range [0,1].
374 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
376 * \param variable The name of the new variable to be declared.
377 * \param color The color for the new variable.
379 void TRACE_vm_variable_declare_with_color (const char *variable, const char *color)
381 instr_user_variable(0, nullptr, variable, "MSG_VM", 0, INSTR_US_DECLARE, color, &simgrid::instr::user_vm_variables);
384 /** \ingroup TRACE_user_variables
385 * \brief Set the value of a variable of a host.
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 new value of the variable.
391 * \see TRACE_vm_variable_declare, TRACE_vm_variable_add, TRACE_vm_variable_sub
393 void TRACE_vm_variable_set (const char *vm, const char *variable, double value)
395 TRACE_vm_variable_set_with_time (MSG_get_clock(), vm, variable, value);
398 /** \ingroup TRACE_user_variables
399 * \brief Add a value to 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 added to the variable.
405 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_sub
407 void TRACE_vm_variable_add (const char *vm, const char *variable, double value)
409 TRACE_vm_variable_add_with_time (MSG_get_clock(), vm, variable, value);
412 /** \ingroup TRACE_user_variables
413 * \brief Subtract a value from a variable of a VM.
415 * \param vm The name of the vm to be considered.
416 * \param variable The name of the variable to be considered.
417 * \param value The value to be subtracted from the variable.
419 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_add
421 void TRACE_vm_variable_sub (const char *vm, const char *variable, double value)
423 TRACE_vm_variable_sub_with_time (MSG_get_clock(), vm, variable, value);
426 /** \ingroup TRACE_user_variables
427 * \brief Set the value of a variable of a VM at a given timestamp.
429 * Same as #TRACE_vm_variable_set, but let user specify the time used to trace it. Users can specify a time that
430 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
431 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
434 * \param time The timestamp to be used to tag this change of value.
435 * \param vm The name of the VM to be considered.
436 * \param variable The name of the variable to be considered.
437 * \param value The new value of the variable.
439 * \see TRACE_vm_variable_declare, TRACE_vm_variable_add_with_time, TRACE_vm_variable_sub_with_time
441 void TRACE_vm_variable_set_with_time (double time, const char *vm, const char *variable, double value)
443 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_SET, nullptr, &simgrid::instr::user_vm_variables);
446 /** \ingroup TRACE_user_variables
447 * \brief Add a value to a variable of a VM at a given timestamp.
449 * Same as #TRACE_vm_variable_add, but let user specify the time used to trace it. Users can specify a time that
450 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
451 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
454 * \param time The timestamp to be used to tag this change of value.
455 * \param vm The name of the VM to be considered.
456 * \param variable The name of the variable to be considered.
457 * \param value The value to be added to the variable.
459 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_sub_with_time
461 void TRACE_vm_variable_add_with_time (double time, const char *vm, const char *variable, double value)
463 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_ADD, nullptr, &simgrid::instr::user_vm_variables);
466 /** \ingroup TRACE_user_variables
467 * \brief Subtract a value from a variable of a VM at a given timestamp.
469 * Same as #TRACE_vm_variable_sub, but let user specify the time used to trace it. Users can specify a time that
470 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
471 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
474 * \param time The timestamp to be used to tag this change of value.
475 * \param vm The name of the VM to be considered.
476 * \param variable The name of the variable to be considered.
477 * \param value The value to be subtracted from the variable.
479 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_add_with_time
481 void TRACE_vm_variable_sub_with_time (double time, const char *vm, const char *variable, double value)
483 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_SUB, nullptr, &simgrid::instr::user_vm_variables);
486 /* for host variables */
487 /** \ingroup TRACE_user_variables
488 * \brief Declare a new user variable associated to hosts.
490 * Declare a user variable that will be associated to hosts.
491 * A user host variable can be used to trace user variables such as the number of tasks in a server, the number of
492 * clients in an application (for hosts), and so on. The color associated to this new variable will be random.
494 * \param variable The name of the new variable to be declared.
496 * \see TRACE_host_variable_declare_with_color
498 void TRACE_host_variable_declare (const char *variable)
500 instr_user_variable(0, nullptr, variable, "HOST", 0, INSTR_US_DECLARE, nullptr, &simgrid::instr::user_host_variables);
503 /** \ingroup TRACE_user_variables
504 * \brief Declare a new user variable associated to hosts with a color.
506 * Same as #TRACE_host_variable_declare, but associated a color to the newly created user host variable. The color
507 * needs to be a string with three numbers separated by spaces in the range [0,1].
508 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
510 * \param variable The name of the new variable to be declared.
511 * \param color The color for the new variable.
513 void TRACE_host_variable_declare_with_color (const char *variable, const char *color)
515 instr_user_variable(0, nullptr, variable, "HOST", 0, INSTR_US_DECLARE, color, &simgrid::instr::user_host_variables);
518 /** \ingroup TRACE_user_variables
519 * \brief Set the value of 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 new value of the variable.
525 * \see TRACE_host_variable_declare, TRACE_host_variable_add, TRACE_host_variable_sub
527 void TRACE_host_variable_set (const char *host, const char *variable, double value)
529 TRACE_host_variable_set_with_time (MSG_get_clock(), host, variable, value);
532 /** \ingroup TRACE_user_variables
533 * \brief Add a value to 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 added to the variable.
539 * \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_sub
541 void TRACE_host_variable_add (const char *host, const char *variable, double value)
543 TRACE_host_variable_add_with_time (MSG_get_clock(), host, variable, value);
546 /** \ingroup TRACE_user_variables
547 * \brief Subtract a value from a variable of a host.
549 * \param host The name of the host to be considered.
550 * \param variable The name of the variable to be considered.
551 * \param value The value to be subtracted from the variable.
553 * \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_add
555 void TRACE_host_variable_sub (const char *host, const char *variable, double value)
557 TRACE_host_variable_sub_with_time (MSG_get_clock(), host, variable, value);
560 /** \ingroup TRACE_user_variables
561 * \brief Set the value of a variable of a host at a given timestamp.
563 * Same as #TRACE_host_variable_set, but let user specify the time used to trace it. Users can specify a time that
564 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
565 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
568 * \param time The timestamp to be used to tag this change of value.
569 * \param host The name of the host to be considered.
570 * \param variable The name of the variable to be considered.
571 * \param value The new value of the variable.
573 * \see TRACE_host_variable_declare, TRACE_host_variable_add_with_time, TRACE_host_variable_sub_with_time
575 void TRACE_host_variable_set_with_time (double time, const char *host, const char *variable, double value)
577 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SET, nullptr, &simgrid::instr::user_host_variables);
580 /** \ingroup TRACE_user_variables
581 * \brief Add a value to a variable of a host at a given timestamp.
583 * Same as #TRACE_host_variable_add, but let user specify the time used to trace it. Users can specify a time that
584 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
585 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
588 * \param time The timestamp to be used to tag this change of value.
589 * \param host The name of the host to be considered.
590 * \param variable The name of the variable to be considered.
591 * \param value The value to be added to the variable.
593 * \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_sub_with_time
595 void TRACE_host_variable_add_with_time (double time, const char *host, const char *variable, double value)
597 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_ADD, nullptr, &simgrid::instr::user_host_variables);
600 /** \ingroup TRACE_user_variables
601 * \brief Subtract a value from a variable of a host at a given timestamp.
603 * Same as #TRACE_host_variable_sub, but let user specify the time used to trace it. Users can specify a time that
604 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
605 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
608 * \param time The timestamp to be used to tag this change of value.
609 * \param host The name of the host to be considered.
610 * \param variable The name of the variable to be considered.
611 * \param value The value to be subtracted from the variable.
613 * \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_add_with_time
615 void TRACE_host_variable_sub_with_time (double time, const char *host, const char *variable, double value)
617 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SUB, nullptr, &simgrid::instr::user_host_variables);
620 /** \ingroup TRACE_user_variables
621 * \brief Get declared user host variables
623 * This function should be used to get host variables that were already declared with #TRACE_host_variable_declare or
624 * with #TRACE_host_variable_declare_with_color.
626 * \return A dynar with the declared host variables, must be freed with xbt_dynar_free.
628 xbt_dynar_t TRACE_get_host_variables ()
630 return instr_set_to_dynar(&simgrid::instr::user_host_variables);
633 /* for link variables */
634 /** \ingroup TRACE_user_variables
635 * \brief Declare a new user variable associated to links.
637 * Declare a user variable that will be associated to links.
638 * A user link variable can be used, for example, to trace user variables such as the number of messages being
639 * transferred through network links. The color associated to this new variable will be random.
641 * \param variable The name of the new variable to be declared.
643 * \see TRACE_link_variable_declare_with_color
645 void TRACE_link_variable_declare (const char *variable)
647 instr_user_variable(0, nullptr, variable, "LINK", 0, INSTR_US_DECLARE, nullptr, &simgrid::instr::user_link_variables);
650 /** \ingroup TRACE_user_variables
651 * \brief Declare a new user variable associated to links with a color.
653 * Same as #TRACE_link_variable_declare, but associated a color to the newly created user link variable. The color
654 * needs to be a string with three numbers separated by spaces in the range [0,1].
655 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
657 * \param variable The name of the new variable to be declared.
658 * \param color The color for the new variable.
660 void TRACE_link_variable_declare_with_color (const char *variable, const char *color)
662 instr_user_variable(0, nullptr, variable, "LINK", 0, INSTR_US_DECLARE, color, &simgrid::instr::user_link_variables);
665 /** \ingroup TRACE_user_variables
666 * \brief Set the value of 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 new value of the variable.
672 * \see TRACE_link_variable_declare, TRACE_link_variable_add, TRACE_link_variable_sub
674 void TRACE_link_variable_set (const char *link, const char *variable, double value)
676 TRACE_link_variable_set_with_time (MSG_get_clock(), link, variable, value);
679 /** \ingroup TRACE_user_variables
680 * \brief Add a value to 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 added to the variable.
686 * \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_sub
688 void TRACE_link_variable_add (const char *link, const char *variable, double value)
690 TRACE_link_variable_add_with_time (MSG_get_clock(), link, variable, value);
693 /** \ingroup TRACE_user_variables
694 * \brief Subtract a value from a variable of a link.
696 * \param link The name of the link to be considered.
697 * \param variable The name of the variable to be considered.
698 * \param value The value to be subtracted from the variable.
700 * \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_add
702 void TRACE_link_variable_sub (const char *link, const char *variable, double value)
704 TRACE_link_variable_sub_with_time (MSG_get_clock(), link, variable, value);
707 /** \ingroup TRACE_user_variables
708 * \brief Set the value of a variable of a link at a given timestamp.
710 * Same as #TRACE_link_variable_set, but let user specify the time used to trace it. Users can specify a time that
711 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
712 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
715 * \param time The timestamp to be used to tag this change of value.
716 * \param link The name of the link to be considered.
717 * \param variable The name of the variable to be considered.
718 * \param value The new value of the variable.
720 * \see TRACE_link_variable_declare, TRACE_link_variable_add_with_time, TRACE_link_variable_sub_with_time
722 void TRACE_link_variable_set_with_time (double time, const char *link, const char *variable, double value)
724 instr_user_variable(time, link, variable, "LINK", value, INSTR_US_SET, nullptr, &simgrid::instr::user_link_variables);
727 /** \ingroup TRACE_user_variables
728 * \brief Add a value to a variable of a link at a given timestamp.
730 * Same as #TRACE_link_variable_add, but let user specify the time used to trace it. Users can specify a time that
731 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
732 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
735 * \param time The timestamp to be used to tag this change of value.
736 * \param link The name of the link to be considered.
737 * \param variable The name of the variable to be considered.
738 * \param value The value to be added to the variable.
740 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_sub_with_time
742 void TRACE_link_variable_add_with_time (double time, const char *link, const char *variable, double value)
744 instr_user_variable(time, link, variable, "LINK", value, INSTR_US_ADD, nullptr, &simgrid::instr::user_link_variables);
747 /** \ingroup TRACE_user_variables
748 * \brief Subtract a value from a variable of a link at a given timestamp.
750 * Same as #TRACE_link_variable_sub, but let user specify the time used to trace it. Users can specify a time that
751 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
752 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
755 * \param time The timestamp to be used to tag this change of value.
756 * \param link The name of the link to be considered.
757 * \param variable The name of the variable to be considered.
758 * \param value The value to be subtracted from the variable.
760 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_add_with_time
762 void TRACE_link_variable_sub_with_time (double time, const char *link, const char *variable, double value)
764 instr_user_variable(time, link, variable, "LINK", value, INSTR_US_SUB, nullptr, &simgrid::instr::user_link_variables);
767 /* for link variables, but with src and dst used for get_route */
768 /** \ingroup TRACE_user_variables
769 * \brief Set the value of the variable present in the links connecting source and destination.
771 * Same as #TRACE_link_variable_set, but instead of providing the name of link to be considered, provide the source
772 * and destination hosts. All links that are part of the route between source and destination will have the variable
773 * set to the provided value.
775 * \param src The name of the source host for get route.
776 * \param dst The name of the destination host for get route.
777 * \param variable The name of the variable to be considered.
778 * \param value The new value of the variable.
780 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add, TRACE_link_srcdst_variable_sub
782 void TRACE_link_srcdst_variable_set (const char *src, const char *dst, const char *variable, double value)
784 TRACE_link_srcdst_variable_set_with_time (MSG_get_clock(), src, dst, variable, value);
787 /** \ingroup TRACE_user_variables
788 * \brief Add a value to the variable present in the links connecting source and destination.
790 * Same as #TRACE_link_variable_add, but instead of providing the name of link to be considered, provide the source
791 * and destination hosts. All links that are part of the route between source and destination will have the value
792 * passed as parameter added to the current value of the variable name to be considered.
794 * \param src The name of the source host for get route.
795 * \param dst The name of the destination host for get route.
796 * \param variable The name of the variable to be considered.
797 * \param value The value to be added to the variable.
799 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_sub
801 void TRACE_link_srcdst_variable_add (const char *src, const char *dst, const char *variable, double value)
803 TRACE_link_srcdst_variable_add_with_time (MSG_get_clock(), src, dst, variable, value);
806 /** \ingroup TRACE_user_variables
807 * \brief Subtract a value from the variable present in the links connecting source and destination.
809 * Same as #TRACE_link_variable_sub, but instead of providing the name of link to be considered, provide the source
810 * and destination hosts. All links that are part of the route between source and destination will have the value
811 * passed as parameter subtracted from the current value of the variable name to be considered.
813 * \param src The name of the source host for get route.
814 * \param dst The name of the destination host for get route.
815 * \param variable The name of the variable to be considered.
816 * \param value The value to be subtracted from the variable.
818 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_add
820 void TRACE_link_srcdst_variable_sub (const char *src, const char *dst, const char *variable, double value)
822 TRACE_link_srcdst_variable_sub_with_time (MSG_get_clock(), src, dst, variable, value);
825 /** \ingroup TRACE_user_variables
826 * \brief Set the value of the variable present in the links connecting source and destination at a given timestamp.
828 * Same as #TRACE_link_srcdst_variable_set, but let user specify the time used to trace it. Users can specify a time
829 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
830 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
833 * \param time The timestamp to be used to tag this change of value.
834 * \param src The name of the source host for get route.
835 * \param dst The name of the destination host for get route.
836 * \param variable The name of the variable to be considered.
837 * \param value The new value of the variable.
839 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add_with_time, TRACE_link_srcdst_variable_sub_with_time
841 void TRACE_link_srcdst_variable_set_with_time (double time, const char *src, const char *dst, const char *variable,
844 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SET);
847 /** \ingroup TRACE_user_variables
848 * \brief Add a value to the variable present in the links connecting source and destination at a given timestamp.
850 * Same as #TRACE_link_srcdst_variable_add, but let user specify the time used to trace it. Users can specify a time
851 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
852 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
855 * \param time The timestamp to be used to tag this change of value.
856 * \param src The name of the source host for get route.
857 * \param dst The name of the destination host for get route.
858 * \param variable The name of the variable to be considered.
859 * \param value The value to be added to the variable.
861 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_sub_with_time
863 void TRACE_link_srcdst_variable_add_with_time (double time, const char *src, const char *dst, const char *variable,
866 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_ADD);
869 /** \ingroup TRACE_user_variables
870 * \brief Subtract a value from the variable present in the links connecting source and dest. at a given timestamp.
872 * Same as #TRACE_link_srcdst_variable_sub, but let user specify the time used to trace it. Users can specify a time
873 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
874 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
877 * \param time The timestamp to be used to tag this change of value.
878 * \param src The name of the source host for get route.
879 * \param dst The name of the destination host for get route.
880 * \param variable The name of the variable to be considered.
881 * \param value The value to be subtracted from the variable.
883 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_add_with_time
885 void TRACE_link_srcdst_variable_sub_with_time (double time, const char *src, const char *dst, const char *variable,
888 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SUB);
891 /** \ingroup TRACE_user_variables
892 * \brief Get declared user link variables
894 * This function should be used to get link variables that were already declared with #TRACE_link_variable_declare or
895 * with #TRACE_link_variable_declare_with_color.
897 * \return A dynar with the declared link variables, must be freed with xbt_dynar_free.
899 xbt_dynar_t TRACE_get_link_variables ()
901 return instr_set_to_dynar(&simgrid::instr::user_link_variables);
904 /** \ingroup TRACE_user_variables
905 * \brief Declare a new user state associated to hosts.
907 * Declare a user state that will be associated to hosts.
908 * A user host state can be used to trace application states.
910 * \param state The name of the new state to be declared.
912 * \see TRACE_host_state_declare_value
914 void TRACE_host_state_declare (const char *state)
916 instr_new_user_state_type("HOST", state);
919 /** \ingroup TRACE_user_variables
920 * \brief Declare a new value for a user state associated to hosts.
922 * Declare a value for a state. The color needs to be a string with 3 numbers separated by spaces in the range [0,1].
923 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
925 * \param state The name of the new state to be declared.
926 * \param value The name of the value
927 * \param color The color of the value
929 * \see TRACE_host_state_declare
931 void TRACE_host_state_declare_value (const char *state, const char *value, const char *color)
933 instr_new_value_for_user_state_type (state, value, color);
936 /** \ingroup TRACE_user_variables
937 * \brief Set the user state to the given value.
939 * Change a user state previously declared to the given value.
941 * \param host The name of the host to be considered.
942 * \param state The name of the state previously declared.
943 * \param value The new value of the state.
945 * \see TRACE_host_state_declare, TRACE_host_push_state, TRACE_host_pop_state, TRACE_host_reset_state
947 void TRACE_host_set_state(const char* host, const char* state, const char* value_str)
949 container_t container = PJ_container_get(host);
950 simgrid::instr::Type* type = PJ_type_get(state, container->type);
951 simgrid::instr::Value* val = simgrid::instr::Value::get_or_new(
952 value_str, nullptr, type); /* if user didn't declare a value with a color, use nullptr color */
953 new simgrid::instr::SetStateEvent(MSG_get_clock(), container, type, val);
956 /** \ingroup TRACE_user_variables
957 * \brief Push a new value for a state of a given host.
959 * Change a user state previously declared by pushing the new value to the state.
961 * \param host The name of the host to be considered.
962 * \param state The name of the state previously declared.
963 * \param value The value to be pushed.
965 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_pop_state, TRACE_host_reset_state
967 void TRACE_host_push_state(const char* host, const char* state, const char* value_str)
969 container_t container = PJ_container_get(host);
970 simgrid::instr::Type* type = PJ_type_get(state, container->type);
971 simgrid::instr::Value* val = simgrid::instr::Value::get_or_new(
972 value_str, nullptr, type); /* if user didn't declare a value with a color, use nullptr color */
973 new simgrid::instr::PushStateEvent(MSG_get_clock(), container, type, val);
976 /** \ingroup TRACE_user_variables
977 * \brief Pop the last value of a state of a given host.
979 * Change a user state previously declared by removing the last value of the state.
981 * \param host The name of the host to be considered.
982 * \param state The name of the state to be popped.
984 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_reset_state
986 void TRACE_host_pop_state (const char *host, const char *state)
988 container_t container = PJ_container_get(host);
989 simgrid::instr::Type* type = PJ_type_get(state, container->type);
990 new simgrid::instr::PopStateEvent(MSG_get_clock(), container, type);
993 /** \ingroup TRACE_API
994 * \brief Get Paje container types that can be mapped to the nodes of a graph.
996 * This function can be used to create a user made graph configuration file for Triva. Normally, it is used with the
997 * functions defined in \ref TRACE_user_variables.
999 * \return A dynar with the types, must be freed with xbt_dynar_free.
1001 xbt_dynar_t TRACE_get_node_types ()
1003 return instr_set_to_dynar(&trivaNodeTypes);
1006 /** \ingroup TRACE_API
1007 * \brief Get Paje container types that can be mapped to the edges of a graph.
1009 * This function can be used to create a user made graph configuration file for Triva. Normally, it is used with the
1010 * functions defined in \ref TRACE_user_variables.
1012 * \return A dynar with the types, must be freed with xbt_dynar_free.
1014 xbt_dynar_t TRACE_get_edge_types ()
1016 return instr_set_to_dynar(&trivaEdgeTypes);