1 /* Copyright (c) 2010. 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/network_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_link_variables = NULL;
26 extern xbt_dict_t trivaNodeTypes;
27 extern xbt_dict_t trivaEdgeTypes;
29 static xbt_dynar_t instr_dict_to_dynar (xbt_dict_t filter)
31 if (!TRACE_is_enabled()) return NULL;
32 if (!TRACE_needs_platform()) return NULL;
34 xbt_dynar_t ret = xbt_dynar_new (sizeof(char*), &xbt_free_ref);
35 xbt_dict_cursor_t cursor = NULL;
37 xbt_dict_foreach(filter, cursor, name, value) {
38 xbt_dynar_push_as (ret, char*, xbt_strdup(name));
43 /** \ingroup TRACE_category
44 * \brief Declare a new category with a random color.
46 * This function should be used to define a user category. The
47 * category can be used to differentiate the tasks that are created
48 * during the simulation (for example, tasks from server1, server2,
49 * or request tasks, computation tasks, communication tasks). All
50 * resource utilization (host power and link bandwidth) will be
51 * classified according to the task category. Tasks that do not
52 * belong to a category are not traced. The color for the category
53 * that is being declared is random. This function has no effect
54 * if a category with the same name has been already declared.
56 * See \ref tracing for details on how to trace
57 * the (categorized) resource utilization.
59 * \param category The name of the new tracing category to be created.
61 * \see TRACE_category_with_color, MSG_task_set_category, SD_task_set_category
63 void TRACE_category(const char *category)
65 TRACE_category_with_color (category, NULL);
68 /** \ingroup TRACE_category
69 * \brief Declare a new category with a color.
71 * Same as #TRACE_category, but let user specify a color encoded as a
72 * RGB-like string with three floats from 0 to 1. So, to specify a
73 * red color, pass "1 0 0" as color parameter. A light-gray color
74 * can be specified using "0.7 0.7 0.7" as color. This function has
75 * no effect if a category with the same name has been already declared.
77 * See \ref tracing for details on how to trace
78 * the (categorized) resource utilization.
80 * \param category The name of the new tracing category to be created.
81 * \param color The color of the category (see \ref tracing to
82 * know how to correctly specify the color)
84 * \see MSG_task_set_category, SD_task_set_category
86 void TRACE_category_with_color (const char *category, const char *color)
89 if (!TRACE_is_enabled()) return;
91 if (!(TRACE_categorized() && category != NULL)) return;
93 /* if platform is not traced, we can't deal with categories */
94 if (!TRACE_needs_platform()) return;
96 //check if category is already created
97 char *created = xbt_dict_get_or_null(created_categories, category);
99 xbt_dict_set (created_categories, category, xbt_strdup("1"), NULL);
102 char final_color[INSTR_DEFAULT_STR_SIZE];
104 //generate a random color
105 double red = drand48();
106 double green = drand48();
107 double blue = drand48();
108 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%f %f %f", red, green, blue);
110 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
113 XBT_DEBUG("CAT,declare %s, %s", category, final_color);
115 //define the type of this category on top of hosts and links
116 instr_new_variable_type (category, final_color);
120 /** \ingroup TRACE_category
121 * \brief Get declared categories
123 * This function should be used to get categories that were already
124 * declared with #TRACE_category or with #TRACE_category_with_color.
126 * See \ref tracing for details on how to trace
127 * the (categorized) resource utilization.
129 * \return A dynar with the declared categories, must be freed with xbt_dynar_free.
131 * \see MSG_task_set_category, SD_task_set_category
133 xbt_dynar_t TRACE_get_categories (void)
135 if (!TRACE_is_enabled()) return NULL;
136 if (!TRACE_categorized()) return NULL;
138 return instr_dict_to_dynar (created_categories);
141 /** \ingroup TRACE_mark
142 * \brief Declare a new type for tracing mark.
144 * This function declares a new Paje event
145 * type in the trace file that can be used by
146 * simulators to declare application-level
147 * marks. This function is independent of
148 * which API is used in SimGrid.
150 * \param mark_type The name of the new type.
154 void TRACE_declare_mark(const char *mark_type)
157 if (!TRACE_is_enabled()) return;
159 /* if platform is not traced, we don't allow marks */
160 if (!TRACE_needs_platform()) return;
162 if (!mark_type) THROWF (tracing_error, 1, "mark_type is NULL");
164 //check if mark_type is already declared
165 char *created = xbt_dict_get_or_null(declared_marks, mark_type);
167 THROWF (tracing_error, 1, "mark_type with name (%s) is already declared", mark_type);
170 XBT_DEBUG("MARK,declare %s", mark_type);
171 PJ_type_event_new(mark_type, PJ_type_get_root());
172 xbt_dict_set (declared_marks, mark_type, xbt_strdup("1"), NULL);
175 /** \ingroup TRACE_mark
176 * \brief Declare a new colored value for a previously declared mark type.
178 * This function declares a new colored value for a Paje event
179 * type in the trace file that can be used by
180 * simulators to declare application-level
181 * marks. This function is independent of
182 * which API is used in SimGrid. The color needs to be
183 * a string with three numbers separated by spaces in the range [0,1].
184 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
185 * If a NULL color is provided, the color used will be white ("1 1 1").
187 * \param mark_type The name of the new type.
188 * \param mark_value The name of the new value for this type.
189 * \param mark_color The color of the new value for this type.
193 void TRACE_declare_mark_value_with_color (const char *mark_type, const char *mark_value, const char *mark_color)
196 if (!TRACE_is_enabled()) return;
198 /* if platform is not traced, we don't allow marks */
199 if (!TRACE_needs_platform()) return;
201 if (!mark_type) THROWF (tracing_error, 1, "mark_type is NULL");
202 if (!mark_value) THROWF (tracing_error, 1, "mark_value is NULL");
204 type_t type = PJ_type_get (mark_type, PJ_type_get_root());
206 THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
209 char white[INSTR_DEFAULT_STR_SIZE] = "1.0 1.0 1.0";
210 if (!mark_color) mark_color = white;
212 XBT_DEBUG("MARK,declare_value %s %s %s", mark_type, mark_value, mark_color);
213 PJ_value_new (mark_value, mark_color, type);
216 /** \ingroup TRACE_mark
217 * \brief Declare a new value for a previously declared mark type.
219 * This function declares a new value for a Paje event
220 * type in the trace file that can be used by
221 * simulators to declare application-level
222 * marks. This function is independent of
223 * which API is used in SimGrid. Calling this function is the same
224 * as calling \ref TRACE_declare_mark_value_with_color with a NULL color.
226 * \param mark_type The name of the new type.
227 * \param mark_value The name of the new value for this type.
231 void TRACE_declare_mark_value (const char *mark_type, const char *mark_value)
233 TRACE_declare_mark_value_with_color (mark_type, mark_value, NULL);
237 * \ingroup TRACE_mark
238 * \brief Create a new instance of a tracing mark type.
240 * This function creates a mark in the trace file. The
241 * first parameter had to be previously declared using
242 * #TRACE_declare_mark, the second is the identifier
243 * for this mark instance. We recommend that the
244 * mark_value is a unique value for the whole simulation.
245 * Nevertheless, this is not a strong requirement: the
246 * trace will be valid even if there are multiple mark
247 * identifiers for the same trace.
249 * \param mark_type The name of the type for which the new instance will belong.
250 * \param mark_value The name of the new instance mark.
252 * \see TRACE_declare_mark
254 void TRACE_mark(const char *mark_type, const char *mark_value)
257 if (!TRACE_is_enabled()) return;
259 /* if platform is not traced, we don't allow marks */
260 if (!TRACE_needs_platform()) return;
262 if (!mark_type) THROWF (tracing_error, 1, "mark_type is NULL");
263 if (!mark_value) THROWF (tracing_error, 1, "mark_value is NULL");
265 //check if mark_type is already declared
266 type_t type = PJ_type_get (mark_type, PJ_type_get_root());
268 THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
271 val_t value = PJ_value_get (mark_value, type);
272 XBT_DEBUG("MARK %s %s", mark_type, mark_value);
273 new_pajeNewEvent (MSG_get_clock(), PJ_container_get_root(), type, value);
276 /** \ingroup TRACE_mark
277 * \brief Get declared marks
279 * This function should be used to get marks that were already
280 * declared with #TRACE_declare_mark.
282 * \return A dynar with the declared marks, must be freed with xbt_dynar_free.
285 xbt_dynar_t TRACE_get_marks (void)
287 if (!TRACE_is_enabled()) return NULL;
289 return instr_dict_to_dynar (declared_marks);
292 static void instr_user_variable(double time,
293 const char *resource,
294 const char *variable,
295 const char *father_type,
297 InstrUserVariable what,
302 if (!TRACE_is_enabled()) return;
304 /* if platform is not traced, we don't allow user variables */
305 if (!TRACE_needs_platform()) return;
307 //check if variable is already declared
308 char *created = xbt_dict_get_or_null(filter, variable);
309 if (what == INSTR_US_DECLARE){
314 xbt_dict_set (filter, variable, xbt_strdup("1"), NULL);
318 //not declared, ignore
324 snprintf(valuestr, 100, "%g", value);
327 case INSTR_US_DECLARE:
328 instr_new_user_variable_type (father_type, variable, color);
332 container_t container = PJ_container_get(resource);
333 type_t type = PJ_type_get (variable, container->type);
334 new_pajeSetVariable(time, container, type, value);
339 container_t container = PJ_container_get(resource);
340 type_t type = PJ_type_get (variable, container->type);
341 new_pajeAddVariable(time, container, type, value);
346 container_t container = PJ_container_get(resource);
347 type_t type = PJ_type_get (variable, container->type);
348 new_pajeSubVariable(time, container, type, value);
352 //TODO: launch exception
357 static void instr_user_srcdst_variable(double time,
360 const char *variable,
361 const char *father_type,
363 InstrUserVariable what)
365 xbt_dynar_t route=NULL;
366 sg_routing_edge_t src_elm = sg_routing_edge_by_name_or_null(src);
367 if(!src_elm) xbt_die("Element '%s' not found!",src);
369 sg_routing_edge_t dst_elm = sg_routing_edge_by_name_or_null(dst);
370 if(!dst_elm) xbt_die("Element '%s' not found!",dst);
372 routing_get_route_and_latency (src_elm, dst_elm, &route,NULL);
375 xbt_dynar_foreach (route, i, link) {
376 char *link_name = ((link_CM02_t)link)->lmm_resource.generic_resource.name;
377 instr_user_variable (time, link_name, variable, father_type, value, what, NULL, user_link_variables);
381 /** \ingroup TRACE_API
382 * \brief Creates a file with the topology of the platform file used for the simulator.
384 * The graph topology will have the following properties: all hosts, links and routers
385 * of the platform file are mapped to graph nodes; routes are mapped to edges.
386 * The platform's AS are not represented in the output.
388 * \param filename The name of the file that will hold the graph.
390 * \return 1 of successful, 0 otherwise.
392 int TRACE_platform_graph_export_graphviz (const char *filename)
394 /* returns 1 if successful, 0 otherwise */
395 if (!TRACE_is_enabled()) return 0;
396 xbt_graph_t g = instr_routing_platform_graph();
397 if (g == NULL) return 0;
398 instr_routing_platform_graph_export_graphviz (g, filename);
399 xbt_graph_free_graph (g, xbt_free, xbt_free, NULL);
404 * Derived functions that use instr_user_variable and TRACE_user_srcdst_variable.
405 * They were previously defined as pre-processors directives, but were transformed
406 * into functions so the user can track them using gdb.
409 /* for host variables */
410 /** \ingroup TRACE_user_variables
411 * \brief Declare a new user variable associated to hosts.
413 * Declare a user variable that will be associated to hosts.
414 * A user host variable can be used to trace user variables
415 * such as the number of tasks in a server, the number of
416 * clients in an application (for hosts), and so on. The color
417 * associated to this new variable will be random.
419 * \param variable The name of the new variable to be declared.
421 * \see TRACE_host_variable_declare_with_color
423 void TRACE_host_variable_declare (const char *variable)
425 instr_user_variable(0, NULL, variable, "HOST", 0, INSTR_US_DECLARE, NULL, user_host_variables);
428 /** \ingroup TRACE_user_variables
429 * \brief Declare a new user variable associated to hosts with a color.
431 * Same as #TRACE_host_variable_declare, but associated a color
432 * to the newly created user host variable. The color needs to be
433 * a string with three numbers separated by spaces in the range [0,1].
434 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
436 * \param variable The name of the new variable to be declared.
437 * \param color The color for the new variable.
440 void TRACE_host_variable_declare_with_color (const char *variable, const char *color)
442 instr_user_variable(0, NULL, variable, "HOST", 0, INSTR_US_DECLARE, color, user_host_variables);
445 /** \ingroup TRACE_user_variables
446 * \brief Set the value of a variable of a host.
448 * \param host The name of the host to be considered.
449 * \param variable The name of the variable to be considered.
450 * \param value The new value of the variable.
452 * \see TRACE_host_variable_declare, TRACE_host_variable_add, TRACE_host_variable_sub
454 void TRACE_host_variable_set (const char *host, const char *variable, double value)
456 TRACE_host_variable_set_with_time (MSG_get_clock(), host, variable, value);
459 /** \ingroup TRACE_user_variables
460 * \brief Add a value to a variable of a host.
462 * \param host The name of the host to be considered.
463 * \param variable The name of the variable to be considered.
464 * \param value The value to be added to the variable.
466 * \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_sub
468 void TRACE_host_variable_add (const char *host, const char *variable, double value)
470 TRACE_host_variable_add_with_time (MSG_get_clock(), host, variable, value);
473 /** \ingroup TRACE_user_variables
474 * \brief Subtract a value from a variable of a host.
476 * \param host The name of the host to be considered.
477 * \param variable The name of the variable to be considered.
478 * \param value The value to be subtracted from the variable.
480 * \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_add
482 void TRACE_host_variable_sub (const char *host, const char *variable, double value)
484 TRACE_host_variable_sub_with_time (MSG_get_clock(), host, variable, value);
487 /** \ingroup TRACE_user_variables
488 * \brief Set the value of a variable of a host at a given timestamp.
490 * Same as #TRACE_host_variable_set, but let user specify
491 * the time used to trace it. Users can specify a time that
492 * is not the simulated clock time as defined by the core
493 * simulator. This allows a fine-grain control of time
494 * definition, but should be used with caution since the trace
495 * can be inconsistent if resource utilization traces are also traced.
497 * \param time The timestamp to be used to tag this change of value.
498 * \param host The name of the host to be considered.
499 * \param variable The name of the variable to be considered.
500 * \param value The new value of the variable.
502 * \see TRACE_host_variable_declare, TRACE_host_variable_add_with_time, TRACE_host_variable_sub_with_time
504 void TRACE_host_variable_set_with_time (double time, const char *host, const char *variable, double value)
506 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SET, NULL, user_host_variables);
509 /** \ingroup TRACE_user_variables
510 * \brief Add a value to a variable of a host at a given timestamp.
512 * Same as #TRACE_host_variable_add, but let user specify
513 * the time used to trace it. Users can specify a time that
514 * is not the simulated clock time as defined by the core
515 * simulator. This allows a fine-grain control of time
516 * definition, but should be used with caution since the trace
517 * can be inconsistent if resource utilization traces are also traced.
519 * \param time The timestamp to be used to tag this change of value.
520 * \param host The name of the host to be considered.
521 * \param variable The name of the variable to be considered.
522 * \param value The value to be added to the variable.
524 * \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_sub_with_time
526 void TRACE_host_variable_add_with_time (double time, const char *host, const char *variable, double value)
528 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_ADD, NULL, user_host_variables);
531 /** \ingroup TRACE_user_variables
532 * \brief Subtract a value from a variable of a host at a given timestamp.
534 * Same as #TRACE_host_variable_sub, but let user specify
535 * the time used to trace it. Users can specify a time that
536 * is not the simulated clock time as defined by the core
537 * simulator. This allows a fine-grain control of time
538 * definition, but should be used with caution since the trace
539 * can be inconsistent if resource utilization traces are also traced.
541 * \param time The timestamp to be used to tag this change of value.
542 * \param host The name of the host to be considered.
543 * \param variable The name of the variable to be considered.
544 * \param value The value to be subtracted from the variable.
546 * \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_add_with_time
548 void TRACE_host_variable_sub_with_time (double time, const char *host, const char *variable, double value)
550 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SUB, NULL, user_host_variables);
553 /** \ingroup TRACE_user_variables
554 * \brief Get declared user host variables
556 * This function should be used to get host variables that were already
557 * declared with #TRACE_host_variable_declare or with #TRACE_host_variable_declare_with_color.
559 * \return A dynar with the declared host variables, must be freed with xbt_dynar_free.
561 xbt_dynar_t TRACE_get_host_variables (void)
563 return instr_dict_to_dynar (user_host_variables);
566 /* for link variables */
567 /** \ingroup TRACE_user_variables
568 * \brief Declare a new user variable associated to links.
570 * Declare a user variable that will be associated to links.
571 * A user link variable can be used, for example, to trace
572 * user variables such as the number of messages being
573 * transferred through network links. The color
574 * associated to this new variable will be random.
576 * \param variable The name of the new variable to be declared.
578 * \see TRACE_link_variable_declare_with_color
580 void TRACE_link_variable_declare (const char *variable)
582 instr_user_variable (0, NULL, variable, "LINK", 0, INSTR_US_DECLARE, NULL, user_link_variables);
585 /** \ingroup TRACE_user_variables
586 * \brief Declare a new user variable associated to links with a color.
588 * Same as #TRACE_link_variable_declare, but associated a color
589 * to the newly created user link variable. The color needs to be
590 * a string with three numbers separated by spaces in the range [0,1].
591 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
593 * \param variable The name of the new variable to be declared.
594 * \param color The color for the new variable.
597 void TRACE_link_variable_declare_with_color (const char *variable, const char *color)
599 instr_user_variable (0, NULL, variable, "LINK", 0, INSTR_US_DECLARE, color, user_link_variables);
602 /** \ingroup TRACE_user_variables
603 * \brief Set the value of a variable of a link.
605 * \param link The name of the link to be considered.
606 * \param variable The name of the variable to be considered.
607 * \param value The new value of the variable.
609 * \see TRACE_link_variable_declare, TRACE_link_variable_add, TRACE_link_variable_sub
611 void TRACE_link_variable_set (const char *link, const char *variable, double value)
613 TRACE_link_variable_set_with_time (MSG_get_clock(), link, variable, value);
616 /** \ingroup TRACE_user_variables
617 * \brief Add a value to a variable of a link.
619 * \param link The name of the link to be considered.
620 * \param variable The name of the variable to be considered.
621 * \param value The value to be added to the variable.
623 * \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_sub
625 void TRACE_link_variable_add (const char *link, const char *variable, double value)
627 TRACE_link_variable_add_with_time (MSG_get_clock(), link, variable, value);
630 /** \ingroup TRACE_user_variables
631 * \brief Subtract a value from a variable of a link.
633 * \param link The name of the link to be considered.
634 * \param variable The name of the variable to be considered.
635 * \param value The value to be subtracted from the variable.
637 * \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_add
639 void TRACE_link_variable_sub (const char *link, const char *variable, double value)
641 TRACE_link_variable_sub_with_time (MSG_get_clock(), link, variable, value);
644 /** \ingroup TRACE_user_variables
645 * \brief Set the value of a variable of a link at a given timestamp.
647 * Same as #TRACE_link_variable_set, but let user specify
648 * the time used to trace it. Users can specify a time that
649 * is not the simulated clock time as defined by the core
650 * simulator. This allows a fine-grain control of time
651 * definition, but should be used with caution since the trace
652 * can be inconsistent if resource utilization traces are also traced.
654 * \param time The timestamp to be used to tag this change of value.
655 * \param link The name of the link to be considered.
656 * \param variable The name of the variable to be considered.
657 * \param value The new value of the variable.
659 * \see TRACE_link_variable_declare, TRACE_link_variable_add_with_time, TRACE_link_variable_sub_with_time
661 void TRACE_link_variable_set_with_time (double time, const char *link, const char *variable, double value)
663 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SET, NULL, user_link_variables);
666 /** \ingroup TRACE_user_variables
667 * \brief Add a value to a variable of a link at a given timestamp.
669 * Same as #TRACE_link_variable_add, but let user specify
670 * the time used to trace it. Users can specify a time that
671 * is not the simulated clock time as defined by the core
672 * simulator. This allows a fine-grain control of time
673 * definition, but should be used with caution since the trace
674 * can be inconsistent if resource utilization traces are also traced.
676 * \param time The timestamp to be used to tag this change of value.
677 * \param link The name of the link to be considered.
678 * \param variable The name of the variable to be considered.
679 * \param value The value to be added to the variable.
681 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_sub_with_time
683 void TRACE_link_variable_add_with_time (double time, const char *link, const char *variable, double value)
685 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_ADD, NULL, user_link_variables);
688 /** \ingroup TRACE_user_variables
689 * \brief Subtract a value from a variable of a link at a given timestamp.
691 * Same as #TRACE_link_variable_sub, but let user specify
692 * the time used to trace it. Users can specify a time that
693 * is not the simulated clock time as defined by the core
694 * simulator. This allows a fine-grain control of time
695 * definition, but should be used with caution since the trace
696 * can be inconsistent if resource utilization traces are also traced.
698 * \param time The timestamp to be used to tag this change of value.
699 * \param link The name of the link to be considered.
700 * \param variable The name of the variable to be considered.
701 * \param value The value to be subtracted from the variable.
703 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_add_with_time
705 void TRACE_link_variable_sub_with_time (double time, const char *link, const char *variable, double value)
707 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SUB, NULL, user_link_variables);
710 /* for link variables, but with src and dst used for get_route */
711 /** \ingroup TRACE_user_variables
712 * \brief Set the value of the variable present in the links connecting source and destination.
714 * Same as #TRACE_link_variable_set, but instead of providing the
715 * name of link to be considered, provide the source and destination
716 * hosts. All links that are part of the route between source and
717 * destination will have the variable set to the provided value.
719 * \param src The name of the source host for get route.
720 * \param dst The name of the destination host for get route.
721 * \param variable The name of the variable to be considered.
722 * \param value The new value of the variable.
724 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add, TRACE_link_srcdst_variable_sub
726 void TRACE_link_srcdst_variable_set (const char *src, const char *dst, const char *variable, double value)
728 TRACE_link_srcdst_variable_set_with_time (MSG_get_clock(), src, dst, variable, value);
731 /** \ingroup TRACE_user_variables
732 * \brief Add a value to the variable present in the links connecting source and destination.
734 * Same as #TRACE_link_variable_add, but instead of providing the
735 * name of link to be considered, provide the source and destination
736 * hosts. All links that are part of the route between source and
737 * destination will have the value passed as parameter added to
738 * the current value of the variable name to be considered.
740 * \param src The name of the source host for get route.
741 * \param dst The name of the destination host for get route.
742 * \param variable The name of the variable to be considered.
743 * \param value The value to be added to the variable.
745 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_sub
747 void TRACE_link_srcdst_variable_add (const char *src, const char *dst, const char *variable, double value)
749 TRACE_link_srcdst_variable_add_with_time (MSG_get_clock(), src, dst, variable, value);
752 /** \ingroup TRACE_user_variables
753 * \brief Subtract a value from the variable present in the links connecting source and destination.
755 * Same as #TRACE_link_variable_sub, but instead of providing the
756 * name of link to be considered, provide the source and destination
757 * hosts. All links that are part of the route between source and
758 * destination will have the value passed as parameter subtracted from
759 * the current value of the variable name to be considered.
761 * \param src The name of the source host for get route.
762 * \param dst The name of the destination host for get route.
763 * \param variable The name of the variable to be considered.
764 * \param value The value to be subtracted from the variable.
766 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_add
768 void TRACE_link_srcdst_variable_sub (const char *src, const char *dst, const char *variable, double value)
770 TRACE_link_srcdst_variable_sub_with_time (MSG_get_clock(), src, dst, variable, value);
773 /** \ingroup TRACE_user_variables
774 * \brief Set the value of the variable present in the links connecting source and destination at a given timestamp.
776 * Same as #TRACE_link_srcdst_variable_set, but let user specify
777 * the time used to trace it. Users can specify a time that
778 * is not the simulated clock time as defined by the core
779 * simulator. This allows a fine-grain control of time
780 * definition, but should be used with caution since the trace
781 * can be inconsistent if resource utilization traces are also traced.
783 * \param time The timestamp to be used to tag this change of value.
784 * \param src The name of the source host for get route.
785 * \param dst The name of the destination host for get route.
786 * \param variable The name of the variable to be considered.
787 * \param value The new value of the variable.
789 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add_with_time, TRACE_link_srcdst_variable_sub_with_time
791 void TRACE_link_srcdst_variable_set_with_time (double time, const char *src, const char *dst, const char *variable, double value)
793 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SET);
796 /** \ingroup TRACE_user_variables
797 * \brief Add a value to the variable present in the links connecting source and destination at a given timestamp.
799 * Same as #TRACE_link_srcdst_variable_add, but let user specify
800 * the time used to trace it. Users can specify a time that
801 * is not the simulated clock time as defined by the core
802 * simulator. This allows a fine-grain control of time
803 * definition, but should be used with caution since the trace
804 * can be inconsistent if resource utilization traces are also traced.
806 * \param time The timestamp to be used to tag this change of value.
807 * \param src The name of the source host for get route.
808 * \param dst The name of the destination host for get route.
809 * \param variable The name of the variable to be considered.
810 * \param value The value to be added to the variable.
812 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_sub_with_time
814 void TRACE_link_srcdst_variable_add_with_time (double time, const char *src, const char *dst, const char *variable, double value)
816 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_ADD);
819 /** \ingroup TRACE_user_variables
820 * \brief Subtract a value from the variable present in the links connecting source and destination at a given timestamp.
822 * Same as #TRACE_link_srcdst_variable_sub, but let user specify
823 * the time used to trace it. Users can specify a time that
824 * is not the simulated clock time as defined by the core
825 * simulator. This allows a fine-grain control of time
826 * definition, but should be used with caution since the trace
827 * can be inconsistent if resource utilization traces are also traced.
829 * \param time The timestamp to be used to tag this change of value.
830 * \param src The name of the source host for get route.
831 * \param dst The name of the destination host for get route.
832 * \param variable The name of the variable to be considered.
833 * \param value The value to be subtracted from the variable.
835 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_add_with_time
837 void TRACE_link_srcdst_variable_sub_with_time (double time, const char *src, const char *dst, const char *variable, double value)
839 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SUB);
842 /** \ingroup TRACE_user_variables
843 * \brief Get declared user link variables
845 * This function should be used to get link variables that were already
846 * declared with #TRACE_link_variable_declare or with #TRACE_link_variable_declare_with_color.
848 * \return A dynar with the declared link variables, must be freed with xbt_dynar_free.
850 xbt_dynar_t TRACE_get_link_variables (void)
852 return instr_dict_to_dynar (user_link_variables);
855 /** \ingroup TRACE_user_variables
856 * \brief Declare a new user state associated to hosts.
858 * Declare a user state that will be associated to hosts.
859 * A user host state can be used to trace application states.
861 * \param state The name of the new state to be declared.
863 * \see TRACE_host_state_declare_value
865 void TRACE_host_state_declare (const char *state)
867 instr_new_user_state_type("HOST", state);
870 /** \ingroup TRACE_user_variables
871 * \brief Declare a new value for a user state associated to hosts.
873 * Declare a value for a state. The color needs to be
874 * a string with three numbers separated by spaces in the range [0,1].
875 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
877 * \param state The name of the new state to be declared.
878 * \param value The name of the value
879 * \param color The color of the value
881 * \see TRACE_host_state_declare
883 void TRACE_host_state_declare_value (const char *state, const char *value, const char *color)
885 instr_new_value_for_user_state_type (state, value, color);
888 /** \ingroup TRACE_user_variables
889 * \brief Set the user state to the given value.
891 * Change a user state previously declared to the given value.
893 * \param host The name of the host to be considered.
894 * \param state The name of the state previously declared.
895 * \param value The new value of the state.
897 * \see TRACE_host_state_declare, TRACE_host_push_state, TRACE_host_pop_state, TRACE_host_reset_state
899 void TRACE_host_set_state (const char *host, const char *state, const char *value)
901 container_t container = PJ_container_get(host);
902 type_t type = PJ_type_get (state, container->type);
903 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 */
904 new_pajeSetState(MSG_get_clock(), container, type, val);
907 /** \ingroup TRACE_user_variables
908 * \brief Push a new value for a state of a given host.
910 * Change a user state previously declared by pushing the new value to the state.
912 * \param host The name of the host to be considered.
913 * \param state The name of the state previously declared.
914 * \param value The value to be pushed.
916 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_pop_state, TRACE_host_reset_state
918 void TRACE_host_push_state (const char *host, const char *state, const char *value)
920 container_t container = PJ_container_get(host);
921 type_t type = PJ_type_get (state, container->type);
922 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 */
923 new_pajePushState(MSG_get_clock(), container, type, val);
926 /** \ingroup TRACE_user_variables
927 * \brief Pop the last value of a state of a given host.
929 * Change a user state previously declared by removing the last value of the state.
931 * \param host The name of the host to be considered.
932 * \param state The name of the state to be popped.
934 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_reset_state
936 void TRACE_host_pop_state (const char *host, const char *state)
938 container_t container = PJ_container_get(host);
939 type_t type = PJ_type_get (state, container->type);
940 new_pajePopState(MSG_get_clock(), container, type);
943 /** \ingroup TRACE_user_variables
944 * \brief Reset the state of a given host.
946 * Clear all previous values of a user state.
948 * \param host The name of the host to be considered.
949 * \param state The name of the state to be cleared.
951 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_pop_state
953 void TRACE_host_reset_state (const char *host, const char *state)
955 container_t container = PJ_container_get(host);
956 type_t type = PJ_type_get (state, container->type);
957 new_pajeResetState(MSG_get_clock(), container, type);
960 /** \ingroup TRACE_API
961 * \brief Get Paje container types that can be mapped to the nodes of a graph.
963 * This function can be used to create a user made
964 * graph configuration file for Triva. Normally, it is
965 * used with the functions defined in \ref TRACE_user_variables.
967 * \return A dynar with the types, must be freed with xbt_dynar_free.
969 xbt_dynar_t TRACE_get_node_types (void)
971 return instr_dict_to_dynar (trivaNodeTypes);
974 /** \ingroup TRACE_API
975 * \brief Get Paje container types that can be mapped to the edges of a graph.
977 * This function can be used to create a user made
978 * graph configuration file for Triva. Normally, it is
979 * used with the functions defined in \ref TRACE_user_variables.
981 * \return A dynar with the types, must be freed with xbt_dynar_free.
983 xbt_dynar_t TRACE_get_edge_types (void)
985 return instr_dict_to_dynar (trivaEdgeTypes);
988 /** \ingroup TRACE_API
989 * \brief Pauses all tracing activities.
992 void TRACE_pause (void)
994 instr_pause_tracing();
997 /** \ingroup TRACE_API
998 * \brief Resumes all tracing activities.
1001 void TRACE_resume (void)
1003 instr_resume_tracing();
1006 #endif /* HAVE_TRACING */