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/surf/network_interface.hpp"
9 #include "src/instr/instr_private.h"
10 #include "surf/surf.h"
11 #include "src/surf/surf_private.h"
20 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API");
22 xbt_dict_t created_categories = NULL;
23 xbt_dict_t declared_marks = NULL;
24 xbt_dict_t user_host_variables = NULL;
25 xbt_dict_t user_vm_variables = NULL;
26 xbt_dict_t user_link_variables = NULL;
27 extern xbt_dict_t trivaNodeTypes;
28 extern xbt_dict_t trivaEdgeTypes;
30 static xbt_dynar_t instr_dict_to_dynar (xbt_dict_t filter)
32 if (!TRACE_is_enabled()) return NULL;
33 if (!TRACE_needs_platform()) return NULL;
35 xbt_dynar_t ret = xbt_dynar_new (sizeof(char*), &xbt_free_ref);
36 xbt_dict_cursor_t cursor = NULL;
38 xbt_dict_foreach(filter, cursor, name, value) {
39 xbt_dynar_push_as (ret, char*, xbt_strdup(name));
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 tracing 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, NULL);
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 tracing 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 tracing 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)
82 if (!TRACE_is_enabled()) return;
84 if (!(TRACE_categorized() && category != NULL)) return;
86 /* if platform is not traced, we can't deal with categories */
87 if (!TRACE_needs_platform()) return;
89 //check if category is already created
90 char *created = (char*)xbt_dict_get_or_null(created_categories, category);
92 xbt_dict_set (created_categories, category, xbt_strdup("1"), NULL);
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 tracing 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 (void)
126 if (!TRACE_is_enabled()) return NULL;
127 if (!TRACE_categorized()) return NULL;
129 return instr_dict_to_dynar (created_categories);
132 /** \ingroup TRACE_mark
133 * \brief Declare a new type for tracing mark.
135 * This function declares a new Paje event type in the trace file that can be used by simulators to declare
136 * application-level marks. This function is independent of which API is used in SimGrid.
138 * \param mark_type The name of the new type.
142 void TRACE_declare_mark(const char *mark_type)
145 if (!TRACE_is_enabled()) return;
147 /* if platform is not traced, we don't allow marks */
148 if (!TRACE_needs_platform()) return;
150 if (!mark_type) THROWF (tracing_error, 1, "mark_type is NULL");
152 //check if mark_type is already declared
153 char *created = (char*)xbt_dict_get_or_null(declared_marks, mark_type);
155 THROWF (tracing_error, 1, "mark_type with name (%s) is already declared", mark_type);
158 XBT_DEBUG("MARK,declare %s", mark_type);
159 PJ_type_event_new(mark_type, PJ_type_get_root());
160 xbt_dict_set (declared_marks, mark_type, xbt_strdup("1"), NULL);
163 /** \ingroup TRACE_mark
164 * \brief Declare a new colored value for a previously declared mark type.
166 * This function declares a new colored value for a Paje event type in the trace file that can be used by simulators to
167 * declare application-level marks. This function is independent of which API is used in SimGrid. The color needs to be
168 * a string with three numbers separated by spaces in the range [0,1].
169 * A light-gray color can be specified using "0.7 0.7 0.7" as color. If a NULL color is provided, the color used will
170 * be white ("1 1 1").
172 * \param mark_type The name of the new type.
173 * \param mark_value The name of the new value for this type.
174 * \param mark_color The color of the new value for this type.
178 void TRACE_declare_mark_value_with_color (const char *mark_type, const char *mark_value, const char *mark_color)
181 if (!TRACE_is_enabled()) return;
183 /* if platform is not traced, we don't allow marks */
184 if (!TRACE_needs_platform()) return;
186 if (!mark_type) THROWF (tracing_error, 1, "mark_type is NULL");
187 if (!mark_value) THROWF (tracing_error, 1, "mark_value is NULL");
189 type_t type = PJ_type_get (mark_type, PJ_type_get_root());
191 THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
194 char white[INSTR_DEFAULT_STR_SIZE] = "1.0 1.0 1.0";
195 if (!mark_color) mark_color = white;
197 XBT_DEBUG("MARK,declare_value %s %s %s", mark_type, mark_value, mark_color);
198 PJ_value_new (mark_value, mark_color, type);
201 /** \ingroup TRACE_mark
202 * \brief Declare a new value for a previously declared mark type.
204 * This function declares a new value for a Paje event type in the trace file that can be used by simulators to declare
205 * application-level marks. This function is independent of which API is used in SimGrid. Calling this function is the
206 * same as calling \ref TRACE_declare_mark_value_with_color with a NULL color.
208 * \param mark_type The name of the new type.
209 * \param mark_value The name of the new value for this type.
213 void TRACE_declare_mark_value (const char *mark_type, const char *mark_value)
215 TRACE_declare_mark_value_with_color (mark_type, mark_value, NULL);
219 * \ingroup TRACE_mark
220 * \brief Create a new instance of a tracing mark type.
222 * This function creates a mark in the trace file. The first parameter had to be previously declared using
223 * #TRACE_declare_mark, the second is the identifier for this mark instance. We recommend that the mark_value is a
224 * unique value for the whole simulation. Nevertheless, this is not a strong requirement: the trace will be valid even
225 * if there are multiple mark identifiers for the same trace.
227 * \param mark_type The name of the type for which the new instance will belong.
228 * \param mark_value The name of the new instance mark.
230 * \see TRACE_declare_mark
232 void TRACE_mark(const char *mark_type, const char *mark_value)
235 if (!TRACE_is_enabled()) return;
237 /* if platform is not traced, we don't allow marks */
238 if (!TRACE_needs_platform()) return;
240 if (!mark_type) THROWF (tracing_error, 1, "mark_type is NULL");
241 if (!mark_value) THROWF (tracing_error, 1, "mark_value is NULL");
243 //check if mark_type is already declared
244 type_t type = PJ_type_get (mark_type, PJ_type_get_root());
246 THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
249 val_t value = PJ_value_get (mark_value, type);
250 XBT_DEBUG("MARK %s %s", mark_type, mark_value);
251 new_pajeNewEvent (MSG_get_clock(), PJ_container_get_root(), type, value);
254 /** \ingroup TRACE_mark
255 * \brief Get declared marks
257 * This function should be used to get marks that were already declared with #TRACE_declare_mark.
259 * \return A dynar with the declared marks, must be freed with xbt_dynar_free.
261 xbt_dynar_t TRACE_get_marks (void)
263 if (!TRACE_is_enabled()) return NULL;
265 return instr_dict_to_dynar (declared_marks);
268 static void instr_user_variable(double time, const char *resource, const char *variable, const char *father_type,
269 double value, InstrUserVariable what, const char *color, xbt_dict_t filter)
272 if (!TRACE_is_enabled()) return;
274 /* if platform is not traced, we don't allow user variables */
275 if (!TRACE_needs_platform()) return;
277 //check if variable is already declared
278 char *created = (char*)xbt_dict_get_or_null(filter, variable);
279 if (what == INSTR_US_DECLARE){
280 if (created){//already declared
283 xbt_dict_set (filter, variable, xbt_strdup("1"), NULL);
286 if (!created){//not declared, ignore
292 snprintf(valuestr, 100, "%g", value);
295 case INSTR_US_DECLARE:
296 instr_new_user_variable_type (father_type, variable, color);
300 container_t container = PJ_container_get(resource);
301 type_t type = PJ_type_get (variable, container->type);
302 new_pajeSetVariable(time, container, type, value);
307 container_t container = PJ_container_get(resource);
308 type_t type = PJ_type_get (variable, container->type);
309 new_pajeAddVariable(time, container, type, value);
314 container_t container = PJ_container_get(resource);
315 type_t type = PJ_type_get (variable, container->type);
316 new_pajeSubVariable(time, container, type, value);
320 //TODO: launch exception
325 static void instr_user_srcdst_variable(double time, const char *src, const char *dst, const char *variable,
326 const char *father_type, double value, InstrUserVariable what)
328 sg_netcard_t src_elm = sg_netcard_by_name_or_null(src);
329 if(!src_elm) xbt_die("Element '%s' not found!",src);
331 sg_netcard_t dst_elm = sg_netcard_by_name_or_null(dst);
332 if(!dst_elm) xbt_die("Element '%s' not found!",dst);
334 std::vector<Link*> *route = new std::vector<Link*>();
335 routing_platf->getRouteAndLatency (src_elm, dst_elm, route,NULL);
336 for (auto link : *route)
337 instr_user_variable (time, link->getName(), variable, father_type, value, what, NULL, user_link_variables);
341 /** \ingroup TRACE_API
342 * \brief Creates a file with the topology of the platform file used for the simulator.
344 * The graph topology will have the following properties: all hosts, links and routers of the platform file are mapped
345 * to graph nodes; routes are mapped to edges.
346 * The platform's AS are not represented in the output.
348 * \param filename The name of the file that will hold the graph.
350 * \return 1 of successful, 0 otherwise.
352 int TRACE_platform_graph_export_graphviz (const char *filename)
354 /* returns 1 if successful, 0 otherwise */
355 if (!TRACE_is_enabled()) return 0;
356 xbt_graph_t g = instr_routing_platform_graph();
357 if (g == NULL) return 0;
358 instr_routing_platform_graph_export_graphviz (g, filename);
359 xbt_graph_free_graph(g, xbt_free_f, xbt_free_f, NULL);
364 * Derived functions that use instr_user_variable and TRACE_user_srcdst_variable. They were previously defined as
365 * pre-processors directives, but were transformed into functions so the user can track them using gdb.
368 /* for VM variables */
369 /** \ingroup TRACE_user_variables
370 * \brief Declare a new user variable associated to VMs.
372 * Declare a user variable that will be associated to VMs. A user vm variable can be used to trace user variables
373 * such as the number of tasks in a VM, the number of clients in an application (for VMs), and so on. The color
374 * associated to this new variable will be random.
376 * \param variable The name of the new variable to be declared.
378 * \see TRACE_vm_variable_declare_with_color
380 void TRACE_vm_variable_declare (const char *variable)
382 instr_user_variable(0, NULL, variable, "MSG_VM", 0, INSTR_US_DECLARE, NULL, user_vm_variables);
385 /** \ingroup TRACE_user_variables
386 * \brief Declare a new user variable associated to VMs with a color.
388 * Same as #TRACE_vm_variable_declare, but associated a color to the newly created user host variable. The color needs
389 * to be a string with three numbers separated by spaces in the range [0,1].
390 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
392 * \param variable The name of the new variable to be declared.
393 * \param color The color for the new variable.
395 void TRACE_vm_variable_declare_with_color (const char *variable, const char *color)
397 instr_user_variable(0, NULL, variable, "MSG_VM", 0, INSTR_US_DECLARE, color, user_vm_variables);
400 /** \ingroup TRACE_user_variables
401 * \brief Set the value of a variable of a host.
403 * \param vm The name of the VM to be considered.
404 * \param variable The name of the variable to be considered.
405 * \param value The new value of the variable.
407 * \see TRACE_vm_variable_declare, TRACE_vm_variable_add, TRACE_vm_variable_sub
409 void TRACE_vm_variable_set (const char *vm, const char *variable, double value)
411 TRACE_vm_variable_set_with_time (MSG_get_clock(), vm, variable, value);
414 /** \ingroup TRACE_user_variables
415 * \brief Add a value to a variable of a VM.
417 * \param vm The name of the VM to be considered.
418 * \param variable The name of the variable to be considered.
419 * \param value The value to be added to the variable.
421 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_sub
423 void TRACE_vm_variable_add (const char *vm, const char *variable, double value)
425 TRACE_vm_variable_add_with_time (MSG_get_clock(), vm, variable, value);
428 /** \ingroup TRACE_user_variables
429 * \brief Subtract a value from a variable of a VM.
431 * \param vm The name of the vm to be considered.
432 * \param variable The name of the variable to be considered.
433 * \param value The value to be subtracted from the variable.
435 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_add
437 void TRACE_vm_variable_sub (const char *vm, const char *variable, double value)
439 TRACE_vm_variable_sub_with_time (MSG_get_clock(), vm, variable, value);
442 /** \ingroup TRACE_user_variables
443 * \brief Set the value of a variable of a VM at a given timestamp.
445 * Same as #TRACE_vm_variable_set, but let user specify the time used to trace it. Users can specify a time that
446 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
447 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
450 * \param time The timestamp to be used to tag this change of value.
451 * \param vm The name of the VM to be considered.
452 * \param variable The name of the variable to be considered.
453 * \param value The new value of the variable.
455 * \see TRACE_vm_variable_declare, TRACE_vm_variable_add_with_time, TRACE_vm_variable_sub_with_time
457 void TRACE_vm_variable_set_with_time (double time, const char *vm, const char *variable, double value)
459 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_SET, NULL, user_vm_variables);
462 /** \ingroup TRACE_user_variables
463 * \brief Add a value to a variable of a VM at a given timestamp.
465 * Same as #TRACE_vm_variable_add, but let user specify the time used to trace it. Users can specify a time that
466 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
467 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
470 * \param time The timestamp to be used to tag this change of value.
471 * \param vm The name of the VM to be considered.
472 * \param variable The name of the variable to be considered.
473 * \param value The value to be added to the variable.
475 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_sub_with_time
477 void TRACE_vm_variable_add_with_time (double time, const char *vm, const char *variable, double value)
479 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_ADD, NULL, user_vm_variables);
482 /** \ingroup TRACE_user_variables
483 * \brief Subtract a value from a variable of a VM at a given timestamp.
485 * Same as #TRACE_vm_variable_sub, but let user specify the time used to trace it. Users can specify a time that
486 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
487 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
490 * \param time The timestamp to be used to tag this change of value.
491 * \param vm The name of the VM to be considered.
492 * \param variable The name of the variable to be considered.
493 * \param value The value to be subtracted from the variable.
495 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_add_with_time
497 void TRACE_vm_variable_sub_with_time (double time, const char *vm, const char *variable, double value)
499 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_SUB, NULL, user_vm_variables);
502 /** \ingroup TRACE_user_variables
503 * \brief Get declared user vm variables
505 * This function should be used to get VM variables that were already declared with #TRACE_vm_variable_declare or with
506 * #TRACE_vm_variable_declare_with_color.
508 * \return A dynar with the declared host variables, must be freed with xbt_dynar_free.
510 xbt_dynar_t TRACE_get_vm_variables (void)
512 return instr_dict_to_dynar (user_vm_variables);
515 /* for host variables */
516 /** \ingroup TRACE_user_variables
517 * \brief Declare a new user variable associated to hosts.
519 * Declare a user variable that will be associated to hosts.
520 * A user host variable can be used to trace user variables such as the number of tasks in a server, the number of
521 * clients in an application (for hosts), and so on. The color associated to this new variable will be random.
523 * \param variable The name of the new variable to be declared.
525 * \see TRACE_host_variable_declare_with_color
527 void TRACE_host_variable_declare (const char *variable)
529 instr_user_variable(0, NULL, variable, "HOST", 0, INSTR_US_DECLARE, NULL, user_host_variables);
532 /** \ingroup TRACE_user_variables
533 * \brief Declare a new user variable associated to hosts with a color.
535 * Same as #TRACE_host_variable_declare, but associated a color to the newly created user host variable. The color
536 * needs to be a string with three numbers separated by spaces in the range [0,1].
537 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
539 * \param variable The name of the new variable to be declared.
540 * \param color The color for the new variable.
542 void TRACE_host_variable_declare_with_color (const char *variable, const char *color)
544 instr_user_variable(0, NULL, variable, "HOST", 0, INSTR_US_DECLARE, color, user_host_variables);
547 /** \ingroup TRACE_user_variables
548 * \brief Set the value of a variable of a host.
550 * \param host The name of the host to be considered.
551 * \param variable The name of the variable to be considered.
552 * \param value The new value of the variable.
554 * \see TRACE_host_variable_declare, TRACE_host_variable_add, TRACE_host_variable_sub
556 void TRACE_host_variable_set (const char *host, const char *variable, double value)
558 TRACE_host_variable_set_with_time (MSG_get_clock(), host, variable, value);
561 /** \ingroup TRACE_user_variables
562 * \brief Add a value to a variable of a host.
564 * \param host The name of the host to be considered.
565 * \param variable The name of the variable to be considered.
566 * \param value The value to be added to the variable.
568 * \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_sub
570 void TRACE_host_variable_add (const char *host, const char *variable, double value)
572 TRACE_host_variable_add_with_time (MSG_get_clock(), host, variable, value);
575 /** \ingroup TRACE_user_variables
576 * \brief Subtract a value from a variable of a host.
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 subtracted from the variable.
582 * \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_add
584 void TRACE_host_variable_sub (const char *host, const char *variable, double value)
586 TRACE_host_variable_sub_with_time (MSG_get_clock(), host, variable, value);
589 /** \ingroup TRACE_user_variables
590 * \brief Set the value of a variable of a host at a given timestamp.
592 * Same as #TRACE_host_variable_set, 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 new value of the variable.
602 * \see TRACE_host_variable_declare, TRACE_host_variable_add_with_time, TRACE_host_variable_sub_with_time
604 void TRACE_host_variable_set_with_time (double time, const char *host, const char *variable, double value)
606 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SET, NULL, user_host_variables);
609 /** \ingroup TRACE_user_variables
610 * \brief Add a value to a variable of a host at a given timestamp.
612 * Same as #TRACE_host_variable_add, but let user specify the time used to trace it. Users can specify a time that
613 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
614 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
617 * \param time The timestamp to be used to tag this change of value.
618 * \param host The name of the host to be considered.
619 * \param variable The name of the variable to be considered.
620 * \param value The value to be added to the variable.
622 * \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_sub_with_time
624 void TRACE_host_variable_add_with_time (double time, const char *host, const char *variable, double value)
626 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_ADD, NULL, user_host_variables);
629 /** \ingroup TRACE_user_variables
630 * \brief Subtract a value from a variable of a host at a given timestamp.
632 * Same as #TRACE_host_variable_sub, but let user specify the time used to trace it. Users can specify a time that
633 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
634 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
637 * \param time The timestamp to be used to tag this change of value.
638 * \param host The name of the host to be considered.
639 * \param variable The name of the variable to be considered.
640 * \param value The value to be subtracted from the variable.
642 * \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_add_with_time
644 void TRACE_host_variable_sub_with_time (double time, const char *host, const char *variable, double value)
646 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SUB, NULL, user_host_variables);
649 /** \ingroup TRACE_user_variables
650 * \brief Get declared user host variables
652 * This function should be used to get host variables that were already declared with #TRACE_host_variable_declare or
653 * with #TRACE_host_variable_declare_with_color.
655 * \return A dynar with the declared host variables, must be freed with xbt_dynar_free.
657 xbt_dynar_t TRACE_get_host_variables (void)
659 return instr_dict_to_dynar (user_host_variables);
662 /* for link variables */
663 /** \ingroup TRACE_user_variables
664 * \brief Declare a new user variable associated to links.
666 * Declare a user variable that will be associated to links.
667 * A user link variable can be used, for example, to trace user variables such as the number of messages being
668 * transferred through network links. The color associated to this new variable will be random.
670 * \param variable The name of the new variable to be declared.
672 * \see TRACE_link_variable_declare_with_color
674 void TRACE_link_variable_declare (const char *variable)
676 instr_user_variable (0, NULL, variable, "LINK", 0, INSTR_US_DECLARE, NULL, user_link_variables);
679 /** \ingroup TRACE_user_variables
680 * \brief Declare a new user variable associated to links with a color.
682 * Same as #TRACE_link_variable_declare, but associated a color to the newly created user link variable. The color
683 * needs to be a string with three numbers separated by spaces in the range [0,1].
684 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
686 * \param variable The name of the new variable to be declared.
687 * \param color The color for the new variable.
689 void TRACE_link_variable_declare_with_color (const char *variable, const char *color)
691 instr_user_variable (0, NULL, variable, "LINK", 0, INSTR_US_DECLARE, color, user_link_variables);
694 /** \ingroup TRACE_user_variables
695 * \brief Set the value of a variable of a link.
697 * \param link The name of the link to be considered.
698 * \param variable The name of the variable to be considered.
699 * \param value The new value of the variable.
701 * \see TRACE_link_variable_declare, TRACE_link_variable_add, TRACE_link_variable_sub
703 void TRACE_link_variable_set (const char *link, const char *variable, double value)
705 TRACE_link_variable_set_with_time (MSG_get_clock(), link, variable, value);
708 /** \ingroup TRACE_user_variables
709 * \brief Add a value to a variable of a link.
711 * \param link The name of the link to be considered.
712 * \param variable The name of the variable to be considered.
713 * \param value The value to be added to the variable.
715 * \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_sub
717 void TRACE_link_variable_add (const char *link, const char *variable, double value)
719 TRACE_link_variable_add_with_time (MSG_get_clock(), link, variable, value);
722 /** \ingroup TRACE_user_variables
723 * \brief Subtract a value from a variable of a link.
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 subtracted from the variable.
729 * \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_add
731 void TRACE_link_variable_sub (const char *link, const char *variable, double value)
733 TRACE_link_variable_sub_with_time (MSG_get_clock(), link, variable, value);
736 /** \ingroup TRACE_user_variables
737 * \brief Set the value of a variable of a link at a given timestamp.
739 * Same as #TRACE_link_variable_set, 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 new value of the variable.
749 * \see TRACE_link_variable_declare, TRACE_link_variable_add_with_time, TRACE_link_variable_sub_with_time
751 void TRACE_link_variable_set_with_time (double time, const char *link, const char *variable, double value)
753 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SET, NULL, user_link_variables);
756 /** \ingroup TRACE_user_variables
757 * \brief Add a value to a variable of a link at a given timestamp.
759 * Same as #TRACE_link_variable_add, but let user specify the time used to trace it. Users can specify a time that
760 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
761 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
764 * \param time The timestamp to be used to tag this change of value.
765 * \param link The name of the link to be considered.
766 * \param variable The name of the variable to be considered.
767 * \param value The value to be added to the variable.
769 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_sub_with_time
771 void TRACE_link_variable_add_with_time (double time, const char *link, const char *variable, double value)
773 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_ADD, NULL, user_link_variables);
776 /** \ingroup TRACE_user_variables
777 * \brief Subtract a value from a variable of a link at a given timestamp.
779 * Same as #TRACE_link_variable_sub, but let user specify the time used to trace it. Users can specify a time that
780 * is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
781 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
784 * \param time The timestamp to be used to tag this change of value.
785 * \param link The name of the link to be considered.
786 * \param variable The name of the variable to be considered.
787 * \param value The value to be subtracted from the variable.
789 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_add_with_time
791 void TRACE_link_variable_sub_with_time (double time, const char *link, const char *variable, double value)
793 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SUB, NULL, user_link_variables);
796 /* for link variables, but with src and dst used for get_route */
797 /** \ingroup TRACE_user_variables
798 * \brief Set the value of the variable present in the links connecting source and destination.
800 * Same as #TRACE_link_variable_set, but instead of providing the name of link to be considered, provide the source
801 * and destination hosts. All links that are part of the route between source and destination will have the variable
802 * set to the provided value.
804 * \param src The name of the source host for get route.
805 * \param dst The name of the destination host for get route.
806 * \param variable The name of the variable to be considered.
807 * \param value The new value of the variable.
809 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add, TRACE_link_srcdst_variable_sub
811 void TRACE_link_srcdst_variable_set (const char *src, const char *dst, const char *variable, double value)
813 TRACE_link_srcdst_variable_set_with_time (MSG_get_clock(), src, dst, variable, value);
816 /** \ingroup TRACE_user_variables
817 * \brief Add a value to the variable present in the links connecting source and destination.
819 * Same as #TRACE_link_variable_add, but instead of providing the name of link to be considered, provide the source
820 * and destination hosts. All links that are part of the route between source and destination will have the value
821 * passed as parameter added to the current value of the variable name to be considered.
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 value to be added to the variable.
828 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_sub
830 void TRACE_link_srcdst_variable_add (const char *src, const char *dst, const char *variable, double value)
832 TRACE_link_srcdst_variable_add_with_time (MSG_get_clock(), src, dst, variable, value);
835 /** \ingroup TRACE_user_variables
836 * \brief Subtract a value from the variable present in the links connecting source and destination.
838 * Same as #TRACE_link_variable_sub, but instead of providing the name of link to be considered, provide the source
839 * and destination hosts. All links that are part of the route between source and destination will have the value
840 * passed as parameter subtracted from the current value of the variable name to be considered.
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 subtracted from the variable.
847 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_add
849 void TRACE_link_srcdst_variable_sub (const char *src, const char *dst, const char *variable, double value)
851 TRACE_link_srcdst_variable_sub_with_time (MSG_get_clock(), src, dst, variable, value);
854 /** \ingroup TRACE_user_variables
855 * \brief Set the value of the variable present in the links connecting source and destination at a given timestamp.
857 * Same as #TRACE_link_srcdst_variable_set, but let user specify the time used to trace it. Users can specify a time
858 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
859 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
862 * \param time The timestamp to be used to tag this change of value.
863 * \param src The name of the source host for get route.
864 * \param dst The name of the destination host for get route.
865 * \param variable The name of the variable to be considered.
866 * \param value The new value of the variable.
868 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add_with_time, TRACE_link_srcdst_variable_sub_with_time
870 void TRACE_link_srcdst_variable_set_with_time (double time, const char *src, const char *dst, const char *variable,
873 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SET);
876 /** \ingroup TRACE_user_variables
877 * \brief Add a value to the variable present in the links connecting source and destination at a given timestamp.
879 * Same as #TRACE_link_srcdst_variable_add, but let user specify the time used to trace it. Users can specify a time
880 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
881 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
884 * \param time The timestamp to be used to tag this change of value.
885 * \param src The name of the source host for get route.
886 * \param dst The name of the destination host for get route.
887 * \param variable The name of the variable to be considered.
888 * \param value The value to be added to the variable.
890 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_sub_with_time
892 void TRACE_link_srcdst_variable_add_with_time (double time, const char *src, const char *dst, const char *variable,
895 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_ADD);
898 /** \ingroup TRACE_user_variables
899 * \brief Subtract a value from the variable present in the links connecting source and dest. at a given timestamp.
901 * Same as #TRACE_link_srcdst_variable_sub, but let user specify the time used to trace it. Users can specify a time
902 * that is not the simulated clock time as defined by the core simulator. This allows a fine-grain control of time
903 * definition, but should be used with caution since the trace can be inconsistent if resource utilization traces are
906 * \param time The timestamp to be used to tag this change of value.
907 * \param src The name of the source host for get route.
908 * \param dst The name of the destination host for get route.
909 * \param variable The name of the variable to be considered.
910 * \param value The value to be subtracted from the variable.
912 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_add_with_time
914 void TRACE_link_srcdst_variable_sub_with_time (double time, const char *src, const char *dst, const char *variable,
917 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SUB);
920 /** \ingroup TRACE_user_variables
921 * \brief Get declared user link variables
923 * This function should be used to get link variables that were already declared with #TRACE_link_variable_declare or
924 * with #TRACE_link_variable_declare_with_color.
926 * \return A dynar with the declared link variables, must be freed with xbt_dynar_free.
928 xbt_dynar_t TRACE_get_link_variables (void)
930 return instr_dict_to_dynar (user_link_variables);
933 /** \ingroup TRACE_user_variables
934 * \brief Declare a new user state associated to hosts.
936 * Declare a user state that will be associated to hosts.
937 * A user host state can be used to trace application states.
939 * \param state The name of the new state to be declared.
941 * \see TRACE_host_state_declare_value
943 void TRACE_host_state_declare (const char *state)
945 instr_new_user_state_type("HOST", state);
948 /** \ingroup TRACE_user_variables
949 * \brief Declare a new value for a user state associated to hosts.
951 * Declare a value for a state. The color needs to be a string with 3 numbers separated by spaces in the range [0,1].
952 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
954 * \param state The name of the new state to be declared.
955 * \param value The name of the value
956 * \param color The color of the value
958 * \see TRACE_host_state_declare
960 void TRACE_host_state_declare_value (const char *state, const char *value, const char *color)
962 instr_new_value_for_user_state_type (state, value, color);
965 /** \ingroup TRACE_user_variables
966 * \brief Set the user state to the given value.
968 * Change a user state previously declared to the given value.
970 * \param host The name of the host to be considered.
971 * \param state The name of the state previously declared.
972 * \param value The new value of the state.
974 * \see TRACE_host_state_declare, TRACE_host_push_state, TRACE_host_pop_state, TRACE_host_reset_state
976 void TRACE_host_set_state (const char *host, const char *state, const char *value)
978 container_t container = PJ_container_get(host);
979 type_t type = PJ_type_get (state, container->type);
980 val_t val = PJ_value_get_or_new (value, NULL, type); /* if user didn't declare a value with a color, use NULL color */
981 new_pajeSetState(MSG_get_clock(), container, type, val);
984 /** \ingroup TRACE_user_variables
985 * \brief Push a new value for a state of a given host.
987 * Change a user state previously declared by pushing the new value to the state.
989 * \param host The name of the host to be considered.
990 * \param state The name of the state previously declared.
991 * \param value The value to be pushed.
993 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_pop_state, TRACE_host_reset_state
995 void TRACE_host_push_state (const char *host, const char *state, const char *value)
997 container_t container = PJ_container_get(host);
998 type_t type = PJ_type_get (state, container->type);
999 val_t val = PJ_value_get_or_new (value, NULL, type); /* if user didn't declare a value with a color, use NULL color */
1000 new_pajePushState(MSG_get_clock(), container, type, val);
1003 /** \ingroup TRACE_user_variables
1004 * \brief Pop the last value of a state of a given host.
1006 * Change a user state previously declared by removing the last value of the state.
1008 * \param host The name of the host to be considered.
1009 * \param state The name of the state to be popped.
1011 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_reset_state
1013 void TRACE_host_pop_state (const char *host, const char *state)
1015 container_t container = PJ_container_get(host);
1016 type_t type = PJ_type_get (state, container->type);
1017 new_pajePopState(MSG_get_clock(), container, type);
1020 /** \ingroup TRACE_user_variables
1021 * \brief Reset the state of a given host.
1023 * Clear all previous values of a user state.
1025 * \param host The name of the host to be considered.
1026 * \param state The name of the state to be cleared.
1028 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_pop_state
1030 void TRACE_host_reset_state (const char *host, const char *state)
1032 container_t container = PJ_container_get(host);
1033 type_t type = PJ_type_get (state, container->type);
1034 new_pajeResetState(MSG_get_clock(), container, type);
1037 /** \ingroup TRACE_API
1038 * \brief Get Paje container types that can be mapped to the nodes of a graph.
1040 * This function can be used to create a user made graph configuration file for Triva. Normally, it is used with the
1041 * functions defined in \ref TRACE_user_variables.
1043 * \return A dynar with the types, must be freed with xbt_dynar_free.
1045 xbt_dynar_t TRACE_get_node_types (void)
1047 return instr_dict_to_dynar (trivaNodeTypes);
1050 /** \ingroup TRACE_API
1051 * \brief Get Paje container types that can be mapped to the edges of a graph.
1053 * This function can be used to create a user made graph configuration file for Triva. Normally, it is used with the
1054 * functions defined in \ref TRACE_user_variables.
1056 * \return A dynar with the types, must be freed with xbt_dynar_free.
1058 xbt_dynar_t TRACE_get_edge_types (void)
1060 return instr_dict_to_dynar (trivaEdgeTypes);
1063 /** \ingroup TRACE_API
1064 * \brief Pauses all tracing activities.
1067 void TRACE_pause (void)
1069 instr_pause_tracing();
1072 /** \ingroup TRACE_API
1073 * \brief Resumes all tracing activities.
1076 void TRACE_resume (void)
1078 instr_resume_tracing();