1 /* Copyright (c) 2010-2014. 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"
10 #include "instr/instr_private.h"
11 #include "surf/surf.h"
12 #include "surf/surf_private.h"
21 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API");
23 xbt_dict_t created_categories = NULL;
24 xbt_dict_t declared_marks = NULL;
25 xbt_dict_t user_host_variables = NULL;
26 xbt_dict_t user_vm_variables = NULL;
27 xbt_dict_t user_link_variables = NULL;
28 extern xbt_dict_t trivaNodeTypes;
29 extern xbt_dict_t trivaEdgeTypes;
31 static xbt_dynar_t instr_dict_to_dynar (xbt_dict_t filter)
33 if (!TRACE_is_enabled()) return NULL;
34 if (!TRACE_needs_platform()) return NULL;
36 xbt_dynar_t ret = xbt_dynar_new (sizeof(char*), &xbt_free_ref);
37 xbt_dict_cursor_t cursor = NULL;
39 xbt_dict_foreach(filter, cursor, name, value) {
40 xbt_dynar_push_as (ret, char*, xbt_strdup(name));
45 /** \ingroup TRACE_category
46 * \brief Declare a new category with a random color.
48 * This function should be used to define a user category. The
49 * category can be used to differentiate the tasks that are created
50 * during the simulation (for example, tasks from server1, server2,
51 * or request tasks, computation tasks, communication tasks). All
52 * resource utilization (host power and link bandwidth) will be
53 * classified according to the task category. Tasks that do not
54 * belong to a category are not traced. The color for the category
55 * that is being declared is random. This function has no effect
56 * if a category with the same name has been already declared.
58 * See \ref tracing for details on how to trace
59 * the (categorized) resource utilization.
61 * \param category The name of the new tracing category to be created.
63 * \see TRACE_category_with_color, MSG_task_set_category, SD_task_set_category
65 void TRACE_category(const char *category)
67 TRACE_category_with_color (category, NULL);
70 /** \ingroup TRACE_category
71 * \brief Declare a new category with a color.
73 * Same as #TRACE_category, but let user specify a color encoded as a
74 * RGB-like string with three floats from 0 to 1. So, to specify a
75 * red color, pass "1 0 0" as color parameter. A light-gray color
76 * can be specified using "0.7 0.7 0.7" as color. This function has
77 * no effect if a category with the same name has been already declared.
79 * See \ref tracing for details on how to trace
80 * the (categorized) resource utilization.
82 * \param category The name of the new tracing category to be created.
83 * \param color The color of the category (see \ref tracing to
84 * know how to correctly specify the color)
86 * \see MSG_task_set_category, SD_task_set_category
88 void TRACE_category_with_color (const char *category, const char *color)
91 if (!TRACE_is_enabled()) return;
93 if (!(TRACE_categorized() && category != NULL)) return;
95 /* if platform is not traced, we can't deal with categories */
96 if (!TRACE_needs_platform()) return;
98 //check if category is already created
99 char *created = xbt_dict_get_or_null(created_categories, category);
101 xbt_dict_set (created_categories, category, xbt_strdup("1"), NULL);
104 char final_color[INSTR_DEFAULT_STR_SIZE];
106 //generate a random color
107 double red = drand48();
108 double green = drand48();
109 double blue = drand48();
110 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%f %f %f", red, green, blue);
112 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
115 XBT_DEBUG("CAT,declare %s, \"%s\" \"%s\"", category, color, final_color);
117 //define the type of this category on top of hosts and links
118 instr_new_variable_type (category, final_color);
122 /** \ingroup TRACE_category
123 * \brief Get declared categories
125 * This function should be used to get categories that were already
126 * declared with #TRACE_category or with #TRACE_category_with_color.
128 * See \ref tracing for details on how to trace
129 * the (categorized) resource utilization.
131 * \return A dynar with the declared categories, must be freed with xbt_dynar_free.
133 * \see MSG_task_set_category, SD_task_set_category
135 xbt_dynar_t TRACE_get_categories (void)
137 if (!TRACE_is_enabled()) return NULL;
138 if (!TRACE_categorized()) return NULL;
140 return instr_dict_to_dynar (created_categories);
143 /** \ingroup TRACE_mark
144 * \brief Declare a new type for tracing mark.
146 * This function declares a new Paje event
147 * type in the trace file that can be used by
148 * simulators to declare application-level
149 * marks. This function is independent of
150 * which API is used in SimGrid.
152 * \param mark_type The name of the new type.
156 void TRACE_declare_mark(const char *mark_type)
159 if (!TRACE_is_enabled()) return;
161 /* if platform is not traced, we don't allow marks */
162 if (!TRACE_needs_platform()) return;
164 if (!mark_type) THROWF (tracing_error, 1, "mark_type is NULL");
166 //check if mark_type is already declared
167 char *created = xbt_dict_get_or_null(declared_marks, mark_type);
169 THROWF (tracing_error, 1, "mark_type with name (%s) is already declared", mark_type);
172 XBT_DEBUG("MARK,declare %s", mark_type);
173 PJ_type_event_new(mark_type, PJ_type_get_root());
174 xbt_dict_set (declared_marks, mark_type, xbt_strdup("1"), NULL);
177 /** \ingroup TRACE_mark
178 * \brief Declare a new colored value for a previously declared mark type.
180 * This function declares a new colored value for a Paje event
181 * type in the trace file that can be used by
182 * simulators to declare application-level
183 * marks. This function is independent of
184 * which API is used in SimGrid. The color needs to be
185 * a string with three numbers separated by spaces in the range [0,1].
186 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
187 * If a NULL color is provided, the color used will be white ("1 1 1").
189 * \param mark_type The name of the new type.
190 * \param mark_value The name of the new value for this type.
191 * \param mark_color The color of the new value for this type.
195 void TRACE_declare_mark_value_with_color (const char *mark_type, const char *mark_value, const char *mark_color)
198 if (!TRACE_is_enabled()) return;
200 /* if platform is not traced, we don't allow marks */
201 if (!TRACE_needs_platform()) return;
203 if (!mark_type) THROWF (tracing_error, 1, "mark_type is NULL");
204 if (!mark_value) THROWF (tracing_error, 1, "mark_value is NULL");
206 type_t type = PJ_type_get (mark_type, PJ_type_get_root());
208 THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
211 char white[INSTR_DEFAULT_STR_SIZE] = "1.0 1.0 1.0";
212 if (!mark_color) mark_color = white;
214 XBT_DEBUG("MARK,declare_value %s %s %s", mark_type, mark_value, mark_color);
215 PJ_value_new (mark_value, mark_color, type);
218 /** \ingroup TRACE_mark
219 * \brief Declare a new value for a previously declared mark type.
221 * This function declares a new value for a Paje event
222 * type in the trace file that can be used by
223 * simulators to declare application-level
224 * marks. This function is independent of
225 * which API is used in SimGrid. Calling this function is the same
226 * as calling \ref TRACE_declare_mark_value_with_color with a NULL color.
228 * \param mark_type The name of the new type.
229 * \param mark_value The name of the new value for this type.
233 void TRACE_declare_mark_value (const char *mark_type, const char *mark_value)
235 TRACE_declare_mark_value_with_color (mark_type, mark_value, NULL);
239 * \ingroup TRACE_mark
240 * \brief Create a new instance of a tracing mark type.
242 * This function creates a mark in the trace file. The
243 * first parameter had to be previously declared using
244 * #TRACE_declare_mark, the second is the identifier
245 * for this mark instance. We recommend that the
246 * mark_value is a unique value for the whole simulation.
247 * Nevertheless, this is not a strong requirement: the
248 * trace will be valid even if there are multiple mark
249 * identifiers for the same trace.
251 * \param mark_type The name of the type for which the new instance will belong.
252 * \param mark_value The name of the new instance mark.
254 * \see TRACE_declare_mark
256 void TRACE_mark(const char *mark_type, const char *mark_value)
259 if (!TRACE_is_enabled()) return;
261 /* if platform is not traced, we don't allow marks */
262 if (!TRACE_needs_platform()) return;
264 if (!mark_type) THROWF (tracing_error, 1, "mark_type is NULL");
265 if (!mark_value) THROWF (tracing_error, 1, "mark_value is NULL");
267 //check if mark_type is already declared
268 type_t type = PJ_type_get (mark_type, PJ_type_get_root());
270 THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
273 val_t value = PJ_value_get (mark_value, type);
274 XBT_DEBUG("MARK %s %s", mark_type, mark_value);
275 new_pajeNewEvent (MSG_get_clock(), PJ_container_get_root(), type, value);
278 /** \ingroup TRACE_mark
279 * \brief Get declared marks
281 * This function should be used to get marks that were already
282 * declared with #TRACE_declare_mark.
284 * \return A dynar with the declared marks, must be freed with xbt_dynar_free.
287 xbt_dynar_t TRACE_get_marks (void)
289 if (!TRACE_is_enabled()) return NULL;
291 return instr_dict_to_dynar (declared_marks);
294 static void instr_user_variable(double time,
295 const char *resource,
296 const char *variable,
297 const char *father_type,
299 InstrUserVariable what,
304 if (!TRACE_is_enabled()) return;
306 /* if platform is not traced, we don't allow user variables */
307 if (!TRACE_needs_platform()) return;
309 //check if variable is already declared
310 char *created = xbt_dict_get_or_null(filter, variable);
311 if (what == INSTR_US_DECLARE){
316 xbt_dict_set (filter, variable, xbt_strdup("1"), NULL);
320 //not declared, ignore
326 snprintf(valuestr, 100, "%g", value);
329 case INSTR_US_DECLARE:
330 instr_new_user_variable_type (father_type, variable, color);
334 container_t container = PJ_container_get(resource);
335 type_t type = PJ_type_get (variable, container->type);
336 new_pajeSetVariable(time, container, type, value);
341 container_t container = PJ_container_get(resource);
342 type_t type = PJ_type_get (variable, container->type);
343 new_pajeAddVariable(time, container, type, value);
348 container_t container = PJ_container_get(resource);
349 type_t type = PJ_type_get (variable, container->type);
350 new_pajeSubVariable(time, container, type, value);
354 //TODO: launch exception
359 static void instr_user_srcdst_variable(double time,
362 const char *variable,
363 const char *father_type,
365 InstrUserVariable what)
367 xbt_dynar_t route=NULL;
368 sg_routing_edge_t src_elm = sg_routing_edge_by_name_or_null(src);
369 if(!src_elm) xbt_die("Element '%s' not found!",src);
371 sg_routing_edge_t dst_elm = sg_routing_edge_by_name_or_null(dst);
372 if(!dst_elm) xbt_die("Element '%s' not found!",dst);
374 routing_get_route_and_latency (src_elm, dst_elm, &route,NULL);
377 xbt_dynar_foreach (route, i, link) {
378 char *link_name = (char*)surf_resource_name(link);
379 instr_user_variable (time, link_name, variable, father_type, value, what, NULL, user_link_variables);
383 /** \ingroup TRACE_API
384 * \brief Creates a file with the topology of the platform file used for the simulator.
386 * The graph topology will have the following properties: all hosts, links and routers
387 * of the platform file are mapped to graph nodes; routes are mapped to edges.
388 * The platform's AS are not represented in the output.
390 * \param filename The name of the file that will hold the graph.
392 * \return 1 of successful, 0 otherwise.
394 int TRACE_platform_graph_export_graphviz (const char *filename)
396 /* returns 1 if successful, 0 otherwise */
397 if (!TRACE_is_enabled()) return 0;
398 xbt_graph_t g = instr_routing_platform_graph();
399 if (g == NULL) return 0;
400 instr_routing_platform_graph_export_graphviz (g, filename);
401 xbt_graph_free_graph (g, xbt_free, xbt_free, NULL);
406 * Derived functions that use instr_user_variable and TRACE_user_srcdst_variable.
407 * They were previously defined as pre-processors directives, but were transformed
408 * into functions so the user can track them using gdb.
411 /* for VM variables */
412 /** \ingroup TRACE_user_variables
413 * \brief Declare a new user variable associated to VMs.
415 * Declare a user variable that will be associated to VMs.
416 * A user vm variable can be used to trace user variables
417 * such as the number of tasks in a VM, the number of
418 * clients in an application (for VMs), and so on. The color
419 * associated to this new variable will be random.
421 * \param variable The name of the new variable to be declared.
423 * \see TRACE_vm_variable_declare_with_color
425 void TRACE_vm_variable_declare (const char *variable)
427 instr_user_variable(0, NULL, variable, "MSG_VM", 0, INSTR_US_DECLARE, NULL, user_vm_variables);
430 /** \ingroup TRACE_user_variables
431 * \brief Declare a new user variable associated to VMs with a color.
433 * Same as #TRACE_vm_variable_declare, but associated a color
434 * to the newly created user host variable. The color needs to be
435 * a string with three numbers separated by spaces in the range [0,1].
436 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
438 * \param variable The name of the new variable to be declared.
439 * \param color The color for the new variable.
442 void TRACE_vm_variable_declare_with_color (const char *variable, const char *color)
444 instr_user_variable(0, NULL, variable, "MSG_VM", 0, INSTR_US_DECLARE, color, user_vm_variables);
447 /** \ingroup TRACE_user_variables
448 * \brief Set the value of a variable of a host.
450 * \param vm The name of the VM to be considered.
451 * \param variable The name of the variable to be considered.
452 * \param value The new value of the variable.
454 * \see TRACE_vm_variable_declare, TRACE_vm_variable_add, TRACE_vm_variable_sub
456 void TRACE_vm_variable_set (const char *vm, const char *variable, double value)
459 TRACE_vm_variable_set_with_time (MSG_get_clock(), vm, variable, value);
462 /** \ingroup TRACE_user_variables
463 * \brief Add a value to a variable of a VM.
465 * \param vm The name of the VM to be considered.
466 * \param variable The name of the variable to be considered.
467 * \param value The value to be added to the variable.
469 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_sub
471 void TRACE_vm_variable_add (const char *vm, const char *variable, double value)
473 TRACE_vm_variable_add_with_time (MSG_get_clock(), vm, variable, value);
476 /** \ingroup TRACE_user_variables
477 * \brief Subtract a value from a variable of a VM.
479 * \param vm The name of the vm to be considered.
480 * \param variable The name of the variable to be considered.
481 * \param value The value to be subtracted from the variable.
483 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set, TRACE_vm_variable_add
485 void TRACE_vm_variable_sub (const char *vm, const char *variable, double value)
487 TRACE_vm_variable_sub_with_time (MSG_get_clock(), vm, variable, value);
490 /** \ingroup TRACE_user_variables
491 * \brief Set the value of a variable of a VM at a given timestamp.
493 * Same as #TRACE_vm_variable_set, but let user specify
494 * the time used to trace it. Users can specify a time that
495 * is not the simulated clock time as defined by the core
496 * simulator. This allows a fine-grain control of time
497 * definition, but should be used with caution since the trace
498 * can be inconsistent if resource utilization traces are also traced.
500 * \param time The timestamp to be used to tag this change of value.
501 * \param vm The name of the VM to be considered.
502 * \param variable The name of the variable to be considered.
503 * \param value The new value of the variable.
505 * \see TRACE_vm_variable_declare, TRACE_vm_variable_add_with_time, TRACE_vm_variable_sub_with_time
507 void TRACE_vm_variable_set_with_time (double time, const char *vm, const char *variable, double value)
509 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_SET, NULL, user_vm_variables);
512 /** \ingroup TRACE_user_variables
513 * \brief Add a value to a variable of a VM at a given timestamp.
515 * Same as #TRACE_vm_variable_add, but let user specify
516 * the time used to trace it. Users can specify a time that
517 * is not the simulated clock time as defined by the core
518 * simulator. This allows a fine-grain control of time
519 * definition, but should be used with caution since the trace
520 * can be inconsistent if resource utilization traces are also traced.
522 * \param time The timestamp to be used to tag this change of value.
523 * \param vm The name of the VM to be considered.
524 * \param variable The name of the variable to be considered.
525 * \param value The value to be added to the variable.
527 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_sub_with_time
529 void TRACE_vm_variable_add_with_time (double time, const char *vm, const char *variable, double value)
531 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_ADD, NULL, user_vm_variables);
534 /** \ingroup TRACE_user_variables
535 * \brief Subtract a value from a variable of a VM at a given timestamp.
537 * Same as #TRACE_vm_variable_sub, but let user specify
538 * the time used to trace it. Users can specify a time that
539 * is not the simulated clock time as defined by the core
540 * simulator. This allows a fine-grain control of time
541 * definition, but should be used with caution since the trace
542 * can be inconsistent if resource utilization traces are also traced.
544 * \param time The timestamp to be used to tag this change of value.
545 * \param vm The name of the VM to be considered.
546 * \param variable The name of the variable to be considered.
547 * \param value The value to be subtracted from the variable.
549 * \see TRACE_vm_variable_declare, TRACE_vm_variable_set_with_time, TRACE_vm_variable_add_with_time
551 void TRACE_vm_variable_sub_with_time (double time, const char *vm, const char *variable, double value)
553 instr_user_variable(time, vm, variable, "MSG_VM", value, INSTR_US_SUB, NULL, user_vm_variables);
556 /** \ingroup TRACE_user_variables
557 * \brief Get declared user vm variables
559 * This function should be used to get VM variables that were already
560 * declared with #TRACE_vm_variable_declare or with #TRACE_vm_variable_declare_with_color.
562 * \return A dynar with the declared host variables, must be freed with xbt_dynar_free.
564 xbt_dynar_t TRACE_get_vm_variables (void)
566 return instr_dict_to_dynar (user_vm_variables);
571 /* for host variables */
572 /** \ingroup TRACE_user_variables
573 * \brief Declare a new user variable associated to hosts.
575 * Declare a user variable that will be associated to hosts.
576 * A user host variable can be used to trace user variables
577 * such as the number of tasks in a server, the number of
578 * clients in an application (for hosts), and so on. The color
579 * associated to this new variable will be random.
581 * \param variable The name of the new variable to be declared.
583 * \see TRACE_host_variable_declare_with_color
585 void TRACE_host_variable_declare (const char *variable)
587 instr_user_variable(0, NULL, variable, "HOST", 0, INSTR_US_DECLARE, NULL, user_host_variables);
590 /** \ingroup TRACE_user_variables
591 * \brief Declare a new user variable associated to hosts with a color.
593 * Same as #TRACE_host_variable_declare, but associated a color
594 * to the newly created user host variable. The color needs to be
595 * a string with three numbers separated by spaces in the range [0,1].
596 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
598 * \param variable The name of the new variable to be declared.
599 * \param color The color for the new variable.
602 void TRACE_host_variable_declare_with_color (const char *variable, const char *color)
604 instr_user_variable(0, NULL, variable, "HOST", 0, INSTR_US_DECLARE, color, user_host_variables);
607 /** \ingroup TRACE_user_variables
608 * \brief Set the value of a variable of a host.
610 * \param host The name of the host to be considered.
611 * \param variable The name of the variable to be considered.
612 * \param value The new value of the variable.
614 * \see TRACE_host_variable_declare, TRACE_host_variable_add, TRACE_host_variable_sub
616 void TRACE_host_variable_set (const char *host, const char *variable, double value)
618 TRACE_host_variable_set_with_time (MSG_get_clock(), host, variable, value);
621 /** \ingroup TRACE_user_variables
622 * \brief Add a value to a variable of a host.
624 * \param host The name of the host to be considered.
625 * \param variable The name of the variable to be considered.
626 * \param value The value to be added to the variable.
628 * \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_sub
630 void TRACE_host_variable_add (const char *host, const char *variable, double value)
632 TRACE_host_variable_add_with_time (MSG_get_clock(), host, variable, value);
635 /** \ingroup TRACE_user_variables
636 * \brief Subtract a value from a variable of a host.
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, TRACE_host_variable_add
644 void TRACE_host_variable_sub (const char *host, const char *variable, double value)
646 TRACE_host_variable_sub_with_time (MSG_get_clock(), host, variable, value);
649 /** \ingroup TRACE_user_variables
650 * \brief Set the value of a variable of a host at a given timestamp.
652 * Same as #TRACE_host_variable_set, but let user specify
653 * the time used to trace it. Users can specify a time that
654 * is not the simulated clock time as defined by the core
655 * simulator. This allows a fine-grain control of time
656 * definition, but should be used with caution since the trace
657 * can be inconsistent if resource utilization traces are also traced.
659 * \param time The timestamp to be used to tag this change of value.
660 * \param host The name of the host to be considered.
661 * \param variable The name of the variable to be considered.
662 * \param value The new value of the variable.
664 * \see TRACE_host_variable_declare, TRACE_host_variable_add_with_time, TRACE_host_variable_sub_with_time
666 void TRACE_host_variable_set_with_time (double time, const char *host, const char *variable, double value)
668 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SET, NULL, user_host_variables);
671 /** \ingroup TRACE_user_variables
672 * \brief Add a value to a variable of a host at a given timestamp.
674 * Same as #TRACE_host_variable_add, but let user specify
675 * the time used to trace it. Users can specify a time that
676 * is not the simulated clock time as defined by the core
677 * simulator. This allows a fine-grain control of time
678 * definition, but should be used with caution since the trace
679 * can be inconsistent if resource utilization traces are also traced.
681 * \param time The timestamp to be used to tag this change of value.
682 * \param host The name of the host 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_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_sub_with_time
688 void TRACE_host_variable_add_with_time (double time, const char *host, const char *variable, double value)
690 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_ADD, NULL, user_host_variables);
693 /** \ingroup TRACE_user_variables
694 * \brief Subtract a value from a variable of a host at a given timestamp.
696 * Same as #TRACE_host_variable_sub, but let user specify
697 * the time used to trace it. Users can specify a time that
698 * is not the simulated clock time as defined by the core
699 * simulator. This allows a fine-grain control of time
700 * definition, but should be used with caution since the trace
701 * can be inconsistent if resource utilization traces are also traced.
703 * \param time The timestamp to be used to tag this change of value.
704 * \param host The name of the host to be considered.
705 * \param variable The name of the variable to be considered.
706 * \param value The value to be subtracted from the variable.
708 * \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_add_with_time
710 void TRACE_host_variable_sub_with_time (double time, const char *host, const char *variable, double value)
712 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SUB, NULL, user_host_variables);
715 /** \ingroup TRACE_user_variables
716 * \brief Get declared user host variables
718 * This function should be used to get host variables that were already
719 * declared with #TRACE_host_variable_declare or with #TRACE_host_variable_declare_with_color.
721 * \return A dynar with the declared host variables, must be freed with xbt_dynar_free.
723 xbt_dynar_t TRACE_get_host_variables (void)
725 return instr_dict_to_dynar (user_host_variables);
728 /* for link variables */
729 /** \ingroup TRACE_user_variables
730 * \brief Declare a new user variable associated to links.
732 * Declare a user variable that will be associated to links.
733 * A user link variable can be used, for example, to trace
734 * user variables such as the number of messages being
735 * transferred through network links. The color
736 * associated to this new variable will be random.
738 * \param variable The name of the new variable to be declared.
740 * \see TRACE_link_variable_declare_with_color
742 void TRACE_link_variable_declare (const char *variable)
744 instr_user_variable (0, NULL, variable, "LINK", 0, INSTR_US_DECLARE, NULL, user_link_variables);
747 /** \ingroup TRACE_user_variables
748 * \brief Declare a new user variable associated to links with a color.
750 * Same as #TRACE_link_variable_declare, but associated a color
751 * to the newly created user link variable. The color needs to be
752 * a string with three numbers separated by spaces in the range [0,1].
753 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
755 * \param variable The name of the new variable to be declared.
756 * \param color The color for the new variable.
759 void TRACE_link_variable_declare_with_color (const char *variable, const char *color)
761 instr_user_variable (0, NULL, variable, "LINK", 0, INSTR_US_DECLARE, color, user_link_variables);
764 /** \ingroup TRACE_user_variables
765 * \brief Set the value of a variable of a link.
767 * \param link The name of the link to be considered.
768 * \param variable The name of the variable to be considered.
769 * \param value The new value of the variable.
771 * \see TRACE_link_variable_declare, TRACE_link_variable_add, TRACE_link_variable_sub
773 void TRACE_link_variable_set (const char *link, const char *variable, double value)
775 TRACE_link_variable_set_with_time (MSG_get_clock(), link, variable, value);
778 /** \ingroup TRACE_user_variables
779 * \brief Add a value to a variable of a link.
781 * \param link The name of the link to be considered.
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_variable_set, TRACE_link_variable_sub
787 void TRACE_link_variable_add (const char *link, const char *variable, double value)
789 TRACE_link_variable_add_with_time (MSG_get_clock(), link, variable, value);
792 /** \ingroup TRACE_user_variables
793 * \brief Subtract a value from a variable of a link.
795 * \param link The name of the link to be considered.
796 * \param variable The name of the variable to be considered.
797 * \param value The value to be subtracted from the variable.
799 * \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_add
801 void TRACE_link_variable_sub (const char *link, const char *variable, double value)
803 TRACE_link_variable_sub_with_time (MSG_get_clock(), link, variable, value);
806 /** \ingroup TRACE_user_variables
807 * \brief Set the value of a variable of a link at a given timestamp.
809 * Same as #TRACE_link_variable_set, but let user specify
810 * the time used to trace it. Users can specify a time that
811 * is not the simulated clock time as defined by the core
812 * simulator. This allows a fine-grain control of time
813 * definition, but should be used with caution since the trace
814 * can be inconsistent if resource utilization traces are also traced.
816 * \param time The timestamp to be used to tag this change of value.
817 * \param link The name of the link to be considered.
818 * \param variable The name of the variable to be considered.
819 * \param value The new value of the variable.
821 * \see TRACE_link_variable_declare, TRACE_link_variable_add_with_time, TRACE_link_variable_sub_with_time
823 void TRACE_link_variable_set_with_time (double time, const char *link, const char *variable, double value)
825 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SET, NULL, user_link_variables);
828 /** \ingroup TRACE_user_variables
829 * \brief Add a value to a variable of a link at a given timestamp.
831 * Same as #TRACE_link_variable_add, but let user specify
832 * the time used to trace it. Users can specify a time that
833 * is not the simulated clock time as defined by the core
834 * simulator. This allows a fine-grain control of time
835 * definition, but should be used with caution since the trace
836 * can be inconsistent if resource utilization traces are also traced.
838 * \param time The timestamp to be used to tag this change of value.
839 * \param link The name of the link to be considered.
840 * \param variable The name of the variable to be considered.
841 * \param value The value to be added to the variable.
843 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_sub_with_time
845 void TRACE_link_variable_add_with_time (double time, const char *link, const char *variable, double value)
847 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_ADD, NULL, user_link_variables);
850 /** \ingroup TRACE_user_variables
851 * \brief Subtract a value from a variable of a link at a given timestamp.
853 * Same as #TRACE_link_variable_sub, but let user specify
854 * the time used to trace it. Users can specify a time that
855 * is not the simulated clock time as defined by the core
856 * simulator. This allows a fine-grain control of time
857 * definition, but should be used with caution since the trace
858 * can be inconsistent if resource utilization traces are also traced.
860 * \param time The timestamp to be used to tag this change of value.
861 * \param link The name of the link to be considered.
862 * \param variable The name of the variable to be considered.
863 * \param value The value to be subtracted from the variable.
865 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_add_with_time
867 void TRACE_link_variable_sub_with_time (double time, const char *link, const char *variable, double value)
869 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SUB, NULL, user_link_variables);
872 /* for link variables, but with src and dst used for get_route */
873 /** \ingroup TRACE_user_variables
874 * \brief Set the value of the variable present in the links connecting source and destination.
876 * Same as #TRACE_link_variable_set, but instead of providing the
877 * name of link to be considered, provide the source and destination
878 * hosts. All links that are part of the route between source and
879 * destination will have the variable set to the provided value.
881 * \param src The name of the source host for get route.
882 * \param dst The name of the destination host for get route.
883 * \param variable The name of the variable to be considered.
884 * \param value The new value of the variable.
886 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add, TRACE_link_srcdst_variable_sub
888 void TRACE_link_srcdst_variable_set (const char *src, const char *dst, const char *variable, double value)
890 TRACE_link_srcdst_variable_set_with_time (MSG_get_clock(), src, dst, variable, value);
893 /** \ingroup TRACE_user_variables
894 * \brief Add a value to the variable present in the links connecting source and destination.
896 * Same as #TRACE_link_variable_add, but instead of providing the
897 * name of link to be considered, provide the source and destination
898 * hosts. All links that are part of the route between source and
899 * destination will have the value passed as parameter added to
900 * the current value of the variable name to be considered.
902 * \param src The name of the source host for get route.
903 * \param dst The name of the destination host for get route.
904 * \param variable The name of the variable to be considered.
905 * \param value The value to be added to the variable.
907 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_sub
909 void TRACE_link_srcdst_variable_add (const char *src, const char *dst, const char *variable, double value)
911 TRACE_link_srcdst_variable_add_with_time (MSG_get_clock(), src, dst, variable, value);
914 /** \ingroup TRACE_user_variables
915 * \brief Subtract a value from the variable present in the links connecting source and destination.
917 * Same as #TRACE_link_variable_sub, but instead of providing the
918 * name of link to be considered, provide the source and destination
919 * hosts. All links that are part of the route between source and
920 * destination will have the value passed as parameter subtracted from
921 * the current value of the variable name to be considered.
923 * \param src The name of the source host for get route.
924 * \param dst The name of the destination host for get route.
925 * \param variable The name of the variable to be considered.
926 * \param value The value to be subtracted from the variable.
928 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_add
930 void TRACE_link_srcdst_variable_sub (const char *src, const char *dst, const char *variable, double value)
932 TRACE_link_srcdst_variable_sub_with_time (MSG_get_clock(), src, dst, variable, value);
935 /** \ingroup TRACE_user_variables
936 * \brief Set the value of the variable present in the links connecting source and destination at a given timestamp.
938 * Same as #TRACE_link_srcdst_variable_set, but let user specify
939 * the time used to trace it. Users can specify a time that
940 * is not the simulated clock time as defined by the core
941 * simulator. This allows a fine-grain control of time
942 * definition, but should be used with caution since the trace
943 * can be inconsistent if resource utilization traces are also traced.
945 * \param time The timestamp to be used to tag this change of value.
946 * \param src The name of the source host for get route.
947 * \param dst The name of the destination host for get route.
948 * \param variable The name of the variable to be considered.
949 * \param value The new value of the variable.
951 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add_with_time, TRACE_link_srcdst_variable_sub_with_time
953 void TRACE_link_srcdst_variable_set_with_time (double time, const char *src, const char *dst, const char *variable, double value)
955 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SET);
958 /** \ingroup TRACE_user_variables
959 * \brief Add a value to the variable present in the links connecting source and destination at a given timestamp.
961 * Same as #TRACE_link_srcdst_variable_add, but let user specify
962 * the time used to trace it. Users can specify a time that
963 * is not the simulated clock time as defined by the core
964 * simulator. This allows a fine-grain control of time
965 * definition, but should be used with caution since the trace
966 * can be inconsistent if resource utilization traces are also traced.
968 * \param time The timestamp to be used to tag this change of value.
969 * \param src The name of the source host for get route.
970 * \param dst The name of the destination host for get route.
971 * \param variable The name of the variable to be considered.
972 * \param value The value to be added to the variable.
974 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_sub_with_time
976 void TRACE_link_srcdst_variable_add_with_time (double time, const char *src, const char *dst, const char *variable, double value)
978 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_ADD);
981 /** \ingroup TRACE_user_variables
982 * \brief Subtract a value from the variable present in the links connecting source and destination at a given timestamp.
984 * Same as #TRACE_link_srcdst_variable_sub, but let user specify
985 * the time used to trace it. Users can specify a time that
986 * is not the simulated clock time as defined by the core
987 * simulator. This allows a fine-grain control of time
988 * definition, but should be used with caution since the trace
989 * can be inconsistent if resource utilization traces are also traced.
991 * \param time The timestamp to be used to tag this change of value.
992 * \param src The name of the source host for get route.
993 * \param dst The name of the destination host for get route.
994 * \param variable The name of the variable to be considered.
995 * \param value The value to be subtracted from the variable.
997 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_add_with_time
999 void TRACE_link_srcdst_variable_sub_with_time (double time, const char *src, const char *dst, const char *variable, double value)
1001 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SUB);
1004 /** \ingroup TRACE_user_variables
1005 * \brief Get declared user link variables
1007 * This function should be used to get link variables that were already
1008 * declared with #TRACE_link_variable_declare or with #TRACE_link_variable_declare_with_color.
1010 * \return A dynar with the declared link variables, must be freed with xbt_dynar_free.
1012 xbt_dynar_t TRACE_get_link_variables (void)
1014 return instr_dict_to_dynar (user_link_variables);
1017 /** \ingroup TRACE_user_variables
1018 * \brief Declare a new user state associated to hosts.
1020 * Declare a user state that will be associated to hosts.
1021 * A user host state can be used to trace application states.
1023 * \param state The name of the new state to be declared.
1025 * \see TRACE_host_state_declare_value
1027 void TRACE_host_state_declare (const char *state)
1029 instr_new_user_state_type("HOST", state);
1032 /** \ingroup TRACE_user_variables
1033 * \brief Declare a new value for a user state associated to hosts.
1035 * Declare a value for a state. The color needs to be
1036 * a string with three numbers separated by spaces in the range [0,1].
1037 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
1039 * \param state The name of the new state to be declared.
1040 * \param value The name of the value
1041 * \param color The color of the value
1043 * \see TRACE_host_state_declare
1045 void TRACE_host_state_declare_value (const char *state, const char *value, const char *color)
1047 instr_new_value_for_user_state_type (state, value, color);
1050 /** \ingroup TRACE_user_variables
1051 * \brief Set the user state to the given value.
1053 * Change a user state previously declared to the given value.
1055 * \param host The name of the host to be considered.
1056 * \param state The name of the state previously declared.
1057 * \param value The new value of the state.
1059 * \see TRACE_host_state_declare, TRACE_host_push_state, TRACE_host_pop_state, TRACE_host_reset_state
1061 void TRACE_host_set_state (const char *host, const char *state, const char *value)
1063 container_t container = PJ_container_get(host);
1064 type_t type = PJ_type_get (state, container->type);
1065 val_t val = PJ_value_get_or_new (value, NULL, type); /* if user didn't declare a value with a color, user a NULL color */
1066 new_pajeSetState(MSG_get_clock(), container, type, val);
1069 /** \ingroup TRACE_user_variables
1070 * \brief Push a new value for a state of a given host.
1072 * Change a user state previously declared by pushing the new value to the state.
1074 * \param host The name of the host to be considered.
1075 * \param state The name of the state previously declared.
1076 * \param value The value to be pushed.
1078 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_pop_state, TRACE_host_reset_state
1080 void TRACE_host_push_state (const char *host, const char *state, const char *value)
1082 container_t container = PJ_container_get(host);
1083 type_t type = PJ_type_get (state, container->type);
1084 val_t val = PJ_value_get_or_new (value, NULL, type); /* if user didn't declare a value with a color, user a NULL color */
1085 new_pajePushState(MSG_get_clock(), container, type, val);
1088 /** \ingroup TRACE_user_variables
1089 * \brief Pop the last value of a state of a given host.
1091 * Change a user state previously declared by removing the last value of the state.
1093 * \param host The name of the host to be considered.
1094 * \param state The name of the state to be popped.
1096 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_reset_state
1098 void TRACE_host_pop_state (const char *host, const char *state)
1100 container_t container = PJ_container_get(host);
1101 type_t type = PJ_type_get (state, container->type);
1102 new_pajePopState(MSG_get_clock(), container, type);
1105 /** \ingroup TRACE_user_variables
1106 * \brief Reset the state of a given host.
1108 * Clear all previous values of a user state.
1110 * \param host The name of the host to be considered.
1111 * \param state The name of the state to be cleared.
1113 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_pop_state
1115 void TRACE_host_reset_state (const char *host, const char *state)
1117 container_t container = PJ_container_get(host);
1118 type_t type = PJ_type_get (state, container->type);
1119 new_pajeResetState(MSG_get_clock(), container, type);
1122 /** \ingroup TRACE_API
1123 * \brief Get Paje container types that can be mapped to the nodes of a graph.
1125 * This function can be used to create a user made
1126 * graph configuration file for Triva. Normally, it is
1127 * used with the functions defined in \ref TRACE_user_variables.
1129 * \return A dynar with the types, must be freed with xbt_dynar_free.
1131 xbt_dynar_t TRACE_get_node_types (void)
1133 return instr_dict_to_dynar (trivaNodeTypes);
1136 /** \ingroup TRACE_API
1137 * \brief Get Paje container types that can be mapped to the edges of a graph.
1139 * This function can be used to create a user made
1140 * graph configuration file for Triva. Normally, it is
1141 * used with the functions defined in \ref TRACE_user_variables.
1143 * \return A dynar with the types, must be freed with xbt_dynar_free.
1145 xbt_dynar_t TRACE_get_edge_types (void)
1147 return instr_dict_to_dynar (trivaEdgeTypes);
1150 /** \ingroup TRACE_API
1151 * \brief Pauses all tracing activities.
1154 void TRACE_pause (void)
1156 instr_pause_tracing();
1159 /** \ingroup TRACE_API
1160 * \brief Resumes all tracing activities.
1163 void TRACE_resume (void)
1165 instr_resume_tracing();
1168 #endif /* HAVE_TRACING */